Skip to content

Commit a0252ab

Browse files
committed
expose co_qualname to Python
1 parent 008cb5a commit a0252ab

File tree

13 files changed

+5578
-5452
lines changed

13 files changed

+5578
-5452
lines changed

Include/cpython/code.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ struct PyCodeObject {
7575
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte per variable) */
7676
PyObject *co_filename; /* unicode (where it was loaded from) */
7777
PyObject *co_name; /* unicode (name, for reference) */
78-
PyObject *co_qualname; /* unicode (qualname, only for code objects created
79-
by the compiler, otherwise NULL) */
78+
PyObject *co_qualname; /* unicode (qualname, for reference) */
8079
PyObject *co_linetable; /* string (encoding addr<->lineno mapping) See
8180
Objects/lnotab_notes.txt for details. */
8281

@@ -151,12 +150,12 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
151150
PyAPI_FUNC(PyCodeObject *) PyCode_New(
152151
int, int, int, int, int, PyObject *, PyObject *,
153152
PyObject *, PyObject *, PyObject *, PyObject *,
154-
PyObject *, PyObject *, int, PyObject *, PyObject *);
153+
PyObject *, PyObject *, PyObject *, int, PyObject *, PyObject *);
155154

156155
PyAPI_FUNC(PyCodeObject *) PyCode_NewWithPosOnlyArgs(
157156
int, int, int, int, int, int, PyObject *, PyObject *,
158157
PyObject *, PyObject *, PyObject *, PyObject *,
159-
PyObject *, PyObject *, int, PyObject *, PyObject *);
158+
PyObject *, PyObject *, PyObject *, int, PyObject *, PyObject *);
160159
/* same as struct above */
161160

162161
/* Creates a new empty code object with the specified source location. */

Lib/ctypes/test/test_values.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ class struct_frozen(Structure):
8080
continue
8181
items.append((entry.name.decode("ascii"), entry.size))
8282

83-
expected = [("__hello__", 133),
84-
("__phello__", -133),
85-
("__phello__.spam", 133),
83+
expected = [("__hello__", 138),
84+
("__phello__", -138),
85+
("__phello__.spam", 138),
8686
]
8787
self.assertEqual(items, expected, "PyImport_FrozenModules example "
8888
"in Doc/library/ctypes.rst may be out of date")

Lib/test/test_code.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,19 @@ def func(): pass
221221
co.co_varnames,
222222
co.co_filename,
223223
co.co_name,
224+
co.co_qualname,
224225
co.co_firstlineno,
225226
co.co_lnotab,
226227
co.co_exceptiontable,
227228
co.co_freevars,
228229
co.co_cellvars)
229230

231+
def test_qualname(self):
232+
self.assertEqual(
233+
CodeTest.test_qualname.__code__.co_qualname,
234+
CodeTest.test_qualname.__qualname__
235+
)
236+
230237
def test_replace(self):
231238
def func():
232239
x = 1
@@ -291,6 +298,7 @@ def func():
291298
co.co_varnames,
292299
co.co_filename,
293300
co.co_name,
301+
co.co_qualname,
294302
co.co_firstlineno,
295303
co.co_lnotab,
296304
co.co_exceptiontable,
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Added the co_qualname to the PyCodeObject structure to propagate the
2-
qualified name from the compiler to code objects. Code objects that are
3-
created manually have this new field set to NULL.
2+
qualified name from the compiler to code objects.
43

54
Patch by Gabriele N. Tornetta

Objects/clinic/codeobject.c.h

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

0 commit comments

Comments
 (0)