diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2024-02-29 21:39:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 21:39:50 (GMT) |
commit | ccfc042bbf31e53c44b8aae444afd8365b798422 (patch) | |
tree | ded4b9df37457393898574c6c3781350882d519d | |
parent | 556749c3e33f7787da149f75ca1702b80383bead (diff) | |
download | cpython-ccfc042bbf31e53c44b8aae444afd8365b798422.zip cpython-ccfc042bbf31e53c44b8aae444afd8365b798422.tar.gz cpython-ccfc042bbf31e53c44b8aae444afd8365b798422.tar.bz2 |
gh-87115: Set `__main__.__spec__` to `None` in pdb (#116141)
-rwxr-xr-x | Lib/pdb.py | 1 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 12 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-02-29-20-06-06.gh-issue-87115.FVMiOR.rst | 1 |
3 files changed, 14 insertions, 0 deletions
@@ -188,6 +188,7 @@ class _ScriptTarget(str): __name__='__main__', __file__=self, __builtins__=__builtins__, + __spec__=None, ) @property diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 2b0795c..3dd275c 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2695,6 +2695,18 @@ def bœr(): ('bœr', 2), ) + def test_spec(self): + # Test that __main__.__spec__ is set to None when running a script + script = """ + import __main__ + print(__main__.__spec__) + """ + + commands = "continue" + + stdout, _ = self.run_pdb_script(script, commands) + self.assertIn('None', stdout) + def test_find_function_first_executable_line(self): code = textwrap.dedent("""\ def foo(): pass diff --git a/Misc/NEWS.d/next/Library/2024-02-29-20-06-06.gh-issue-87115.FVMiOR.rst b/Misc/NEWS.d/next/Library/2024-02-29-20-06-06.gh-issue-87115.FVMiOR.rst new file mode 100644 index 0000000..8443405 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-02-29-20-06-06.gh-issue-87115.FVMiOR.rst @@ -0,0 +1 @@ +Set ``__main__.__spec__`` to ``None`` when running a script with :mod:`pdb` |