Mailing List Archive

python/dist/src/Lib pickle.py,1.56.4.2,1.56.4.3
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv13142

Modified Files:
Tag: release22-maint
pickle.py
Log Message:
Backport 1.70 and 1.71 (which really go together):

1.70:
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__

1.71:
Fiddle comments and variable names in whichmodule().


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.56.4.2
retrieving revision 1.56.4.3
diff -C2 -d -r1.56.4.2 -r1.56.4.3
*** pickle.py 16 Jul 2002 20:02:14 -0000 1.56.4.2
--- pickle.py 7 Oct 2002 13:09:25 -0000 1.56.4.3
***************
*** 553,578 ****


! classmap = {}

! # This is no longer used to find classes, but still for functions
! def whichmodule(cls, clsname):
! """Figure out the module in which a class occurs.

Search sys.modules for the module.
Cache in classmap.
Return a module name.
! If the class cannot be found, return __main__.
"""
! if classmap.has_key(cls):
! return classmap[cls]

for name, module in sys.modules.items():
if name != '__main__' and \
! hasattr(module, clsname) and \
! getattr(module, clsname) is cls:
break
else:
name = '__main__'
! classmap[cls] = name
return name

--- 553,579 ----


! classmap = {} # called classmap for backwards compatibility

! def whichmodule(func, funcname):
! """Figure out the module in which a function occurs.

Search sys.modules for the module.
Cache in classmap.
Return a module name.
! If the function cannot be found, return __main__.
"""
! if classmap.has_key(classmap):
! return classmap[func]

for name, module in sys.modules.items():
+ if module is None:
+ continue # skip dummy package entries
if name != '__main__' and \
! hasattr(module, funcname) and \
! getattr(module, funcname) is func:
break
else:
name = '__main__'
! classmap[func] = name
return name