Skip to content

Commit 4baf672

Browse files
authored
Fix abstract and non-abstract variant error for prop.deleter (#15395)
1 parent 27593bc commit 4baf672

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

mypy/semanal.py

+2
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -
13371337
first_item.var.is_settable_property = True
13381338
# Get abstractness from the original definition.
13391339
item.func.abstract_status = first_item.func.abstract_status
1340+
if node.name == "deleter":
1341+
item.func.abstract_status = first_item.func.abstract_status
13401342
else:
13411343
self.fail(
13421344
f"Only supported top decorator is @{first_item.func.name}.setter", item

test-data/unit/check-abstract.test

+39-2
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,44 @@ class A(metaclass=ABCMeta):
735735
def x(self) -> int: pass
736736
@x.setter
737737
def x(self, x: int) -> None: pass
738-
[out]
738+
739+
[case testReadWriteDeleteAbstractProperty]
740+
from abc import ABC, abstractmethod
741+
class Abstract(ABC):
742+
@property
743+
@abstractmethod
744+
def prop(self) -> str: ...
745+
746+
@prop.setter
747+
@abstractmethod
748+
def prop(self, code: str) -> None: ...
749+
750+
@prop.deleter
751+
@abstractmethod
752+
def prop(self) -> None: ...
753+
754+
class Good(Abstract):
755+
@property
756+
def prop(self) -> str: ...
757+
@prop.setter
758+
def prop(self, code: str) -> None: ...
759+
@prop.deleter
760+
def prop(self) -> None: ...
761+
762+
class Bad1(Abstract):
763+
@property # E: Read-only property cannot override read-write property
764+
def prop(self) -> str: ...
765+
766+
class ThisShouldProbablyError(Abstract):
767+
@property
768+
def prop(self) -> str: ...
769+
@prop.setter
770+
def prop(self, code: str) -> None: ...
771+
772+
a = Good()
773+
reveal_type(a.prop) # N: Revealed type is "builtins.str"
774+
a.prop = 123 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
775+
[builtins fixtures/property.pyi]
739776

740777
[case testInstantiateClassWithReadOnlyAbstractProperty]
741778
from abc import abstractproperty, ABCMeta
@@ -767,7 +804,7 @@ b = B()
767804
b.x() # E: "int" not callable
768805
[builtins fixtures/property.pyi]
769806

770-
[case testImplementReradWriteAbstractPropertyViaProperty]
807+
[case testImplementReadWriteAbstractPropertyViaProperty]
771808
from abc import abstractproperty, ABCMeta
772809
class A(metaclass=ABCMeta):
773810
@abstractproperty

0 commit comments

Comments
 (0)