Correct global name issues.

This commit is contained in:
Dave Halter
2015-01-08 01:20:53 +01:00
parent f5e687bc22
commit 83a94c12c9
5 changed files with 27 additions and 5 deletions
+8 -2
View File
@@ -36,7 +36,7 @@ def filter_definition_names(names, origin, position=None):
# Just calculate the scope from the first
stmt = names[0].get_definition()
scope = stmt.get_parent_scope()
if isinstance(stmt, (pr.CompFor, pr.Lambda, pr.GlobalStmt)):
if isinstance(stmt, (pr.CompFor, pr.Lambda)):
return names
if not (isinstance(scope, er.FunctionExecution)
@@ -377,7 +377,13 @@ def _name_to_types(evaluator, name, scope):
elif isinstance(typ, pr.Import):
types += imports.ImportWrapper(evaluator, name).follow()
elif isinstance(typ, pr.GlobalStmt):
types += evaluator.find_types(typ.get_parent_scope(), str(name))
# TODO theoretically we shouldn't be using search_global here, it
# doesn't make sense, because it's a local search (for that name)!
# However, globals are not that important and resolving them doesn't
# guarantee correctness in any way, because we don't check for when
# something is executed.
types += evaluator.find_types(typ.get_parent_scope(), str(name),
search_global=True)
elif isinstance(typ, pr.TryStmt):
# TODO an exception can also be a tuple. Check for those.
# TODO check for types that are not classes and add it to
+11 -1
View File
@@ -824,6 +824,16 @@ class FunctionExecution(Executed):
return "<%s of %s>" % (type(self).__name__, self.base)
class GlobalName(helpers.FakeName):
def __init__(self, name):
"""
We need to mark global names somehow. Otherwise they are just normal
names that are not definitions.
"""
super(GlobalName, self).__init__(name.value, name.parent,
name.start_pos, is_definition=True)
class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
def __init__(self, evaluator, module):
self._evaluator = evaluator
@@ -847,7 +857,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
for star_module in self.star_imports():
yield star_module.names_dict
yield dict((str(n), [n]) for n in self.base.global_names)
yield dict((str(n), [GlobalName(n)]) for n in self.base.global_names)
yield self._sub_modules_dict()
@cache_star_import