# HG changeset patch # User Paul Boddie # Date 1481059629 -3600 # Node ID c3aadc0a672daed52bc82db7fe381983462a4fec # Parent aa10eecbc8ce350f4ad5057b2689bd04277b00f1 Attempt to handle module ordering dependencies caused by function defaults. diff -r aa10eecbc8ce -r c3aadc0a672d importer.py --- a/importer.py Tue Dec 06 21:26:58 2016 +0100 +++ b/importer.py Tue Dec 06 22:27:09 2016 +0100 @@ -445,7 +445,7 @@ # Record a module ordering dependency. - if not found.static(): + if not found.static() or self.uses_dynamic_callable(found): init_item(self.depends, module.name, set) self.depends[module.name].add(provider) @@ -470,6 +470,16 @@ print >>sys.stderr, "Requiring", provider self.require_providers(provider) + def uses_dynamic_callable(self, ref): + + """ + Return whether 'ref' refers to a callable employing defaults that may + need initialising before the callable can be used. + """ + + return ref.has_kind("") and self.function_defaults.get(ref.get_origin()) or \ + ref.has_kind("") and self.function_defaults.get("%s.__init__" % ref.get_origin()) + def order_modules(self): "Produce a module initialisation ordering."