[Python-Dev] doctest and inspect.getmodule

Johannes Gijsbers jlgijsbers at planet.nl
Sat Sep 11 18:26:51 CEST 2004


I just checked in a change to inspect.getmodule (without running the tests
beforehand, not a smart move) which broke a whole bunc of tests for doctest.
The tests mostly seem to fail because doctest can find modules for objects it
previously couldn't. 

I think the change is basically correct, but I'm not sure how to fix doctest.
Should doctest omit the module, or should the doctest tests be changed to
expect the module being printed?

Oh, I promise I'll run the tests before checking in next time.

Johannes

P.S.: here's the checkin message for the change:

Modified Files:
	inspect.py
Log Message:
Use __module__ attribute when available instead of using isclass()
predicate (functions and methods have grown the __module__ attribute too).
See bug #570300.

Index: inspect.py
=================================================================== RCS
file: /cvsroot/python/python/dist/src/Lib/inspect.py,v retrieving revision
1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- inspect.py	18 Aug 2004 12:40:30 -0000	1.54 +++ inspect.py	11 Sep 2004
15:53:22 -0000	1.55 @@ -370,7 +370,7 @@
     """Return the module an object was defined in, or None if not
     found.""" if ismodule(object):
         return object
-    if isclass(object):
+    if hasattr(object, '__module__'):
         return sys.modules.get(object.__module__)
     try:
         file = getabsfile(object)


More information about the Python-Dev mailing list