File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -256,8 +256,13 @@ is_unionable(PyObject *obj)
256256PyObject *
257257_Py_union_type_or (PyObject * self , PyObject * other )
258258{
259+ if (!is_unionable (self ) || !is_unionable (other )) {
260+ Py_RETURN_NOTIMPLEMENTED ;
261+ }
262+
259263 unionbuilder ub ;
260- if (!unionbuilder_init (& ub , true)) {
264+ // unchecked because we already checked is_unionable()
265+ if (!unionbuilder_init (& ub , false)) {
261266 return NULL ;
262267 }
263268 if (!unionbuilder_add_single (& ub , self ) ||
@@ -388,8 +393,23 @@ static PyGetSetDef union_properties[] = {
388393 {0 }
389394};
390395
396+ static PyObject *
397+ union_nb_or (PyObject * a , PyObject * b )
398+ {
399+ unionbuilder ub ;
400+ if (!unionbuilder_init (& ub , true)) {
401+ return NULL ;
402+ }
403+ if (!unionbuilder_add_single (& ub , a ) ||
404+ !unionbuilder_add_single (& ub , b )) {
405+ unionbuilder_finalize (& ub );
406+ return NULL ;
407+ }
408+ return make_union (& ub );
409+ }
410+
391411static PyNumberMethods union_as_number = {
392- .nb_or = _Py_union_type_or , // Add __or__ function
412+ .nb_or = union_nb_or , // Add __or__ function
393413};
394414
395415static const char * const cls_attrs [] = {
You can’t perform that action at this time.
0 commit comments