https://github.com/python/cpython/commit/40e9295a581f2908f2cdf09b1726822379ea7bd0 commit: 40e9295a581f2908f2cdf09b1726822379ea7bd0 branch: 3.12 author: Tian Gao <[email protected]> committer: iritkatriel <[email protected]> date: 2024-02-29T23:24:09Z summary:
[3.12] gh-87115: Set `__main__.__spec__` to `None` in pdb (GH-116141) (#116154) * gh-87115: Set `__main__.__spec__` to `None` in pdb (#116141) (cherry picked from commit ccfc042bbf31e53c44b8aae444afd8365b798422) * [3.12] gh-87115: Set `__main__.__spec__` to `None` in pdb (GH-116141) (cherry picked from commit ccfc042bbf31e53c44b8aae444afd8365b798422) Co-authored-by: Tian Gao <[email protected]> files: A Misc/NEWS.d/next/Library/2024-02-29-20-06-06.gh-issue-87115.FVMiOR.rst M Lib/pdb.py M Lib/test/test_pdb.py diff --git a/Lib/pdb.py b/Lib/pdb.py index a838a26b038df6..494e640cda2757 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -154,6 +154,7 @@ def namespace(self): __name__='__main__', __file__=self, __builtins__=__builtins__, + __spec__=None, ) @property diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 51b844262ed1e8..0e1b1c9864f8c1 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2013,6 +2013,18 @@ def bœr(): ('bœr', 1), ) + 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_issue7964(self): # open the file as binary so we can force \r\n newline with open(os_helper.TESTFN, 'wb') as f: 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 00000000000000..844340583cd456 --- /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` _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
