cpython/Misc/NEWS.d/next/Library/2020-06-11-16-20-33.bpo-27578.CIA-fu.rst
kernc 52ef4430a9
gh-71765: Fix inspect.getsource() on empty file (GH-20809)
* bpo-27578: Fix inspect.getsource() on empty file

For modules from empty files, `inspect.getsource()` now
returns an empty string, and `inspect.getsourcelines()` returns
a list of one empty string, fixing the expected invariant.

As indicated by `exec('')`, empty strings are valid Python
source code.

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2024-03-18 16:13:02 +01:00

3 lines
174 B
ReStructuredText

:func:`inspect.getsource` (and related functions) work with
empty module files, returning ``'\n'`` (or reasonable equivalent)
instead of raising ``OSError``. Patch by Kernc.