File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ impl PyUnion {
41
41
}
42
42
43
43
/// Direct access to args field, matching CPython's _Py_union_args
44
- pub ( crate ) fn get_args ( & self ) -> & PyTupleRef {
44
+ #[ inline]
45
+ pub fn args ( & self ) -> & PyTupleRef {
45
46
& self . args
46
47
}
47
48
Original file line number Diff line number Diff line change @@ -513,7 +513,7 @@ impl PyObject {
513
513
let union = cls
514
514
. downcast_ref :: < crate :: builtins:: PyUnion > ( )
515
515
. expect ( "union is already checked" ) ;
516
- union. get_args ( ) . as_object ( )
516
+ union. args ( ) . as_object ( )
517
517
} else {
518
518
cls
519
519
} ;
@@ -602,16 +602,14 @@ impl PyObject {
602
602
603
603
// Check for Union type (e.g., int | str) - CPython checks this before tuple
604
604
if cls. class ( ) . is ( vm. ctx . types . union_type ) {
605
- if let Ok ( args) = cls. get_attr ( identifier ! ( vm, __args__) , vm) {
606
- if let Ok ( tuple) = args. try_to_ref :: < PyTuple > ( vm) {
607
- for typ in tuple {
608
- if vm
609
- . with_recursion ( "in __instancecheck__" , || self . is_instance ( typ, vm) ) ?
610
- {
611
- return Ok ( true ) ;
612
- }
613
- }
614
- return Ok ( false ) ;
605
+ // Match CPython's _Py_union_args which directly accesses the args field
606
+ let union = cls
607
+ . try_to_ref :: < crate :: builtins:: PyUnion > ( vm)
608
+ . expect ( "checked by is" ) ;
609
+ let tuple = union. args ( ) ;
610
+ for typ in tuple. iter ( ) {
611
+ if vm. with_recursion ( "in __instancecheck__" , || self . is_instance ( typ, vm) ) ? {
612
+ return Ok ( true ) ;
615
613
}
616
614
}
617
615
}
You can’t perform that action at this time.
0 commit comments