On Oct 2, 2017, at 17:36, Guido van Rossum <gu...@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.)

Cheers,
-Barry

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to