[docs] [issue16355] inspect.getcomments() does not work in the interactive shell

R. David Murray report at bugs.python.org
Wed Oct 9 22:04:10 CEST 2013


R. David Murray added the comment:

Looking at the source, the suppression of errors is clearly intentional.  Looking at the change that added the TypeError check, we see this from Jeremy Hilton in March 2002 (9c2ca37bdeec):

    It appears that getcomments() can get called for classes defined in
    C.  Since these don't have source code, it can't do anything useful.
    A function buried many levels deep was raising a TypeError that was
    not caught.

    Who knows why this broke...

Which implies that getcomments was being called from somewhere in Python itself...at least back then.

The check for OSError (IOError, then) was from shortly after the module was first added, in February of 2001 by Ka-Ping Yee.

So, the motivation behind this behavior are shrouded in the mists of time :)

Should we really be changing something of that long standing, when it raising a TypeError previously clearly broke something?

I'm thinking not.  I'm thinking we should leave well enough alone.  It is, after all, working as documented....in the doc string, from the time Jeremy made the TypeError change.  So after all this work (sorry people, I do appreciate the work!), I think we should just make a doc fix that copies the line about returning None if source can't be found into the rst docs.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16355>
_______________________________________


More information about the docs mailing list