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.
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 4bc54ec..d4085cf 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -626,6 +626,8 @@
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: