whichmodule() should skip dummy package entries in sys.modules.
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 19 Sep 2002 22:57:26 +0000 (22:57 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 19 Sep 2002 22:57:26 +0000 (22:57 +0000)
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.

Lib/pickle.py

index 4bc54ec5f9de96f222f502430d3df4ffb6567307..d4085cfbc09b2d9aaff18416857bf21cd1b5b377 100644 (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: