Author: Yannick Jadoul <[email protected]>
Branch: py3.7-pep553
Changeset: r97791:075c2edf30ee
Date: 2019-10-12 23:44 +0200
http://bitbucket.org/pypy/pypy/changeset/075c2edf30ee/
Log: Implemented breakpoint and sys.breakpointhook from PEP 553
diff --git a/pypy/module/__builtin__/app_breakpoint.py
b/pypy/module/__builtin__/app_breakpoint.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/app_breakpoint.py
@@ -0,0 +1,16 @@
+# NOT_RPYTHON
+"""
+Plain Python definition of the builtin breakpoint function.
+"""
+
+import sys
+
+def breakpoint(*args, **kwargs):
+ """Call sys.breakpointhook(*args, **kws). sys.breakpointhook() must accept
+whatever arguments are passed.
+
+By default, this drops you into the pdb debugger."""
+
+ if not hasattr(sys, 'breakpointhook'):
+ raise RuntimeError('lost sys.breakpointhook')
+ return sys.breakpointhook(*args, **kwargs)
diff --git a/pypy/module/__builtin__/moduledef.py
b/pypy/module/__builtin__/moduledef.py
--- a/pypy/module/__builtin__/moduledef.py
+++ b/pypy/module/__builtin__/moduledef.py
@@ -23,6 +23,8 @@
'bin' : 'app_operation.bin',
'oct' : 'app_operation.oct',
'hex' : 'app_operation.hex',
+
+ 'breakpoint' : 'app_breakpoint.breakpoint',
}
interpleveldefs = {
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -68,6 +68,31 @@
except:
return False # got an exception again... ignore, report the original
+def breakpointhook(*args, **kwargs):
+ """This hook function is called by built-in breakpoint()."""
+
+ import importlib, os, warnings
+
+ hookname = os.getenv('PYTHONBREAKPOINT')
+ if hookname is None or len(hookname) == 0:
+ hookname = 'pdb.set_trace'
+ elif hookname == '0':
+ return None
+ modname, dot, funcname = hookname.rpartition('.')
+ if dot == '':
+ modname = 'builtins'
+
+ try:
+ module = importlib.import_module(modname)
+ hook = getattr(module, funcname)
+ except:
+ warnings.warn(
+ 'Ignoring unimportable $PYTHONBREAKPOINT: "{}"'.format(hookname),
+ RuntimeWarning)
+ return None
+
+ return hook(*args, **kwargs)
+
def exit(exitcode=None):
"""Exit the interpreter by raising SystemExit(exitcode).
If the exitcode is omitted or None, it defaults to zero (i.e., success).
diff --git a/pypy/module/sys/moduledef.py b/pypy/module/sys/moduledef.py
--- a/pypy/module/sys/moduledef.py
+++ b/pypy/module/sys/moduledef.py
@@ -109,6 +109,8 @@
appleveldefs = {
'excepthook' : 'app.excepthook',
'__excepthook__' : 'app.excepthook',
+ 'breakpointhook' : 'app.breakpointhook',
+ '__breakpointhook__' : 'app.breakpointhook',
'exit' : 'app.exit',
'callstats' : 'app.callstats',
'copyright' : 'app.copyright_str',
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit