mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									4d07189788
								
							
						
					
					
						commit
						36c1d1f1e5
					
				
					 9 changed files with 324 additions and 23 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barry Warsaw
						Barry Warsaw