Skip to content

Commit 410f933

Browse files
Fix stubtest false positive for properties with a deleter (#21259)
Previously, properties with a deleter but no setter were treated as read-only. Update logic to consider a property read-only only if both `fset` and `fdel` are None. Fixes #21254
1 parent d779750 commit 410f933

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

mypy/stubtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ def is_probably_a_function(runtime: Any) -> bool:
18511851

18521852

18531853
def is_read_only_property(runtime: object) -> bool:
1854-
return isinstance(runtime, property) and runtime.fset is None
1854+
return isinstance(runtime, property) and runtime.fset is None and runtime.fdel is None
18551855

18561856

18571857
def safe_inspect_signature(runtime: Any) -> inspect.Signature | None:

mypy/test/teststubtest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,25 @@ class FineAndDandy:
10611061
""",
10621062
error=None,
10631063
)
1064+
yield Case(
1065+
stub="""
1066+
class spam:
1067+
@property
1068+
def eggs(self) -> int: ...
1069+
@eggs.deleter
1070+
def eggs(self) -> None: ...
1071+
""",
1072+
runtime="""
1073+
class spam:
1074+
@property
1075+
def eggs(self):
1076+
return 42
1077+
@eggs.deleter
1078+
def eggs(self):
1079+
print("eggs")
1080+
""",
1081+
error=None,
1082+
)
10641083

10651084
@collect_cases
10661085
def test_cached_property(self) -> Iterator[Case]:

0 commit comments

Comments
 (0)