New submission from Pekka Klärck <pekka.kla...@gmail.com>: 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 ---------- messages: 370547 nosy: pekka.klarck priority: normal severity: normal status: open title: inspect.getsourcefile documentation doesn't mention it can return None _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40838> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com