summaryrefslogtreecommitdiff
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2017-10-05 12:11:18 -0400
committerGitHub <noreply@github.com>2017-10-05 12:11:18 -0400
commit36c1d1f1e52ba54007cbecb42c5599e5ff62aa52 (patch)
tree317c296450800bfb25851dd92a62050e26c4c4fd /Python/bltinmodule.c
parent4d071897880b7e84e1a217ebe19971c118316970 (diff)
downloadcpython-git-36c1d1f1e52ba54007cbecb42c5599e5ff62aa52.tar.gz
PEP 553 built-in breakpoint() function (bpo-31353) (#3355)
Implement PEP 553, built-in breakpoint() with support from sys.breakpointhook(), along with documentation and tests. Closes bpo-31353
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 2269fe2165..6215a638c9 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -422,6 +422,28 @@ builtin_callable(PyObject *module, PyObject *obj)
return PyBool_FromLong((long)PyCallable_Check(obj));
}
+static PyObject *
+builtin_breakpoint(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *keywords)
+{
+ PyObject *hook = PySys_GetObject("breakpointhook");
+
+ if (hook == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.breakpointhook");
+ return NULL;
+ }
+ Py_INCREF(hook);
+ PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
+ Py_DECREF(hook);
+ return retval;
+}
+
+PyDoc_STRVAR(breakpoint_doc,
+"breakpoint(*args, **kws)\n\
+\n\
+Call sys.breakpointhook(*args, **kws). sys.breakpointhook() must accept\n\
+whatever arguments are passed.\n\
+\n\
+By default, this drops you into the pdb debugger.");
typedef struct {
PyObject_HEAD
@@ -2627,6 +2649,7 @@ static PyMethodDef builtin_methods[] = {
BUILTIN_ANY_METHODDEF
BUILTIN_ASCII_METHODDEF
BUILTIN_BIN_METHODDEF
+ {"breakpoint", (PyCFunction)builtin_breakpoint, METH_FASTCALL | METH_KEYWORDS, breakpoint_doc},
BUILTIN_CALLABLE_METHODDEF
BUILTIN_CHR_METHODDEF
BUILTIN_COMPILE_METHODDEF