1.1 --- a/importer.py Sat Dec 17 01:51:10 2016 +0100
1.2 +++ b/importer.py Sat Dec 17 14:59:19 2016 +0100
1.3 @@ -528,10 +528,22 @@
1.4 if self.is_dynamic_callable(name):
1.5
1.6 # Make functions with defaults requiring initialisation depend
1.7 - # on the parent scope.
1.8 + # on the parent scope, if a function, or the module scope.
1.9
1.10 ref = Reference("<function>", name)
1.11 - self.add_dependency(name, ref.parent())
1.12 + parent_ref = self.get_object(ref.parent())
1.13 +
1.14 + # Function no longer present in the program.
1.15 +
1.16 + if not parent_ref:
1.17 + continue
1.18 +
1.19 + if parent_ref.has_kind("<class>"):
1.20 + parent = self.get_module_provider(parent_ref)
1.21 + else:
1.22 + parent = parent_ref.get_origin()
1.23 +
1.24 + self.add_dependency(name, parent)
1.25
1.26 def add_module_dependencies(self):
1.27
1.28 @@ -594,6 +606,9 @@
1.29
1.30 special_attributes = ("__args__", "__file__", "__fn__", "__fname__", "__mname__", "__name__")
1.31
1.32 + def is_dynamic(self, ref):
1.33 + return not ref or not ref.static() and not ref.is_constant_alias() and not ref.is_predefined_value()
1.34 +
1.35 def is_dynamic_class(self, name):
1.36
1.37 """
1.38 @@ -609,7 +624,8 @@
1.39 for attrname, attr in attrs.items():
1.40 if attrname in self.special_attributes:
1.41 continue
1.42 - if not attr or not self.get_object(attr).static():
1.43 + ref = attr and self.get_object(attr)
1.44 + if self.is_dynamic(ref):
1.45 return True
1.46
1.47 return False
1.48 @@ -630,7 +646,7 @@
1.49 # Identify non-constant defaults.
1.50
1.51 for name, ref in defaults:
1.52 - if not ref.static() and not ref.is_constant_alias():
1.53 + if self.is_dynamic(ref):
1.54 return True
1.55
1.56 return False