Skip to content

Commit

Permalink
gh-87115: Set __main__.__spec__ to None in pdb (#116141)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian authored Feb 29, 2024
1 parent 556749c commit ccfc042
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def namespace(self):
__name__='__main__',
__file__=self,
__builtins__=__builtins__,
__spec__=None,
)

@property
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set ``__main__.__spec__`` to ``None`` when running a script with :mod:`pdb`

0 comments on commit ccfc042

Please sign in to comment.