8000 [3.11] gh-86457: Fix signature for code.replace() (GH-23199) (GH-107746) · python/cpython@edaa0db · GitHub
[go: up one dir, main page]

Skip to content

Commit edaa0db

Browse files
[3.11] gh-86457: Fix signature for code.replace() (GH-23199) (GH-107746)
Also add support of @text_signature in Argument Clinic. (cherry picked from commit 0e6e32f)
1 parent 0aa3b9d commit edaa0db

File tree

4 files changed

+177
-172
lines changed

4 files changed

+177
-172
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Argument Clinic now supports overriding automatically generated signature by
2+
using directive ``@text_signature``.

Objects/clinic/codeobject.c.h

Lines changed: 14 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/codeobject.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,27 +1875,28 @@ code_linesiterator(PyCodeObject *code, PyObject *Py_UNUSED(args))
18751875
}
18761876

18771877
/*[clinic input]
1878+
@text_signature "($self, /, **changes)"
18781879
code.replace
18791880
18801881
*
1881-
co_argcount: int(c_default="self->co_argcount") = -1
1882-
co_posonlyargcount: int(c_default="self->co_posonlyargcount") = -1
1883-
co_kwonlyargcount: int(c_default="self->co_kwonlyargcount") = -1
1884-
co_nlocals: int(c_default="self->co_nlocals") = -1
1885-
co_stacksize: int(c_default="self->co_stacksize") = -1
1886-
co_flags: int(c_default="self->co_flags") = -1
1887-
co_firstlineno: int(c_default="self->co_firstlineno") = -1
1888-
co_code: PyBytesObject(c_default="NULL") = None
1889-
co_consts: object(subclass_of="&PyTuple_Type", c_default="self->co_consts") = None
1890-
co_names: object(subclass_of="&PyTuple_Type", c_default="self->co_names") = None
1891-
co_varnames: object(subclass_of="&PyTuple_Type", c_default="NULL") = None
1892-
co_freevars: object(subclass_of="&PyTuple_Type", c_default="NULL") = None
1893-
co_cellvars: object(subclass_of="&PyTuple_Type", c_default="NULL") = None
1894-
co_filename: unicode(c_default="self->co_filename") = None
1895-
co_name: unicode(c_default="self->co_name") = None
1896-
co_qualname: unicode(c_default="self->co_qualname") = None
1897-
co_linetable: PyBytesObject(c_default="(PyBytesObject *)self->co_linetable") = None
1898-
co_exceptiontable: PyBytesObject(c_default="(PyBytesObject *)self->co_exceptiontable") = None
1882+
co_argcount: int(c_default="self->co_argcount") = unchanged
1883+
co_posonlyargcount: int(c_default="self->co_posonlyargcount") = unchanged
1884+
co_kwonlyargcount: int(c_default="self->co_kwonlyargcount") = unchanged
1885+
co_nlocals: int(c_default="self->co_nlocals") = unchanged
1886+
co_stacksize: int(c_default="self->co_stacksize") = unchanged
1887+
co_flags: int(c_default="self->co_flags") = unchanged
1888+
co_firstlineno: int(c_default="self->co_firstlineno") = unchanged
1889+
co_code: object(subclass_of="&PyBytes_Type", c_default="NULL") = unchanged
1890+
co_consts: object(subclass_of="&PyTuple_Type", c_default="self->co_consts") = unchanged
1891+
co_names: object(subclass_of="&PyTuple_Type", c_default="self->co_names") = unchanged
1892+
co_varnames: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
1893+
co_freevars: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
1894+
co_cellvars: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
1895+
co_filename: unicode(c_default="self->co_filename") = unchanged
1896+
co_name: unicode(c_default="self->co_name") = unchanged
1897+
co_qualname: unicode(c_default="self->co_qualname") = unchanged
1898+
co_linetable: object(subclass_of="&PyBytes_Type", c_default="self->co_linetable") = unchanged
1899+
co_exceptiontable: object(subclass_of="&PyBytes_Type", c_default="self->co_exceptiontable") = unchanged
18991900
19001901
Return a copy of the code object with new values for the specified fields.
19011902
[clinic start generated code]*/
@@ -1904,14 +1905,13 @@ static PyObject *
19041905
code_replace_impl(PyCodeObject *self, int co_argcount,
19051906
int co_posonlyargcount, int co_kwonlyargcount,
19061907
int co_nlocals, int co_stacksize, int co_flags,
1907-
int co_firstlineno, PyBytesObject *co_code,
1908-
PyObject *co_consts, PyObject *co_names,
1909-
PyObject *co_varnames, PyObject *co_freevars,
1910-
PyObject *co_cellvars, PyObject *co_filename,
1911-
PyObject *co_name, PyObject *co_qualname,
1912-
PyBytesObject *co_linetable,
1913-
PyBytesObject *co_exceptiontable)
1914-
/*[clinic end generated code: output=b6cd9988391d5711 input=f6f68e03571f8d7c]*/
1908+
int co_firstlineno, PyObject *co_code, PyObject *co_consts,
1909+
PyObject *co_names, PyObject *co_varnames,
1910+
PyObject *co_freevars, PyObject *co_cellvars,
1911+
PyObject *co_filename, PyObject *co_name,
1912+
PyObject *co_qualname, PyObject *co_linetable,
1913+
PyObject *co_exceptiontable)
1914+
/*[clinic end generated code: output=e75c48a15def18b9 input=18e280e07846c122]*/
19151915
{
19161916
#define CHECK_INT_ARG(ARG) \
19171917
if (ARG < 0) { \
@@ -1936,7 +1936,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
19361936
if (code == NULL) {
19371937
return NULL;
19381938
}
1939-
co_code = (PyBytesObject *)code;
1939+
co_code = code;
19401940
}
19411941

19421942
if (PySys_Audit("code.__new__", "OOOiiiiii",
@@ -1975,10 +1975,10 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
19751975

19761976
co = PyCode_NewWithPosOnlyArgs(
19771977
co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals,
1978-
co_stacksize, co_flags, (PyObject*)co_code, co_consts, co_names,
1978+
co_stacksize, co_flags, co_code, co_consts, co_names,
19791979
co_varnames, co_freevars, co_cellvars, co_filename, co_name,
19801980
co_qualname, co_firstlineno,
1981-
(PyObject*)co_linetable, (PyObject*)co_exceptiontable);
1981+
co_linetable, co_exceptiontable);
19821982

19831983
error:
19841984
Py_XDECREF(code);

0 commit comments

Comments
 (0)
0