Skip to content

Commit

Permalink
Merge pull request #190 from mahmoud/glomit-spec-instances-only
Browse files Browse the repository at this point in the history
Enforce that specifier types must be passed as instances
  • Loading branch information
kurtbrose committed Aug 11, 2020
2 parents 0d6a45b + 622048d commit e8cd3b8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions glom/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,8 @@ def _is_spec(obj, strict=False):
return True
if strict:
return type(obj) is Spec
# TODO: revisit line below
return callable(getattr(obj, 'glomit', None)) and not isinstance(obj, type) # pragma: no cover

return _has_callable_glomit(obj) # pragma: no cover


class Invoke(object):
Expand Down Expand Up @@ -2089,6 +2089,14 @@ def chain_child(scope):
return nxt_in_chain


unbound_methods = set([type(str.__len__)]) #, type(Ref.glomit)])


def _has_callable_glomit(obj):
glomit = getattr(obj, 'glomit', None)
return callable(glomit) and not isinstance(obj, type)


def _glom(target, spec, scope):
parent = scope
scope = scope.new_child({
Expand All @@ -2102,7 +2110,7 @@ def _glom(target, spec, scope):
try:
if isinstance(spec, TType): # must go first, due to callability
return _t_eval(target, spec, scope)
elif callable(getattr(spec, 'glomit', None)):
elif _has_callable_glomit(spec):
return spec.glomit(target, scope)

return scope[MODE](target, spec, scope)
Expand Down

0 comments on commit e8cd3b8

Please sign in to comment.