Skip to content
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

Type checking for property.{fget,fset,fdel} #1112

Open
jpy-git opened this issue Mar 21, 2022 · 4 comments
Open

Type checking for property.{fget,fset,fdel} #1112

jpy-git opened this issue Mar 21, 2022 · 4 comments
Labels
topic: other Other topics not covered

Comments

@jpy-git
Copy link

jpy-git commented Mar 21, 2022

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

@jpy-git jpy-git added the topic: other Other topics not covered label Mar 21, 2022
@Gobot1234
Copy link
Contributor

Gobot1234 commented Mar 22, 2022

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 python/typeshed#6347

@erictraut
Copy link
Collaborator

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.

@JelleZijlstra
Copy link
Member

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.

@antazoey
Copy link

antazoey commented Oct 31, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: other Other topics not covered
Projects
None yet
Development

No branches or pull requests

5 participants