You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able to disable the behavior introduced in #3451 where defining __setattr__ makes mypy assume all property assignments are valid.
Pitch
Suppose I have a class that logs all attribute accesses:
@dataclass
class MyClass:
field: int
another_field: str
def __setattr__(self, key: str, val: Any) -> None:
print(f"You just set {key}!")
super().__setattr__(key, val)
Defining __setattr__ means that I can now write my_class.feild = 123 and mypy won't catch it. My current workaround is to define a free function and do MyClass.__setattr__ = _setattr, but that's kind of janky. I'd like to be able to use a magic comment or a magic dunder variable (__mypy_no_special_setattr_handling__) to disable this.
The text was updated successfully, but these errors were encountered:
Feature
I'd like to be able to disable the behavior introduced in #3451 where defining
__setattr__
makes mypy assume all property assignments are valid.Pitch
Suppose I have a class that logs all attribute accesses:
Defining
__setattr__
means that I can now writemy_class.feild = 123
and mypy won't catch it. My current workaround is to define a free function and doMyClass.__setattr__ = _setattr
, but that's kind of janky. I'd like to be able to use a magic comment or a magic dunder variable (__mypy_no_special_setattr_handling__
) to disable this.The text was updated successfully, but these errors were encountered: