[Python-checkins] python/dist/src/Lib pickle.py,1.133,1.134

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Fri, 31 Jan 2003 10:33:19 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv18557/Lib

Modified Files:
	pickle.py 
Log Message:
Provide __module__ attributes for functions defined in C and Python.

__module__ is the string name of the module the function was defined
in, just like __module__ of classes.  In some cases, particularly for
C functions, the __module__ may be None.

Change PyCFunction_New() from a function to a macro, but keep an
unused copy of the function around so that we don't change the binary
API.

Change pickle's save_global() to use whichmodule() if __module__ is
None, but add the __module__ logic to whichmodule() since it might be
used outside of pickle.



Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.133
retrieving revision 1.134
diff -C2 -d -r1.133 -r1.134
*** pickle.py	31 Jan 2003 17:17:49 -0000	1.133
--- pickle.py	31 Jan 2003 18:33:16 -0000	1.134
***************
*** 788,794 ****
              name = obj.__name__
  
!         try:
!             module = obj.__module__
!         except AttributeError:
              module = whichmodule(obj, name)
  
--- 788,793 ----
              name = obj.__name__
  
!         module = getattr(obj, "__module__", None)
!         if module is None:
              module = whichmodule(obj, name)
  
***************
*** 877,880 ****
--- 876,883 ----
      If the function cannot be found, return "__main__".
      """
+     # Python functions should always get an __module__ from their globals.
+     mod = getattr(func, "__module__", None)
+     if mod is not None:
+         return mod
      if func in classmap:
          return classmap[func]