Guido prefers built-in breakpoint().
This commit is contained in:
parent
f6cdc14509
commit
2833cb48ce
71
pep-0553.rst
71
pep-0553.rst
|
@ -1,5 +1,5 @@
|
||||||
PEP: 553
|
PEP: 553
|
||||||
Title: Built-in debug()
|
Title: Built-in breakpoint()
|
||||||
Author: Barry Warsaw <barry@python.org>
|
Author: Barry Warsaw <barry@python.org>
|
||||||
Status: Draft
|
Status: Draft
|
||||||
Type: Standards Track
|
Type: Standards Track
|
||||||
|
@ -12,7 +12,7 @@ Post-History:
|
||||||
Abstract
|
Abstract
|
||||||
========
|
========
|
||||||
|
|
||||||
This PEP proposes adding a new built-in function called ``debug()`` which
|
This PEP proposes adding a new built-in function called ``breakpoint()`` which
|
||||||
enters a Python debugger at the point of the call. Additionally, two new
|
enters a Python debugger at the point of the call. Additionally, two new
|
||||||
names are added to the ``sys`` module to make the debugger pluggable.
|
names are added to the ``sys`` module to make the debugger pluggable.
|
||||||
|
|
||||||
|
@ -53,49 +53,53 @@ Proposal
|
||||||
The JavaScript language provides a ``debugger`` statement [2]_ which enters
|
The JavaScript language provides a ``debugger`` statement [2]_ which enters
|
||||||
the debugger at the point where the statement appears.
|
the debugger at the point where the statement appears.
|
||||||
|
|
||||||
This PEP proposes a new built-in function called ``debug()`` which enters a
|
This PEP proposes a new built-in function called ``breakpoint()``
|
||||||
Python debugger at the call site. Thus the example above would be written
|
which enters a Python debugger at the call site. Thus the example
|
||||||
like so::
|
above would be written like so::
|
||||||
|
|
||||||
foo()
|
foo()
|
||||||
debug()
|
breakpoint()
|
||||||
bar()
|
bar()
|
||||||
|
|
||||||
Built-in ``debug()`` takes no arguments.
|
Built-in ``breakpoint()`` takes no arguments.
|
||||||
|
|
||||||
Further, this PEP proposes two new name bindings for the ``sys`` module,
|
Further, this PEP proposes two new name bindings for the ``sys``
|
||||||
called ``debughook()`` and ``__debughook__``. By default, ``sys.debughook()``
|
module, called ``sys.breakpointhook()`` and
|
||||||
implements the actual importing and entry into ``pdb.set_trace()``, and it can
|
``sys.__breakpointhook__``. By default, ``sys.breakpointhook()``
|
||||||
be set to a different function to change the debugger that ``debug()`` enters.
|
implements the actual importing and entry into ``pdb.set_trace()``,
|
||||||
``sys.__debughook__`` then stashes the default value of ``sys.debughook()`` to
|
and it can be set to a different function to change the debugger that
|
||||||
make it easy to reset. This exactly models the existing ``sys.displayhook()``
|
``breakpoint()`` enters. ``sys.__breakpointhook__`` then stashes the
|
||||||
/ ``sys.__displayhook__`` and ``sys.excepthook()`` / ``sys.__excepthook__``
|
default value of ``sys.breakpointhook()`` to make it easy to reset.
|
||||||
hooks [3]_.
|
This exactly models the existing ``sys.displayhook()`` /
|
||||||
|
``sys.__displayhook__`` and ``sys.excepthook()`` /
|
||||||
|
``sys.__excepthook__`` hooks [3]_.
|
||||||
|
|
||||||
``sys.displayhook()`` would be called with no arguments. It returns whatever
|
``sys.breakpointhook()`` would be called with no arguments. It
|
||||||
is returned from the underlying debugger entry point. ``debug()`` returns
|
returns whatever is returned from the underlying debugger entry point.
|
||||||
whatever ``sys.displayhook()`` returns.
|
``breakpoint()`` returns whatever ``sys.breakpointhook()`` returns.
|
||||||
|
|
||||||
|
|
||||||
Open issues
|
Open issues
|
||||||
===========
|
===========
|
||||||
|
|
||||||
We want to get confirmation from at least one alternative debugger
|
We want to get confirmation from at least one alternative debugger
|
||||||
implementation (e.g. PyCharm) that the hooks provided in this PEP will be
|
implementation (e.g. PyCharm) that the hooks provided in this PEP will
|
||||||
useful to them.
|
be useful to them.
|
||||||
|
|
||||||
Related, there has been an idea to add a bytecode that calls
|
Related, there has been an idea to add a bytecode that calls
|
||||||
``sys.debughook()``. Whether built-in ``debug()`` emits this bytecode (or
|
``sys.breakpointhook()``. Whether built-in ``breakpoint()`` emits
|
||||||
gets peephole optimized to the bytecode) is an open issue. The bytecode is
|
this bytecode (or gets peephole optimized to the bytecode) is an open
|
||||||
useful for debuggers that actively modify bytecode streams to trampoline into
|
issue. The bytecode is useful for debuggers that actively modify
|
||||||
their own debugger. Having a "debug" bytecode might allow them to avoid
|
bytecode streams to trampoline into their own debugger. Having a
|
||||||
bytecode modification in order to invoke this trampoline.
|
"breakpoint" bytecode might allow them to avoid bytecode modification
|
||||||
|
in order to invoke this trampoline. *NOTE*: It probably makes sense to split
|
||||||
|
this idea into a separate PEP.
|
||||||
|
|
||||||
Does it make sense to define the built-in function's signature as
|
Does it make sense to define the built-in function's signature as
|
||||||
``debug(*args, **kws)`` which would just be passed along to the
|
``breakpoint(*args, **kws)`` which would just be passed along to the
|
||||||
``sys.debughook()``? One argument for doing this is that it would allow users
|
``sys.breakpointhook()``? One argument for doing this is that it
|
||||||
to pass useful arguments to their actual debugger. This isn't useful for
|
would allow users to pass useful arguments to their actual debugger.
|
||||||
``pdb`` but might be useful for alternatives.
|
This isn't useful for ``pdb`` but might be useful for alternatives.
|
||||||
|
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
|
@ -127,14 +131,15 @@ existing keyword such as ``break here``. This is rejected on several fronts.
|
||||||
no existing code (since any existing module global would just shadow the
|
no existing code (since any existing module global would just shadow the
|
||||||
built-in) and is quite easy to implement.
|
built-in) and is quite easy to implement.
|
||||||
|
|
||||||
sys.debug()
|
|
||||||
-----------
|
|
||||||
|
|
||||||
Why not ``sys.debug()``? Requiring an import to invoke the debugger is
|
sys.breakpoint()
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Why not ``sys.breakpoint()``? Requiring an import to invoke the debugger is
|
||||||
explicitly rejected because ``sys`` is not imported in every module. That
|
explicitly rejected because ``sys`` is not imported in every module. That
|
||||||
just requires more typing and would lead to::
|
just requires more typing and would lead to::
|
||||||
|
|
||||||
import sys; sys.debug()
|
import sys; sys.breakpoint()
|
||||||
|
|
||||||
which inherits several of the problems this PEP aims to solve.
|
which inherits several of the problems this PEP aims to solve.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue