-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Abstract Properties & Overloaded method has both abstract and non-abstract variants
#4165
Comments
Overloaded method has both abstract and non-abstract variants
Overloaded method has both abstract and non-abstract variants
It seems that version 0.750 still have this bug. Do you have any ideas how to solve it? |
|
Here's a link that works to the py-evm workaround: |
I'm running mypy 0.782 on OSX 10.13.6. Furthermore, if you use from abc import ABC, abstractmethod
class C(ABC):
@property # type:ignore
@abstractmethod
def x(self) -> int:
pass
@x.setter # type:ignore
@abstractmethod
def x(self, val: int) -> None:
pass
class D(C):
def __init__(self) -> None:
self._x = 0
@property
def x(self) -> int:
return self._x
def main() -> None:
d = D()
print(d.x)
if __name__ == '__main__':
main() I get $ python3 -m mypy --strict bar.py && python3 bar.py
Success: no issues found in 1 source file
0
I would expect for mypy to say "hey, implement an x.setter in class bar.py:5: error: Overloaded method has both abstract and non-abstract variants as the OP already mentioned. Removing the bar.py:10: error: Decorated property not supported The only workaround that seems to make sense is to avoid using properties altogether, and stick with abstract methods: from abc import ABC, abstractmethod
class C(ABC):
@abstractmethod
def get_x(self) -> int:
pass
@abstractmethod
def set_x(self, val: int) -> None:
pass
class D(C):
def __init__(self) -> None:
self._x = 0
def get_x(self) -> int:
return self._x
def main() -> None:
d = D()
if __name__ == '__main__':
main() which results in:
|
@Property, its setter and @AbstractMethod do not work well together in mypy. This fix was suggested in a GitHub issue: python/mypy#4165
Seems that using class A(ABC):
@abstractproperty
def a(self) -> int:
...
@a.setter
def a(self, new_a: int) -> None:
... |
|
I hit this today with code similar to the repro, and removing I got this idea from the 2nd code block here in the docs: https://docs.python.org/3.10/library/abc.html#abc.abstractproperty |
The original example now works without any type-ignores on master. Probably was fixed by the same PR that fixed #1362. Also the example in the comments now correctly gives |
Edit: I misread and thought #4165 (comment) was from long ago; I now see it is only just over a month old. I think there is nothing to do here; sorry for the noise. We're seeing this issue pop up again with 0.971 and it appears to be subsequently fixed with 0.981. Haven't tried other versions; perhaps a test should be added? Good behavior (mypy 0.981): pandas-dev/pandas#48943 |
Is this issue actually fixed? I've run into this same problem with mypy 1.3.0. Here's a reproducible example.
And here is from abc import ABC, abstractmethod
class Abstract(ABC):
"""An abstract thing."""
@property
@abstractmethod
def default(self) -> str:
"""The default code."""
@default.setter
@abstractmethod
def default(self, code: str) -> None:
"""Set the code."""
@default.deleter
@abstractmethod
def default(self) -> None:
"""Reset the code.""" |
Looks like it got fixed for setters, but not deleters |
Expected Behaviour
getters
andsetters
Actual Behaviour & Repro Case
Python Code
Mypy CLI
Result
Notes
mypy/mypy/messages.py
Lines 74 to 75 in a1ace48
mypy/mypy/checker.py
Lines 329 to 330 in 936ceac
# type: ignore
from@foo.setter
causesmypy
to throwerror: Decorated property not supported
, just as in Decorated property not supported #1362Related Issues
Current Solution
@property # type: ignore
The text was updated successfully, but these errors were encountered: