whichmodule() should skip dummy package entries in sys.modules.

This fixes the charming, but unhelpful error message for
>>> pickle.dumps(type.__new__)
Can't pickle <built-in method __new__ of type object at 0x812a440>: it's not the same object as datetime.math.__new__

Bugfix candidate.
This commit is contained in:
Jeremy Hylton 2002-09-19 22:57:26 +00:00
parent 16849a7e53
commit 065a5ab8fb

View file

@ -626,6 +626,8 @@ def whichmodule(cls, clsname):
return classmap[cls]
for name, module in sys.modules.items():
if module is None:
continue # skip dummy package entries
if name != '__main__' and \
hasattr(module, clsname) and \
getattr(module, clsname) is cls: