mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-20201: variadic arguments support for AC (GH-18609)
Implement support for `*args` in AC, and port `print()` to use it.
This commit is contained in:
		
							parent
							
								
									7915c96ffd
								
							
						
					
					
						commit
						9af34c9351
					
				
					 8 changed files with 664 additions and 100 deletions
				
			
		
							
								
								
									
										76
									
								
								Python/clinic/bltinmodule.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										76
									
								
								Python/clinic/bltinmodule.c.h
									
										
									
										generated
									
									
									
								
							|  | @ -674,6 +674,80 @@ exit: | |||
|     return return_value; | ||||
| } | ||||
| 
 | ||||
| PyDoc_STRVAR(builtin_print__doc__, | ||||
| "print($module, /, *args, sep=\' \', end=\'\\n\', file=None, flush=False)\n" | ||||
| "--\n" | ||||
| "\n" | ||||
| "Prints the values to a stream, or to sys.stdout by default.\n" | ||||
| "\n" | ||||
| "  sep\n" | ||||
| "    string inserted between values, default a space.\n" | ||||
| "  end\n" | ||||
| "    string appended after the last value, default a newline.\n" | ||||
| "  file\n" | ||||
| "    a file-like object (stream); defaults to the current sys.stdout.\n" | ||||
| "  flush\n" | ||||
| "    whether to forcibly flush the stream."); | ||||
| 
 | ||||
| #define BUILTIN_PRINT_METHODDEF    \ | ||||
|     {"print", (PyCFunction)(void(*)(void))builtin_print, METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__}, | ||||
| 
 | ||||
| static PyObject * | ||||
| builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, | ||||
|                    PyObject *end, PyObject *file, int flush); | ||||
| 
 | ||||
| static PyObject * | ||||
| builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) | ||||
| { | ||||
|     PyObject *return_value = NULL; | ||||
|     static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL}; | ||||
|     static _PyArg_Parser _parser = {NULL, _keywords, "print", 0}; | ||||
|     PyObject *argsbuf[5]; | ||||
|     Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; | ||||
|     PyObject *__clinic_args = NULL; | ||||
|     PyObject *sep = Py_None; | ||||
|     PyObject *end = Py_None; | ||||
|     PyObject *file = Py_None; | ||||
|     int flush = 0; | ||||
| 
 | ||||
|     args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); | ||||
|     if (!args) { | ||||
|         goto exit; | ||||
|     } | ||||
|     __clinic_args = args[0]; | ||||
|     if (!noptargs) { | ||||
|         goto skip_optional_kwonly; | ||||
|     } | ||||
|     if (args[1]) { | ||||
|         sep = args[1]; | ||||
|         if (!--noptargs) { | ||||
|             goto skip_optional_kwonly; | ||||
|         } | ||||
|     } | ||||
|     if (args[2]) { | ||||
|         end = args[2]; | ||||
|         if (!--noptargs) { | ||||
|             goto skip_optional_kwonly; | ||||
|         } | ||||
|     } | ||||
|     if (args[3]) { | ||||
|         file = args[3]; | ||||
|         if (!--noptargs) { | ||||
|             goto skip_optional_kwonly; | ||||
|         } | ||||
|     } | ||||
|     flush = PyObject_IsTrue(args[4]); | ||||
|     if (flush < 0) { | ||||
|         goto exit; | ||||
|     } | ||||
| skip_optional_kwonly: | ||||
|     return_value = builtin_print_impl(module, __clinic_args, sep, end, file, flush); | ||||
| 
 | ||||
| exit: | ||||
|     Py_XDECREF(__clinic_args); | ||||
|     return return_value; | ||||
| } | ||||
| 
 | ||||
| PyDoc_STRVAR(builtin_input__doc__, | ||||
| "input($module, prompt=None, /)\n" | ||||
| "--\n" | ||||
|  | @ -877,4 +951,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) | |||
| exit: | ||||
|     return return_value; | ||||
| } | ||||
| /*[clinic end generated code: output=e1d8057298b5de61 input=a9049054013a1b77]*/ | ||||
| /*[clinic end generated code: output=77ace832b3fb38e0 input=a9049054013a1b77]*/ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Batuhan Taskaya
						Batuhan Taskaya