Author pekka.klarck
Recipients pekka.klarck
Date 2020-06-01.11:41:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591011704.27.0.0385051429778.issue40838@roundup.psfhosted.org>
In-reply-to
Content
The docs of inspect.getsourcefile [1] mention the function can raise TypeError, but there's nothing about the function possibly returning None. This caused a bug in our project [2].

If I understand the code [3] correctly, None is returned if getsourcefile cannot determine the original source file of the file returned by getfile. That's understandable but should definitely be documented. Raising TypeError that getfile itself may raise might be even better, but such a backwards incompatible API change is probably not worth the effort.

While looking at the code, I also noticed there's getabsfile [4] that uses getfile if getsourcefile returns None. That looks handy but since the function isn't included in the inspect module documentation [5] using it feels pretty risky.

[1] https://docs.python.org/3/library/inspect.html#inspect.getsourcefile
[2] https://github.com/robotframework/robotframework/issues/3587
[3] https://github.com/python/cpython/blob/3.8/Lib/inspect.py#L692
[4] https://github.com/python/cpython/blob/3.8/Lib/inspect.py#L714
[5] https://bugs.python.org/issue12317
History
Date User Action Args
2020-06-01 11:41:44pekka.klarcksetrecipients: + pekka.klarck
2020-06-01 11:41:44pekka.klarcksetmessageid: <1591011704.27.0.0385051429778.issue40838@roundup.psfhosted.org>
2020-06-01 11:41:44pekka.klarcklinkissue40838 messages
2020-06-01 11:41:44pekka.klarckcreate