helpers.py 489 B

12345678910111213
  1. from astroid.nodes.scoped_nodes import Module
  2. def register_module_extender(manager, module_name, get_extension_mod):
  3. def transform(node):
  4. extension_module = get_extension_mod()
  5. for name, objs in extension_module.locals.items():
  6. node.locals[name] = objs
  7. for obj in objs:
  8. if obj.parent is extension_module:
  9. obj.parent = node
  10. manager.register_transform(Module, transform, lambda n: n.name == module_name)