Skip to content

Commit 1486fad

Browse files
committed
fix: prevent override when there exists a setter
1 parent 0060334 commit 1486fad

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mypy/checker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2285,10 +2285,11 @@ def check_method_override_for_base_with_name(
22852285
isinstance(original_node, Var)
22862286
and original_node.is_classvar
22872287
and defn.name == original_node.name
2288-
and isinstance(defn, Decorator)
2288+
and (isinstance(defn, (Decorator, OverloadedFuncDef)))
22892289
):
22902290
self.fail(
2291-
message_registry.CANNOT_OVERRIDE_CLASS_VAR.format(base.name), defn.func
2291+
message_registry.CANNOT_OVERRIDE_CLASS_VAR.format(base.name),
2292+
defn.func if isinstance(defn, Decorator) else defn.items[0].func,
22922293
)
22932294

22942295
if (

test-data/unit/check-classvar.test

+3-1
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,12 @@ class A:
277277
class B(A):
278278
@property
279279
def x(self) -> int: ...
280+
281+
@x.setter
282+
def x(self, value: int) -> None: ...
280283
[builtins fixtures/property.pyi]
281284
[out]
282285
main:7: error: Cannot override class variable (previously declared on base class "A") with instance variable
283-
main:7: error: Cannot override writeable attribute with read-only property
284286

285287
[case testAcrossModules]
286288
import m

0 commit comments

Comments
 (0)