Open mihneagiurgea opened 8 years ago
What is the status of this issue? #1713 is closed as duplicate of this issue.
We don't have immediate plans for fix this issue, but we are happy to receive a PR.
I had missed that moving the setter next to getter solves the problem, which is good enough. Thanks for the update!
This also affects subclasses that override properties, e.g.:
class Parent(object):
@property
def foo(self):
return "parent_foo"
class Child(Parent):
@Parent.foo.getter
def foo(self):
return "child_foo"
mypy returns a "Callable[[Any], Any]" has no attribute "getter"
error here. In this case, it's obviously not possible to move the two methods to be next to each other.
So I've been looking at this. The issue is basically the OverloadedFuncDef unification logic in fastparse. Currently it basically unites all decorated consecutive functions with the same name. That is incorrect for everything that is not the overload decorator. However, due to its location it is unaware of name resolving. Meaning that if if I import overload as a different name, in order to correctly create OverloadedFuncDef, it has to err on the side of caution and apply the logic anyway.
I'm not sure how to handle this - the visitor logic depends on OverloadedFuncDef created in tree parsing but it obviously can't do this right. Do you have an idea where to move this logic? If we want to not change too much, we need somewhere that can resolve which decorator is used.
Maybe unite everything but add function indices? Then we can figure everything out in the semantic analysis phase.
This problem seems to be persistent and still confuses people a lot maybe it's time to fix it?
This also affects subclasses that override properties, e.g.:
class Parent(object): @property def foo(self): return "parent_foo" class Child(Parent): @Parent.foo.getter def foo(self): return "child_foo"
mypy returns a
"Callable[[Any], Any]" has no attribute "getter"
error here. In this case, it's obviously not possible to move the two methods to be next to each other.
Thanks for posting this - also struggling with this. Is there any known workaround? Specifically I wanted to override a property setter.
"No attribute" along with "Untyped decorator" error.
class Cell(ABC):
def __init__(self, value: int | None = None):
...
@property
def value(self) -> int | None:
return self._value
class InputCell(Cell):
@Cell.value.setter
def value(self, value: int) -> None:
...
Running mypy with --strict
generates:
react.py:28: error: "Callable[[Cell], int | None]" has no attribute "setter" [attr-defined]
react.py:28: error: Untyped decorator makes function "value" untyped [misc]
Line 28 happens to be the @Cell.value.setter
.
The following code incorrectly raises an error:
Error:
Commenting out the
_other
method will fix the error.