@@ -48,73 +48,6 @@ union_hash(PyObject *self)
48
48
return hash ;
49
49
}
50
50
51
- static int
52
- is_generic_alias_in_args (PyObject * args )
53
- {
54
- Py_ssize_t nargs = PyTuple_GET_SIZE (args );
55
- for (Py_ssize_t iarg = 0 ; iarg < nargs ; iarg ++ ) {
56
- PyObject * arg = PyTuple_GET_ITEM (args , iarg );
57
- if (_PyGenericAlias_Check (arg )) {
58
- return 0 ;
59
- }
60
- }
61
- return 1 ;
62
- }
63
-
64
- static PyObject *
65
- union_instancecheck (PyObject * self , PyObject * instance )
66
- {
67
- unionobject * alias = (unionobject * ) self ;
68
- Py_ssize_t nargs = PyTuple_GET_SIZE (alias -> args );
69
- if (!is_generic_alias_in_args (alias -> args )) {
70
- PyErr_SetString (PyExc_TypeError ,
71
- "isinstance() argument 2 cannot contain a parameterized generic" );
72
- return NULL ;
73
- }
74
- for (Py_ssize_t iarg = 0 ; iarg < nargs ; iarg ++ ) {
75
- PyObject * arg = PyTuple_GET_ITEM (alias -> args , iarg );
76
- if (PyType_Check (arg )) {
77
- int res = PyObject_IsInstance (instance , arg );
78
- if (res < 0 ) {
79
- return NULL ;
80
- }
81
- if (res ) {
82
- Py_RETURN_TRUE ;
83
- }
84
- }
85
- }
86
- Py_RETURN_FALSE ;
87
- }
88
-
89
- static PyObject *
90
- union_subclasscheck (PyObject * self , PyObject * instance )
91
- {
92
- if (!PyType_Check (instance )) {
93
- PyErr_SetString (PyExc_TypeError , "issubclass() arg 1 must be a class" );
94
- return NULL ;
95
- }
96
- unionobject * alias = (unionobject * )self ;
97
- if (!is_generic_alias_in_args (alias -> args )) {
98
- PyErr_SetString (PyExc_TypeError ,
99
- "issubclass() argument 2 cannot contain a parameterized generic" );
100
- return NULL ;
101
- }
102
- Py_ssize_t nargs = PyTuple_GET_SIZE (alias -> args );
103
- for (Py_ssize_t iarg = 0 ; iarg < nargs ; iarg ++ ) {
104
- PyObject * arg = PyTuple_GET_ITEM (alias -> args , iarg );
105
- if (PyType_Check (arg )) {
106
- int res = PyObject_IsSubclass (instance , arg );
107
- if (res < 0 ) {
108
- return NULL ;
109
- }
110
- if (res ) {
111
- Py_RETURN_TRUE ;
112
- }
113
- }
114
- }
115
- Py_RETURN_FALSE ;
116
- }
117
-
118
51
static PyObject *
119
52
union_richcompare (PyObject * a , PyObject * b , int op )
120
53
{
@@ -342,12 +275,6 @@ static PyMemberDef union_members[] = {
342
275
{0 }
343
276
};
344
277
345
- static PyMethodDef union_methods [] = {
346
- {"__instancecheck__" , union_instancecheck , METH_O },
347
- {"__subclasscheck__" , union_subclasscheck , METH_O },
348
- {0 }};
349
-
350
-
351
278
static PyObject *
352
279
union_getitem (PyObject * self , PyObject * item )
353
280
{
@@ -434,6 +361,13 @@ union_getattro(PyObject *self, PyObject *name)
434
361
return PyObject_GenericGetAttr (self , name );
435
362
}
436
363
364
+ PyObject *
365
+ _Py_union_args (PyObject * self )
366
+ {
367
+ assert (_PyUnion_Check (self ));
368
+ return ((unionobject * ) self )-> args ;
369
+ }
370
+
437
371
PyTypeObject _PyUnion_Type = {
438
372
PyVarObject_HEAD_INIT (& PyType_Type , 0 )
439
373
.tp_name = "types.UnionType" ,
@@ -449,7 +383,6 @@ PyTypeObject _PyUnion_Type = {
449
383
.tp_hash = union_hash ,
450
384
.tp_getattro = union_getattro ,
451
385
.tp_members = union_members ,
452
- .tp_methods = union_methods ,
453
386
.tp_richcompare = union_richcompare ,
454
387
.tp_as_mapping = & union_as_mapping ,
455
388
.tp_as_number = & union_as_number ,
0 commit comments