From 5b76a2695a9bd9250a1e96e39a9589a717daf34d Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 23 Sep 2020 15:09:13 -0700 Subject: [PATCH] Revert "Check __setattr__ when property is not settable (#9196)" This reverts commit 31862816ee87afc2b7514aec76249b884a9fdbef. --- mypy/checkmember.py | 6 ++--- mypy/test/testcheck.py | 1 - test-data/unit/check-setattr.test | 39 ------------------------------- 3 files changed, 2 insertions(+), 44 deletions(-) delete mode 100644 test-data/unit/check-setattr.test diff --git a/mypy/checkmember.py b/mypy/checkmember.py index a90a3148b214..64e693d52c96 100644 --- a/mypy/checkmember.py +++ b/mypy/checkmember.py @@ -553,8 +553,7 @@ def analyze_var(name: str, return mx.chk.handle_partial_var_type(typ, mx.is_lvalue, var, mx.context) if mx.is_lvalue and var.is_property and not var.is_settable_property: # TODO allow setting attributes in subclass (although it is probably an error) - if info.get('__setattr__') is None: - mx.msg.read_only_property(name, itype.type, mx.context) + mx.msg.read_only_property(name, itype.type, mx.context) if mx.is_lvalue and var.is_classvar: mx.msg.cant_assign_to_classvar(name, mx.context) t = get_proper_type(expand_type_by_instance(typ, itype)) @@ -564,8 +563,7 @@ def analyze_var(name: str, if mx.is_lvalue: if var.is_property: if not var.is_settable_property: - if info.get('__setattr__') is None: - mx.msg.read_only_property(name, itype.type, mx.context) + mx.msg.read_only_property(name, itype.type, mx.context) else: mx.msg.cant_assign_to_method(mx.context) diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index b138d180dc3b..34d9b66da0c1 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -90,7 +90,6 @@ 'check-reports.test', 'check-errorcodes.test', 'check-annotated.test', - 'check-setattr.test', 'check-parameter-specification.test', ] diff --git a/test-data/unit/check-setattr.test b/test-data/unit/check-setattr.test deleted file mode 100644 index 7f7134b8eb11..000000000000 --- a/test-data/unit/check-setattr.test +++ /dev/null @@ -1,39 +0,0 @@ -[case testSetAttrWithProperty] -from typing import Any -class Foo: - _a = 1 - def __setattr__(self, name: str, value: Any) -> None: - self._a = value - @property - def a(self) -> int: - return self._a -f = Foo() -f.a = 2 -[builtins fixtures/property.pyi] - -[case testInheritedSetAttrWithProperty] -from typing import Any -class Foo: - _a = 1 - def __setattr__(self, name: str, value: Any) -> None: - self._a = value -class Bar(Foo): - @property - def a(self) -> int: - return self._a -f = Bar() -f.a = 2 -[builtins fixtures/property.pyi] - -[case testSetAttrWithIncompatibleType] -from typing import Any -class Foo: - _a = 1 - def __setattr__(self, name: str, value: Any) -> None: - self._a = value - @property - def a(self) -> int: - return self._a -f = Foo() -f.a = 'hello' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -[builtins fixtures/property.pyi]