@@ -192,7 +192,7 @@ def may_be_immortal(self) -> bool:
192
192
def serialize (self ) -> str :
193
193
return "void"
194
194
195
- def __eq__ (self , other : object ) -> bool :
195
+ def __eq__ (self , other : object ) -> TypeGuard [ RVoid ] :
196
196
return isinstance (other , RVoid )
197
197
198
198
def __hash__ (self ) -> int :
@@ -279,7 +279,7 @@ def serialize(self) -> str:
279
279
def __repr__ (self ) -> str :
280
280
return "<RPrimitive %s>" % self .name
281
281
282
- def __eq__ (self , other : object ) -> bool :
282
+ def __eq__ (self , other : object ) -> TypeGuard [ RPrimitive ] :
283
283
return isinstance (other , RPrimitive ) and other .name == self .name
284
284
285
285
def __hash__ (self ) -> int :
@@ -513,15 +513,15 @@ def __hash__(self) -> int:
513
513
range_rprimitive : Final = RPrimitive ("builtins.range" , is_unboxed = False , is_refcounted = True )
514
514
515
515
516
- def is_tagged (rtype : RType ) -> bool :
516
+ def is_tagged (rtype : RType ) -> TypeGuard [ RPrimitive ] :
517
517
return rtype is int_rprimitive or rtype is short_int_rprimitive
518
518
519
519
520
- def is_int_rprimitive (rtype : RType ) -> bool :
520
+ def is_int_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
521
521
return rtype is int_rprimitive
522
522
523
523
524
- def is_short_int_rprimitive (rtype : RType ) -> bool :
524
+ def is_short_int_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
525
525
return rtype is short_int_rprimitive
526
526
527
527
@@ -535,7 +535,7 @@ def is_int32_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
535
535
)
536
536
537
537
538
- def is_int64_rprimitive (rtype : RType ) -> bool :
538
+ def is_int64_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
539
539
return rtype is int64_rprimitive or (
540
540
rtype is c_pyssize_t_rprimitive and rtype ._ctype == "int64_t"
541
541
)
@@ -554,79 +554,79 @@ def is_uint8_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
554
554
return rtype is uint8_rprimitive
555
555
556
556
557
- def is_uint32_rprimitive (rtype : RType ) -> bool :
557
+ def is_uint32_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
558
558
return rtype is uint32_rprimitive
559
559
560
560
561
- def is_uint64_rprimitive (rtype : RType ) -> bool :
561
+ def is_uint64_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
562
562
return rtype is uint64_rprimitive
563
563
564
564
565
- def is_c_py_ssize_t_rprimitive (rtype : RType ) -> bool :
565
+ def is_c_py_ssize_t_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
566
566
return rtype is c_pyssize_t_rprimitive
567
567
568
568
569
- def is_pointer_rprimitive (rtype : RType ) -> bool :
569
+ def is_pointer_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
570
570
return rtype is pointer_rprimitive
571
571
572
572
573
- def is_float_rprimitive (rtype : RType ) -> bool :
573
+ def is_float_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
574
574
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.float"
575
575
576
576
577
- def is_bool_rprimitive (rtype : RType ) -> bool :
577
+ def is_bool_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
578
578
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.bool"
579
579
580
580
581
- def is_bit_rprimitive (rtype : RType ) -> bool :
581
+ def is_bit_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
582
582
return isinstance (rtype , RPrimitive ) and rtype .name == "bit"
583
583
584
584
585
- def is_bool_or_bit_rprimitive (rtype : RType ) -> bool :
585
+ def is_bool_or_bit_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
586
586
return is_bool_rprimitive (rtype ) or is_bit_rprimitive (rtype )
587
587
588
588
589
- def is_object_rprimitive (rtype : RType ) -> bool :
589
+ def is_object_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
590
590
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.object"
591
591
592
592
593
- def is_none_rprimitive (rtype : RType ) -> bool :
593
+ def is_none_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
594
594
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.None"
595
595
596
596
597
- def is_list_rprimitive (rtype : RType ) -> bool :
597
+ def is_list_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
598
598
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.list"
599
599
600
600
601
- def is_dict_rprimitive (rtype : RType ) -> bool :
601
+ def is_dict_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
602
602
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.dict"
603
603
604
604
605
- def is_set_rprimitive (rtype : RType ) -> bool :
605
+ def is_set_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
606
606
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.set"
607
607
608
608
609
- def is_frozenset_rprimitive (rtype : RType ) -> bool :
609
+ def is_frozenset_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
610
610
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.frozenset"
611
611
612
612
613
- def is_str_rprimitive (rtype : RType ) -> bool :
613
+ def is_str_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
614
614
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.str"
615
615
616
616
617
- def is_bytes_rprimitive (rtype : RType ) -> bool :
617
+ def is_bytes_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
618
618
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.bytes"
619
619
620
620
621
- def is_tuple_rprimitive (rtype : RType ) -> bool :
621
+ def is_tuple_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
622
622
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.tuple"
623
623
624
624
625
- def is_range_rprimitive (rtype : RType ) -> bool :
625
+ def is_range_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
626
626
return isinstance (rtype , RPrimitive ) and rtype .name == "builtins.range"
627
627
628
628
629
- def is_sequence_rprimitive (rtype : RType ) -> bool :
629
+ def is_sequence_rprimitive (rtype : RType ) -> TypeGuard [ RPrimitive ] :
630
630
return isinstance (rtype , RPrimitive ) and (
631
631
is_list_rprimitive (rtype )
632
632
or is_tuple_rprimitive (rtype )
@@ -729,7 +729,7 @@ def __str__(self) -> str:
729
729
def __repr__ (self ) -> str :
730
730
return "<RTuple %s>" % ", " .join (repr (typ ) for typ in self .types )
731
731
732
- def __eq__ (self , other : object ) -> bool :
732
+ def __eq__ (self , other : object ) -> TypeGuard [ RTuple ] :
733
733
return isinstance (other , RTuple ) and self .types == other .types
734
734
735
735
def __hash__ (self ) -> int :
@@ -862,7 +862,7 @@ def __repr__(self) -> str:
862
862
", " .join (name + ":" + repr (typ ) for name , typ in zip (self .names , self .types )),
863
863
)
864
864
865
- def __eq__ (self , other : object ) -> bool :
865
+ def __eq__ (self , other : object ) -> TypeGuard [ RStruct ] :
866
866
return (
867
867
isinstance (other , RStruct )
868
868
and self .name == other .name
@@ -932,7 +932,7 @@ def attr_type(self, name: str) -> RType:
932
932
def __repr__ (self ) -> str :
933
933
return "<RInstance %s>" % self .name
934
934
935
- def __eq__ (self , other : object ) -> bool :
935
+ def __eq__ (self , other : object ) -> TypeGuard [ RInstance ] :
936
936
return isinstance (other , RInstance ) and other .name == self .name
937
937
938
938
def __hash__ (self ) -> int :
@@ -986,7 +986,7 @@ def __str__(self) -> str:
986
986
return "union[%s]" % ", " .join (str (item ) for item in self .items )
987
987
988
988
# We compare based on the set because order in a union doesn't matter
989
- def __eq__ (self , other : object ) -> bool :
989
+ def __eq__ (self , other : object ) -> TypeGuard [ RUnion ] :
990
990
return isinstance (other , RUnion ) and self .items_set == other .items_set
991
991
992
992
def __hash__ (self ) -> int :
@@ -1028,7 +1028,7 @@ def optional_value_type(rtype: RType) -> RType | None:
1028
1028
return None
1029
1029
1030
1030
1031
- def is_optional_type (rtype : RType ) -> bool :
1031
+ def is_optional_type (rtype : RType ) -> TypeGuard [ RUnion ] :
1032
1032
"""Is rtype an optional type with exactly two union items?"""
1033
1033
return optional_value_type (rtype ) is not None
1034
1034
@@ -1060,7 +1060,7 @@ def __str__(self) -> str:
1060
1060
def __repr__ (self ) -> str :
1061
1061
return f"<RArray { self .item_type !r} [{ self .length } ]>"
1062
1062
1063
- def __eq__ (self , other : object ) -> bool :
1063
+ def __eq__ (self , other : object ) -> TypeGuard [ RArray ] :
1064
1064
return (
1065
1065
isinstance (other , RArray )
1066
1066
and self .item_type == other .item_type
0 commit comments