]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-71765: Fix inspect.getsource() on empty file (GH-20809)
authorkernc <kerncece@gmail.com>
Mon, 18 Mar 2024 15:13:02 +0000 (16:13 +0100)
committerGitHub <noreply@github.com>
Mon, 18 Mar 2024 15:13:02 +0000 (16:13 +0100)
commit52ef4430a9b3e212fe9200675cddede77b90785b
tree19f7aabd2c858add151919eb895c4577e7b1f8e1
parentf6cdc6b4a191b75027de342aa8b5d344fb31313e
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>
Lib/linecache.py
Lib/test/test_inspect/test_inspect.py
Lib/test/test_linecache.py
Misc/NEWS.d/next/Library/2020-06-11-16-20-33.bpo-27578.CIA-fu.rst [new file with mode: 0644]