Skip to content

Commit d3282f5

Browse files
[3.11] gh-87115: Set __main__.__spec__ to None in pdb (GH-116141) (#116155)
* gh-87115: Set `__main__.__spec__` to `None` in pdb (#116141) (cherry picked from commit ccfc042) * [3.11] gh-87115: Set `__main__.__spec__` to `None` in pdb (GH-116141) (cherry picked from commit ccfc042) Co-authored-by: Tian Gao <[email protected]>
1 parent da34d55 commit d3282f5

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/pdb.py

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def namespace(self):
153153
__name__='__main__',
154154
__file__=self,
155155
__builtins__=__builtins__,
156+
__spec__=None,
156157
)
157158

158159
@property

Lib/test/test_pdb.py

+12
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,18 @@ def bœr():
18621862
('bœr', 1),
18631863
)
18641864

1865+
def test_spec(self):
1866+
# Test that __main__.__spec__ is set to None when running a script
1867+
script = """
1868+
import __main__
1869+
print(__main__.__spec__)
1870+
"""
1871+
1872+
commands = "continue"
1873+
1874+
stdout, _ = self.run_pdb_script(script, commands)
1875+
self.assertIn('None', stdout)
1876+
18651877
def test_issue7964(self):
18661878
# open the file as binary so we can force \r\n newline
18671879
with open(os_helper.TESTFN, 'wb') as f:
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)