better understanding of isinstance in executions (temporary commit)

This commit is contained in:
David Halter
2012-11-24 02:10:21 +01:00
parent a4b8c720e7
commit 4627e22a1c
2 changed files with 38 additions and 7 deletions

View File

@@ -504,6 +504,9 @@ class Execution(Executable):
key = name.var_args.get_only_subelement() key = name.var_args.get_only_subelement()
stmts += follow_path(iter([key]), obj, self.base) stmts += follow_path(iter([key]), obj, self.base)
return stmts return stmts
elif func_name == 'type':
print 'LALA'
raise NotImplementedError()
if self.base.isinstance(Class): if self.base.isinstance(Class):
# There maybe executions of executions. # There maybe executions of executions.
@@ -714,7 +717,7 @@ class Execution(Executable):
objects = [] objects = []
for element in attr: for element in attr:
copied = helpers.fast_parent_copy(element) copied = helpers.fast_parent_copy(element)
copied.parent = weakref.ref(self) copied.parent = weakref.ref(self._scope_copy(copied.parent()))
if isinstance(copied, parsing.Function): if isinstance(copied, parsing.Function):
copied = Function(copied) copied = Function(copied)
objects.append(copied) objects.append(copied)
@@ -726,6 +729,24 @@ class Execution(Executable):
raise AttributeError('Tried to access %s: %s. Why?' % (name, self)) raise AttributeError('Tried to access %s: %s. Why?' % (name, self))
return getattr(self.base, name) return getattr(self.base, name)
@memoize_default()
def _scope_copy(self, scope):
try:
""" Copies a scope (e.g. if) in an execution """
# TODO This method uses different scopes than the subscopes property.
if scope == self.base or scope == self.base.base_func:
return self
else:
copied = helpers.fast_parent_copy(scope)
#copied.parent = self._scope_copy(copied.parent())
copied.parent = weakref.ref(self._scope_copy(copied.parent()))
#copied.parent = weakref.ref(self)
faked_scopes.append(copied)
return copied
except AttributeError:
raise MultiLevelAttributeError(sys.exc_info())
@property @property
@memoize_default() @memoize_default()
def returns(self): def returns(self):
@@ -1139,8 +1160,8 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
result = [] result = []
# compare func uses the tuple of line/indent = line/column # compare func uses the tuple of line/indent = line/column
comparison_func = lambda name: (name.start_pos) comparison_func = lambda name: (name.start_pos)
check_for_param = lambda p: isinstance(p, parsing.Param) \ check_for_param = lambda p: isinstance(p, parsing.Param)
and not p.is_generated
for nscope, name_list in scope_generator: for nscope, name_list in scope_generator:
break_scopes = [] break_scopes = []
# here is the position stuff happening (sorting of variables) # here is the position stuff happening (sorting of variables)
@@ -1166,14 +1187,15 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
if not name.parent() or p == s: if not name.parent() or p == s:
break break
break_scopes.append(p) break_scopes.append(p)
# if there are results, ignore the other scopes, if params are in
# there, we still need to check flows, if they contain information. print 'b', flow_scope, name_str, result
if result and not [r for r in result if check_for_param(r)]:
break
while flow_scope: while flow_scope:
# TODO check if result is in scope -> no evaluation necessary
n = dynamic.check_flow_information(flow_scope, name_str, n = dynamic.check_flow_information(flow_scope, name_str,
position) position)
print
print 'n', n, flow_scope
if n and result: if n and result:
result = n + [p for p in result if not check_for_param(r)] result = n + [p for p in result if not check_for_param(r)]
elif n: elif n:

View File

@@ -38,3 +38,12 @@ def fooooo(obj):
if isinstance(obj, datetime.datetime): if isinstance(obj, datetime.datetime):
#? datetime.datetime #? datetime.datetime
obj obj
def fooooo2(obj):
if isinstance(obj, datetime.datetime):
return obj
else:
return 1
#? int() datetime.datetime
fooooo2('')