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

Skip to content

Commit ccfc042

Browse files
gh-87115: Set __main__.__spec__ to None in pdb (#116141)
1 parent 556749c commit ccfc042

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
@@ -188,6 +188,7 @@ def namespace(self):
188188
__name__='__main__',
189189
__file__=self,
190190
__builtins__=__builtins__,
191+
__spec__=None,
191192
)
192193

193194
@property

Lib/test/test_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,18 @@ def bœr():
26952695
('bœr', 2),
26962696
)
26972697

2698+
def test_spec(self):
2699+
# Test that __main__.__spec__ is set to None when running a script
2700+
script = """
2701+
import __main__
2702+
print(__main__.__spec__)
2703+
"""
2704+
2705+
commands = "continue"
2706+
2707+
stdout, _ = self.run_pdb_script(script, commands)
2708+
self.assertIn('None', stdout)
2709+
26982710
def test_find_function_first_executable_line(self):
26992711
code = textwrap.dedent("""\
27002712
def foo(): pass
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