Skip to content

Commit db7d454

Browse files
committed
Make GetAttrNullable a subclass of GetAttr
1 parent 7b0abac commit db7d454

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

mypyc/ir/ops.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def accept(self, visitor: OpVisitor[T]) -> T:
799799
return visitor.visit_get_attr(self)
800800

801801

802-
class GetAttrNullable(RegisterOp):
802+
class GetAttrNullable(GetAttr):
803803
"""obj.attr (for a native object) - allows NULL without raising AttributeError
804804
805805
This is used for spill targets where NULL indicates the non-return path was taken.
@@ -809,20 +809,9 @@ class GetAttrNullable(RegisterOp):
809809
error_kind = ERR_NEVER
810810

811811
def __init__(self, obj: Value, attr: str, line: int, *, borrow: bool = False) -> None:
812-
super().__init__(line)
813-
self.obj = obj
814-
self.attr = attr
815-
assert isinstance(obj.type, RInstance), "Attribute access not supported: %s" % obj.type
816-
self.class_type = obj.type
817-
attr_type = obj.type.attr_type(attr)
818-
self.type = attr_type
819-
self.is_borrowed = borrow and attr_type.is_refcounted
820-
821-
def sources(self) -> list[Value]:
822-
return [self.obj]
823-
824-
def set_sources(self, new: list[Value]) -> None:
825-
(self.obj,) = new
812+
super().__init__(obj, attr, line, borrow=borrow)
813+
# Override error_kind since GetAttr sets it based on attr_type.error_overlap
814+
self.error_kind = ERR_NEVER
826815

827816
def accept(self, visitor: OpVisitor[T]) -> T:
828817
return visitor.visit_get_attr_nullable(self)

0 commit comments

Comments
 (0)