Type checking for `property.{fget,fset,fdel}`
When trying to fix an issue in typeshed we found that both mypy and pyright raised incorrect errors that were also inconsistent with one another so I'm creating this issue to facilitate further discussion on resolving this.
class A:
@property
def foo(self):
return 'a'
A.foo.fget(A())
mypy: "Callable[[A], Any]" has no attribute "fget"
pyright: Expected 0 positional arguments
Initial PR attempt and relevant discussions can be found here
I'd actually been thinking about this recently, I think the best way to solve this moving forwards is for mypy to implement pyright's current behaviour (which is the correct one). Then to make FunctionType and MethodType generic as then users could actually opt-in to the descriptor behaviour if they wanted. The only issue with this is that currently this isn't do-able in the current type system (as far as I'm aware).
See https://github.com/python/typeshed/issues/6347
It looks like both mypy and pyright are currently handling this case incorrectly. The signature of fget isn't documented (as far as I can tell), and I made an incorrect assumption when implementing it in pyright. The problem will be fixed in the next release. Same goes for fset and fdel.
I don't think the property issue here needs broader discussion; that can be addressed in typeshed or within type checkers. But there's a behavior discrepancy that needs to be addressed; I opened #1113 for that.
I ran into this issue as well but it seems to only happen for properties with an additional decorator @abstractmethod.
Edit: Nevermind, I am not sure why it only raises for some properties and not others. I don't see a pattern yet.