mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	evaluate positional defaults before keyword-only defaults (closes #16967)
This commit is contained in:
		
							parent
							
								
									34a2a87d17
								
							
						
					
					
						commit
						1ef876cd28
					
				
					 7 changed files with 161 additions and 147 deletions
				
			
		|  | @ -2901,23 +2901,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | |||
|             } | ||||
| 
 | ||||
|             /* XXX Maybe this should be a separate opcode? */ | ||||
|             if (posdefaults > 0) { | ||||
|                 PyObject *defs = PyTuple_New(posdefaults); | ||||
|                 if (defs == NULL) { | ||||
|                     Py_DECREF(func); | ||||
|                     goto error; | ||||
|                 } | ||||
|                 while (--posdefaults >= 0) | ||||
|                     PyTuple_SET_ITEM(defs, posdefaults, POP()); | ||||
|                 if (PyFunction_SetDefaults(func, defs) != 0) { | ||||
|                     /* Can't happen unless
 | ||||
|                        PyFunction_SetDefaults changes. */ | ||||
|                     Py_DECREF(defs); | ||||
|                     Py_DECREF(func); | ||||
|                     goto error; | ||||
|                 } | ||||
|                 Py_DECREF(defs); | ||||
|             } | ||||
|             if (kwdefaults > 0) { | ||||
|                 PyObject *defs = PyDict_New(); | ||||
|                 if (defs == NULL) { | ||||
|  | @ -2945,6 +2928,23 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | |||
|                 } | ||||
|                 Py_DECREF(defs); | ||||
|             } | ||||
|             if (posdefaults > 0) { | ||||
|                 PyObject *defs = PyTuple_New(posdefaults); | ||||
|                 if (defs == NULL) { | ||||
|                     Py_DECREF(func); | ||||
|                     goto error; | ||||
|                 } | ||||
|                 while (--posdefaults >= 0) | ||||
|                     PyTuple_SET_ITEM(defs, posdefaults, POP()); | ||||
|                 if (PyFunction_SetDefaults(func, defs) != 0) { | ||||
|                     /* Can't happen unless
 | ||||
|                        PyFunction_SetDefaults changes. */ | ||||
|                     Py_DECREF(defs); | ||||
|                     Py_DECREF(func); | ||||
|                     goto error; | ||||
|                 } | ||||
|                 Py_DECREF(defs); | ||||
|             } | ||||
|             PUSH(func); | ||||
|             DISPATCH(); | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Benjamin Peterson
						Benjamin Peterson