1.1 --- a/importer.py Tue Dec 06 21:26:58 2016 +0100
1.2 +++ b/importer.py Tue Dec 06 22:27:09 2016 +0100
1.3 @@ -445,7 +445,7 @@
1.4
1.5 # Record a module ordering dependency.
1.6
1.7 - if not found.static():
1.8 + if not found.static() or self.uses_dynamic_callable(found):
1.9 init_item(self.depends, module.name, set)
1.10 self.depends[module.name].add(provider)
1.11
1.12 @@ -470,6 +470,16 @@
1.13 print >>sys.stderr, "Requiring", provider
1.14 self.require_providers(provider)
1.15
1.16 + def uses_dynamic_callable(self, ref):
1.17 +
1.18 + """
1.19 + Return whether 'ref' refers to a callable employing defaults that may
1.20 + need initialising before the callable can be used.
1.21 + """
1.22 +
1.23 + return ref.has_kind("<function>") and self.function_defaults.get(ref.get_origin()) or \
1.24 + ref.has_kind("<class>") and self.function_defaults.get("%s.__init__" % ref.get_origin())
1.25 +
1.26 def order_modules(self):
1.27
1.28 "Produce a module initialisation ordering."