-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[1.16 regression] crashes on invalid and self-referential setter #19205
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
Comments
This did not crash in 1.15 and prior.
While it's definitely a bug in our code as we should be taking a value argument, I also wouldn't expect mypy to crash. I'm going to venture a guess this was introduced as part of the property rework: #18510 |
I bisected this, and the regression was in #18774. cc @ilevkivskyi as the author of the PR |
OK, so the problem is not the invalid setter, the problem is that you are missing an underscore inside the setter body (thus creating an infinite recursion at runtime). This code doesn't crash and gives a correct error: class NoopPowerResource:
_hardware_type = None
@property
def hardware_type(self) -> Any:
return self._hardware_type
@hardware_type.setter
def hardware_type(self) -> None: # error: Invalid property setter signature [misc]
self._hardware_type = None
def test(self) -> None:
self.hardware_type = None This happens because we "patch up" invalid properties after we analyze the property definition. Should be a simple fix. |
Thanks for looking into it so quickly. I maybe simplified the original code too much to obscure the fact that in our scenario the attribute is a I made some assumptions since the following did not crash: from dataclasses import dataclass
from typing import Any, ClassVar, TypeVar, Generic
DT = TypeVar("DT", bound="Driver")
class Driver(Generic[DT]): pass
@dataclass
class Resource:
hardware_type: ClassVar[type[Driver] | None] = Driver
name: str
class NoopPowerResource(Resource):
_hardware_type = None
@property
def hardware_type(self) -> Any:
return self._hardware_type
@hardware_type.setter
def hardware_type(self, _value: Any) -> None:
self.hardware_type = None
async def on(self) -> None:
pass
async def off(self) -> None:
pass None of this changes the fact our code is still wrong, so I'm glad it was at least catching something |
Crash Report
(Tell us what happened.)
Traceback
To Reproduce
(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: