Working with circular dependency (functools & # 8594; _functools & # 8594; functools) when copying a namespace

The functools module refers to reduce , which is defined in _functools . Meanwhile, _functools refers to partial , which is defined in functools

I ran into this problem while trying to create a copy of the namespace for correcting monkeys. But in my case, I need both old and monkey-fixed functionality, so you need a copy. Any suggestion, what a good way for circular dependencies like this?

Using Python 2.7.10

Some source code for the request

 def _get_dependent_modules(m): """Return set of all modules defining symbols in given module.""" modules = set() for symbol_name, symbol in m.__dict__.items(): if hasattr(symbol, '__module__'): if symbol.__module__ in sys.modules: print "Symbol %s, defined in %s" % (symbol_name, symbol.__module__) modules.add(sys.modules[symbol.__module__]) else: print "Cant find module for %s" %(symbol) return modules _get_dependent_modules(functools) Symbol wraps, defined in functools Symbol partial, defined in functools Symbol update_wrapper, defined in functools Symbol total_ordering, defined in functools Symbol reduce, defined in _functools Symbol cmp_to_key, defined in functools _get_dependent_modules(sys.modules["_functools"]) Symbol partial, defined in functools Symbol reduce, defined in _functools 
+5
source share
1 answer

You can just remember what you saw ( identity comparison ) so far, and not go over or go down into things that you remember.

Perhaps I do not understand the complexity of the operation (copy namespace).

Just a suggestion:

 sub scan_symbols(object): for each member in object: if member is of type-primitive: whatever if member is of type-object: record member reference if not already recorded if reference is new: scan_symbols(member) 

Example real code in PHP:

https://raw.githubusercontent.com/pradosoft/prado/master/framework/Util/TVarDumper.php

This avoids circular depots:

https://github.com/symfony/var-dumper

0
source

All Articles