Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix abstract and non-abstract variant error for prop.deleter #15395

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,8 @@ def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -
first_item.var.is_settable_property = True
# Get abstractness from the original definition.
item.func.abstract_status = first_item.func.abstract_status
if node.name == "deleter":
item.func.abstract_status = first_item.func.abstract_status
else:
self.fail(
f"Only supported top decorator is @{first_item.func.name}.setter", item
Expand Down
41 changes: 39 additions & 2 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,44 @@ class A(metaclass=ABCMeta):
def x(self) -> int: pass
@x.setter
def x(self, x: int) -> None: pass
[out]

[case testReadWriteDeleteAbstractProperty]
from abc import ABC, abstractmethod
class Abstract(ABC):
@property
@abstractmethod
def prop(self) -> str: ...

@prop.setter
@abstractmethod
def prop(self, code: str) -> None: ...

@prop.deleter
@abstractmethod
def prop(self) -> None: ...

class Good(Abstract):
@property
def prop(self) -> str: ...
@prop.setter
def prop(self, code: str) -> None: ...
@prop.deleter
def prop(self) -> None: ...

class Bad1(Abstract):
@property # E: Read-only property cannot override read-write property
def prop(self) -> str: ...

class ThisShouldProbablyError(Abstract):
@property
def prop(self) -> str: ...
@prop.setter
def prop(self, code: str) -> None: ...

a = Good()
reveal_type(a.prop) # N: Revealed type is "builtins.str"
a.prop = 123 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
[builtins fixtures/property.pyi]

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

[case testImplementReradWriteAbstractPropertyViaProperty]
[case testImplementReadWriteAbstractPropertyViaProperty]
from abc import abstractproperty, ABCMeta
class A(metaclass=ABCMeta):
@abstractproperty
Expand Down