[Python-Dev] PEP 553

Guido van Rossum guido at python.org
Mon Oct 2 18:43:50 EDT 2017


On Mon, Oct 2, 2017 at 3:03 PM, Barry Warsaw <barry at python.org> wrote:

> On Oct 2, 2017, at 17:36, Guido van Rossum <guido at python.org> wrote:
>
> > I've seen your updates and it is now acceptable, except for *one* nit:
> in builtins.breakpoint() the pseudo code raises RuntimeError if
> sys.breakpointhook is missing or None. OTOH sys.breakpointhook() just
> issues a RuntimeWarning when something's wrong with the hook. Maybe
> builtins.breakpoint() should also just warn if it can't find the hook?
> Setting `sys.breakpointhook = None` might be the simplest way to
> programmatically disable breakpoints. Why not allow it?
>
> Oh, actually the pseudocode doesn’t match the C implementation exactly in
> this regard.  Currently the C implementation is more like:
>
>     def breakpoint(*args, **kws):
>         import sys
>         missing = object()
>         hook = getattr(sys, 'breakpointhook', missing)
>         if hook is missing:
>             raise RuntimeError('lost sys.breakpointhook')
>         return hook(*args, **kws)
>
> The intent being, much like the other sys-hooks, that if PySys_GetObject("breakpointhook”)
> returns NULL, Something Bad Happened, so we have to set an error string and
> bail.  (PySys_GetObject() does not set an exception.)
>
> E.g.
>
> >>> def foo():
> ...   print('yes')
> ...   breakpoint()
> ...   print('no')
> ...
> >>> del sys.breakpointhook
> >>> foo()
> yes
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 3, in foo
> RuntimeError: lost sys.breakpointhook
>
>
> Setting `sys.breakpoint = None` could be an interesting use case, but
> that’s not currently special in any way:
>
> >>> sys.breakpointhook = None
> >>> foo()
> yes
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 3, in foo
> TypeError: 'NoneType' object is not callable
>
>
> I’m open to special-casing this if you think it’s useful.
>
> (I’ll update the pseudocode in the PEP.)
>

OK. That then concludes the review of your PEP. It is now accepted!
Congrats. I am looking forward to using the backport. :-)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171002/177c4e56/attachment-0001.html>


More information about the Python-Dev mailing list