mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
[3.14] gh-132661: Add default value (of "") for Interpolation.expression (GH-136441) (#136511)
Co-authored-by: Dave Peck <davepeck@gmail.com>
This commit is contained in:
parent
da8bcfd949
commit
95baa28d9f
5 changed files with 58 additions and 27 deletions
23
Objects/clinic/interpolationobject.c.h
generated
23
Objects/clinic/interpolationobject.c.h
generated
|
|
@ -47,26 +47,31 @@ interpolation_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *argsbuf[4];
|
||||
PyObject * const *fastargs;
|
||||
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
|
||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
|
||||
PyObject *value;
|
||||
PyObject *expression;
|
||||
PyObject *expression = &_Py_STR(empty);
|
||||
PyObject *conversion = Py_None;
|
||||
PyObject *format_spec = &_Py_STR(empty);
|
||||
|
||||
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
|
||||
/*minpos*/ 2, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
/*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!fastargs) {
|
||||
goto exit;
|
||||
}
|
||||
value = fastargs[0];
|
||||
if (!PyUnicode_Check(fastargs[1])) {
|
||||
_PyArg_BadArgument("Interpolation", "argument 'expression'", "str", fastargs[1]);
|
||||
goto exit;
|
||||
}
|
||||
expression = fastargs[1];
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
if (fastargs[1]) {
|
||||
if (!PyUnicode_Check(fastargs[1])) {
|
||||
_PyArg_BadArgument("Interpolation", "argument 'expression'", "str", fastargs[1]);
|
||||
goto exit;
|
||||
}
|
||||
expression = fastargs[1];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
}
|
||||
if (fastargs[2]) {
|
||||
if (!_conversion_converter(fastargs[2], &conversion)) {
|
||||
goto exit;
|
||||
|
|
@ -86,4 +91,4 @@ skip_optional_pos:
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=599742a5ccd6f060 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=2391391e2d7708c0 input=a9049054013a1b77]*/
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ typedef struct {
|
|||
Interpolation.__new__ as interpolation_new
|
||||
|
||||
value: object
|
||||
expression: object(subclass_of='&PyUnicode_Type')
|
||||
expression: object(subclass_of='&PyUnicode_Type', c_default='&_Py_STR(empty)') = ""
|
||||
conversion: object(converter='_conversion_converter') = None
|
||||
format_spec: object(subclass_of='&PyUnicode_Type', c_default='&_Py_STR(empty)') = ""
|
||||
[clinic start generated code]*/
|
||||
|
|
@ -63,7 +63,7 @@ static PyObject *
|
|||
interpolation_new_impl(PyTypeObject *type, PyObject *value,
|
||||
PyObject *expression, PyObject *conversion,
|
||||
PyObject *format_spec)
|
||||
/*[clinic end generated code: output=6488e288765bc1a9 input=d91711024068528c]*/
|
||||
/*[clinic end generated code: output=6488e288765bc1a9 input=fc5c285c1dd23d36]*/
|
||||
{
|
||||
interpolationobject *self = PyObject_GC_New(interpolationobject, type);
|
||||
if (!self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue