4
4
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
5
5
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
6
6
#include "pycore_object.h"
7
+ #include "pycore_typevarobject.h" // _Py_typing_type_repr
7
8
#include "pycore_unionobject.h" // _Py_union_type_or, _PyGenericAlias_Check
8
9
9
10
@@ -50,69 +51,6 @@ ga_traverse(PyObject *self, visitproc visit, void *arg)
50
51
return 0 ;
51
52
}
52
53
53
- static int
54
- ga_repr_item (PyUnicodeWriter * writer , PyObject * p )
55
- {
56
- PyObject * qualname = NULL ;
57
- PyObject * module = NULL ;
58
- int rc ;
59
-
60
- if (p == Py_Ellipsis ) {
61
- // The Ellipsis object
62
- rc = PyUnicodeWriter_WriteUTF8 (writer , "..." , 3 );
63
- goto done ;
64
- }
65
-
66
- if ((rc = PyObject_HasAttrWithError (p , & _Py_ID (__origin__ ))) > 0 &&
67
- (rc = PyObject_HasAttrWithError (p , & _Py_ID (__args__ ))) > 0 )
68
- {
69
- // It looks like a GenericAlias
70
- goto use_repr ;
71
- }
72
- if (rc < 0 ) {
73
- goto error ;
74
- }
75
-
76
- if (PyObject_GetOptionalAttr (p , & _Py_ID (__qualname__ ), & qualname ) < 0 ) {
77
- goto error ;
78
- }
79
- if (qualname == NULL ) {
80
- goto use_repr ;
81
- }
82
- if (PyObject_GetOptionalAttr (p , & _Py_ID (__module__ ), & module ) < 0 ) {
83
- goto error ;
84
- }
85
- if (module == NULL || module == Py_None ) {
86
- goto use_repr ;
87
- }
88
-
89
- // Looks like a class
90
- if (PyUnicode_Check (module ) &&
91
- _PyUnicode_EqualToASCIIString (module , "builtins" ))
92
- {
93
- // builtins don't need a module name
94
- rc = PyUnicodeWriter_WriteStr (writer , qualname );
95
- goto done ;
96
- }
97
- else {
98
- rc = PyUnicodeWriter_Format (writer , "%S.%S" , module , qualname );
99
- goto done ;
100
- }
101
-
102
- error :
103
- rc = -1 ;
104
- goto done ;
105
-
106
- use_repr :
107
- rc = PyUnicodeWriter_WriteRepr (writer , p );
108
- goto done ;
109
-
110
- done :
111
- Py_XDECREF (qualname );
112
- Py_XDECREF (module );
113
- return rc ;
114
- }
115
-
116
54
static int
117
55
ga_repr_items_list (PyUnicodeWriter * writer , PyObject * p )
118
56
{
@@ -131,7 +69,7 @@ ga_repr_items_list(PyUnicodeWriter *writer, PyObject *p)
131
69
}
132
70
}
133
71
PyObject * item = PyList_GET_ITEM (p , i );
134
- if (ga_repr_item (writer , item ) < 0 ) {
72
+ if (_Py_typing_type_repr (writer , item ) < 0 ) {
135
73
return -1 ;
136
74
}
137
75
}
@@ -162,7 +100,7 @@ ga_repr(PyObject *self)
162
100
goto error ;
163
101
}
164
102
}
165
- if (ga_repr_item (writer , alias -> origin ) < 0 ) {
103
+ if (_Py_typing_type_repr (writer , alias -> origin ) < 0 ) {
166
104
goto error ;
167
105
}
168
106
if (PyUnicodeWriter_WriteChar (writer , '[' ) < 0 ) {
@@ -181,7 +119,7 @@ ga_repr(PyObject *self)
181
119
goto error ;
182
120
}
183
121
}
184
- else if (ga_repr_item (writer , p ) < 0 ) {
122
+ else if (_Py_typing_type_repr (writer , p ) < 0 ) {
185
123
goto error ;
186
124
}
187
125
}
0 commit comments