GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-44554: refactor pdb targets (and internal tweaks) by jaraco · Pull Request #26992 · python/cpython

bpo-44554: refactor pdb targets (and internal tweaks) #26992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
miss-islington merged 14 commits into main from bpo-44461-refactor-targets
Jul 19, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-44554: refactor pdb targets (and internal tweaks) #26992

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
59b5906
Refactor module/script handling to share an interface (check method).
jaraco Jul 2, 2021
4df7611
Import functools and adjust tests for the new line number for find_fu…
jaraco Jul 2, 2021
86fbc39
Use cached_property for details.
jaraco Jul 2, 2021
825e35b
Add blurb.
jaraco Jul 2, 2021
914ec41
Add comments about 'orig'
jaraco Jul 2, 2021
b959e3e
Rely on singledispatch to dispatch the target.
jaraco Jul 2, 2021
4fdd84e
Ignore ModuleTarget in test_pyclbr. It trips up on the cached property.
jaraco Jul 2, 2021
9dfbe0c
Update blurb to reflect more than a refactor.
jaraco Jul 2, 2021
415ea29
Rename news to reference bpo-44554.
jaraco Jul 2, 2021
0d0bd5c
Add blurb
jaraco Jul 2, 2021
e21f085
Simplify changelog per suggestion.
jaraco Jul 18, 2021
fe8aea5
Replace singledispatch _run with a unified implementation selecting o…
jaraco Jul 18, 2021
0d8611c
Suppress spurious errors in pyclbr when it encounters properties and …
jaraco Jul 18, 2021
c91ba80
Make _spec and _details private.
jaraco Jul 18, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
Replace singledispatch _run with a unified implementation selecting o…
…n properties of the Target object.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
jaraco committed Jul 18, 2021
commit fe8aea5ae98c57cb98573b3dd0a04cb4fc3d12b0

There are no files selected for viewing

98 changes: 59 additions & 39 deletions 98 Lib/pdb.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import traceback
import linecache

from typing import Union


class Restart(Exception):
"""Causes a debugger to be restarted for the debugged python program."""
Expand Down Expand Up @@ -147,6 +149,23 @@ def check(self):
# Replace pdb's dir with script's dir in front of module search path.
sys.path[0] = os.path.dirname(self)

@property
def filename(self):
return self

@property
def namespace(self):
return dict(
__name__='__main__',
__file__=self,
__builtins__=__builtins__,
)

@property
def code(self):
with io.open(self) as fp:
return f"exec(compile({fp.read()!r}, {self!r}, 'exec'))"


class ModuleTarget(str):
def check(self):
Expand All @@ -157,6 +176,31 @@ def details(self):
import runpy
return runpy._get_module_details(self)

@property
def filename(self):
return self.code.co_filename

@property
def code(self):
name, spec, code = self.details
return code

@property
def spec(self):
name, spec, code = self.details
return spec

@property
def namespace(self):
return dict(
__name__='__main__',
__file__=os.path.normcase(os.path.abspath(self.filename)),
__package__=self.spec.parent,
__loader__=self.spec.loader,
__spec__=self.spec,
__builtins__=__builtins__,
)


# Interaction prompt line will separate file and call info from code
# text using value of line_prefix string. A newline and arrow may
Expand Down Expand Up @@ -1564,50 +1608,26 @@ def lookupmodule(self, filename):
return fullname
return None

@functools.singledispatchmethod
def _run(self, target: 'ModuleTarget'):
def _run(self, target: Union[ModuleTarget, ScriptTarget]):
# When bdb sets tracing, a number of call and line events happen
# BEFORE debugger even reaches user's code (and the exact sequence of
# events depends on python version). Take special measures to
# avoid stopping before reaching the main script (see user_line and
# user_call for details).
self._wait_for_mainpyfile = True
self._user_requested_quit = False
mod_name, mod_spec, code = target.details
self.mainpyfile = self.canonic(code.co_filename)
import __main__
__main__.__dict__.clear()
__main__.__dict__.update({
"__name__": "__main__",
"__file__": self.mainpyfile,
"__package__": mod_spec.parent,
"__loader__": mod_spec.loader,
"__spec__": mod_spec,
"__builtins__": __builtins__,
})
self.run(code)

@_run.register
def _(self, filename: 'ScriptTarget'):
# The script has to run in __main__ namespace (or imports from
# __main__ will break).
#
# So we clear up the __main__ and set several special variables
# (this gets rid of pdb's globals and cleans old variables on restarts).

self.mainpyfile = self.canonic(target.filename)

# The target has to run in __main__ namespace (or imports from
# __main__ will break). Clear __main__ and replace with
# the target namespace.
import __main__
__main__.__dict__.clear()
__main__.__dict__.update({"__name__" : "__main__",
"__file__" : filename,
"__builtins__": __builtins__,
})
__main__.__dict__.update(target.namespace)

self.run(target.code)

# When bdb sets tracing, a number of call and line events happens
# BEFORE debugger even reaches user's code (and the exact sequence of
# events depends on python version). So we take special measures to
# avoid stopping before we reach the main script (see user_line and
# user_call for details).
self._wait_for_mainpyfile = True
self.mainpyfile = self.canonic(filename)
self._user_requested_quit = False
with io.open_code(filename) as fp:
statement = "exec(compile(%r, %r, 'exec'))" % \
(fp.read(), self.mainpyfile)
self.run(statement)

# Collect all command help into docstring, if not run with -OO

Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/test/test_pdb.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_pdb_breakpoints_preserved_across_interactive_sessions():
1 breakpoint keep yes at ...test_pdb.py:...
2 breakpoint keep yes at ...test_pdb.py:...
(Pdb) break pdb.find_function
Breakpoint 3 at ...pdb.py:95
Breakpoint 3 at ...pdb.py:97
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep yes at ...test_pdb.py:...
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.