Skip to content

Commit f595d24

Browse files
committed
rtypes
1 parent d93c207 commit f595d24

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

mypyc/ir/rtypes.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def may_be_immortal(self) -> bool:
192192
def serialize(self) -> str:
193193
return "void"
194194

195-
def __eq__(self, other: object) -> bool:
195+
def __eq__(self, other: object) -> TypeGuard[RVoid]:
196196
return isinstance(other, RVoid)
197197

198198
def __hash__(self) -> int:
@@ -279,7 +279,7 @@ def serialize(self) -> str:
279279
def __repr__(self) -> str:
280280
return "<RPrimitive %s>" % self.name
281281

282-
def __eq__(self, other: object) -> bool:
282+
def __eq__(self, other: object) -> TypeGuard[RPrimitive]:
283283
return isinstance(other, RPrimitive) and other.name == self.name
284284

285285
def __hash__(self) -> int:
@@ -513,15 +513,15 @@ def __hash__(self) -> int:
513513
range_rprimitive: Final = RPrimitive("builtins.range", is_unboxed=False, is_refcounted=True)
514514

515515

516-
def is_tagged(rtype: RType) -> bool:
516+
def is_tagged(rtype: RType) -> TypeGuard[RPrimitive]:
517517
return rtype is int_rprimitive or rtype is short_int_rprimitive
518518

519519

520-
def is_int_rprimitive(rtype: RType) -> bool:
520+
def is_int_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
521521
return rtype is int_rprimitive
522522

523523

524-
def is_short_int_rprimitive(rtype: RType) -> bool:
524+
def is_short_int_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
525525
return rtype is short_int_rprimitive
526526

527527

@@ -535,7 +535,7 @@ def is_int32_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
535535
)
536536

537537

538-
def is_int64_rprimitive(rtype: RType) -> bool:
538+
def is_int64_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
539539
return rtype is int64_rprimitive or (
540540
rtype is c_pyssize_t_rprimitive and rtype._ctype == "int64_t"
541541
)
@@ -554,79 +554,79 @@ def is_uint8_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
554554
return rtype is uint8_rprimitive
555555

556556

557-
def is_uint32_rprimitive(rtype: RType) -> bool:
557+
def is_uint32_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
558558
return rtype is uint32_rprimitive
559559

560560

561-
def is_uint64_rprimitive(rtype: RType) -> bool:
561+
def is_uint64_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
562562
return rtype is uint64_rprimitive
563563

564564

565-
def is_c_py_ssize_t_rprimitive(rtype: RType) -> bool:
565+
def is_c_py_ssize_t_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
566566
return rtype is c_pyssize_t_rprimitive
567567

568568

569-
def is_pointer_rprimitive(rtype: RType) -> bool:
569+
def is_pointer_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
570570
return rtype is pointer_rprimitive
571571

572572

573-
def is_float_rprimitive(rtype: RType) -> bool:
573+
def is_float_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
574574
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.float"
575575

576576

577-
def is_bool_rprimitive(rtype: RType) -> bool:
577+
def is_bool_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
578578
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.bool"
579579

580580

581-
def is_bit_rprimitive(rtype: RType) -> bool:
581+
def is_bit_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
582582
return isinstance(rtype, RPrimitive) and rtype.name == "bit"
583583

584584

585-
def is_bool_or_bit_rprimitive(rtype: RType) -> bool:
585+
def is_bool_or_bit_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
586586
return is_bool_rprimitive(rtype) or is_bit_rprimitive(rtype)
587587

588588

589-
def is_object_rprimitive(rtype: RType) -> bool:
589+
def is_object_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
590590
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.object"
591591

592592

593-
def is_none_rprimitive(rtype: RType) -> bool:
593+
def is_none_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
594594
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.None"
595595

596596

597-
def is_list_rprimitive(rtype: RType) -> bool:
597+
def is_list_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
598598
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.list"
599599

600600

