8000 [3.12] gh-87115: Set `__main__.__spec__` to `None` in pdb (GH-116141)… · python/cpython@40e9295 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40e9295

Browse files
[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 ccfc042) * [3.12] gh-87115: Set `__main__.__spec__` to `None` in pdb (GH-116141) (cherry picked from commit ccfc042) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent 8d865f1 commit 40e9295

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/pdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def namespace(self):
154154
__name__='__main__',
155155
__file__=self,
156156
__builtins__=__builtins__,
157+
__spec__=None,
157158
)
158159

159160
@property

Lib/test/test_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,18 @@ def bœr():
20132013
('bœr', 1),
20142014
)
20152015

2016+
def test_spec(self):
2017+
# Test that __main__.__spec__ is set to None when running a script
2018+
script = """
2019+
import __main__
2020+
print(__main__.__spec__)
2021+
"""
2022+
2023+
commands = "continue"
2024+
2025+
stdout, _ = self.run_pdb_script(script, commands)
2026+
self.assertIn('None', stdout)
2027+
20162028
def test_issue7964(self):
20172029
# open the file as binary so we can force \r\n newline
20182030
with open(os_helper.TESTFN, 'wb') as f:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set ``__main__.__spec__`` to ``None`` when running a script with :mod:`pdb`

0 commit comments

Comments
 (0)
0