601-
def is_dict_rprimitive(rtype: RType) -> bool:
601+
def is_dict_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
602602
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.dict"
603603

604604

605-
def is_set_rprimitive(rtype: RType) -> bool:
605+
def is_set_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
606606
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.set"
607607

608608

609-
def is_frozenset_rprimitive(rtype: RType) -> bool:
609+
def is_frozenset_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
610610
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.frozenset"
611611

612612

613-
def is_str_rprimitive(rtype: RType) -> bool:
613+
def is_str_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
614614
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.str"
615615

616616

617-
def is_bytes_rprimitive(rtype: RType) -> bool:
617+
def is_bytes_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
618618
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.bytes"
619619

620620

621-
def is_tuple_rprimitive(rtype: RType) -> bool:
621+
def is_tuple_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
622622
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.tuple"
623623

624624

625-
def is_range_rprimitive(rtype: RType) -> bool:
625+
def is_range_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
626626
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.range"
627627

628628

629-
def is_sequence_rprimitive(rtype: RType) -> bool:
629+
def is_sequence_rprimitive(rtype: RType) -> TypeGuard[RPrimitive]:
630630
return isinstance(rtype, RPrimitive) and (
631631
is_list_rprimitive(rtype)
632632
or is_tuple_rprimitive(rtype)
@@ -720,7 +720,7 @@ def __str__(self) -> str:
720720
def __repr__(self) -> str:
721721
return "<RTuple %s>" % ", ".join(repr(typ) for typ in self.types)
722722

723-
def __eq__(self, other: object) -> bool:
723+
def __eq__(self, other: object) -> TypeGuard[RTuple]:
724724
return isinstance(other, RTuple) and self.types == other.types
725725

726726
def __hash__(self) -> int:
@@ -853,7 +853,7 @@ def __repr__(self) -> str:
853853
", ".join(name + ":" + repr(typ) for name, typ in zip(self.names, self.types)),
854854
)
855855

856-
def __eq__(self, other: object) -> bool:
856+
def __eq__(self, other: object) -> TypeGuard[RStruct]:
857857
return (
858858
isinstance(other, RStruct)
859859
and self.name == other.name
@@ -923,7 +923,7 @@ def attr_type(self, name: str) -> RType:
923923
def __repr__(self) -> str:
924924
return "<RInstance %s>" % self.name
925925

926-
def __eq__(self, other: object) -> bool:
926+
def __eq__(self, other: object) -> TypeGuard[RInstance]:
927927
return isinstance(other, RInstance) and other.name == self.name
928928

929929
def __hash__(self) -> int:
@@ -977,7 +977,7 @@ def __str__(self) -> str:
977977
return "union[%s]" % ", ".join(str(item) for item in self.items)
978978

979979
# We compare based on the set because order in a union doesn't matter
980-
def __eq__(self, other: object) -> bool:
980+
def __eq__(self, other: object) -> TypeGuard[RUnion]:
981981
return isinstance(other, RUnion) and self.items_set == other.items_set
982982

983983
def __hash__(self) -> int:
@@ -1019,7 +1019,7 @@ def optional_value_type(rtype: RType) -> RType | None:
10191019
return None
10201020

10211021

1022-
def is_optional_type(rtype: RType) -> bool:
1022+
def is_optional_type(rtype: RType) -> TypeGuard[RUnion]:
10231023
"""Is rtype an optional type with exactly two union items?"""
10241024
return optional_value_type(rtype) is not None
10251025

@@ -1051,7 +1051,7 @@ def __str__(self) -> str:
10511051
def __repr__(self) -> str:
10521052
return f"<RArray {self.item_type!r}[{self.length}]>"
10531053

1054-
def __eq__(self, other: object) -> bool:
1054+
def __eq__(self, other: object) -> TypeGuard[RArray]:
10551055
return (
10561056
isinstance(other, RArray)
10571057
and self.item_type == other.item_type

0 commit comments

Comments
 (0)