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

property fail on fget, fset #6185

Open
zsluedem opened this issue Jan 12, 2019 · 6 comments
Open

property fail on fget, fset #6185

zsluedem opened this issue Jan 12, 2019 · 6 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@zsluedem
Copy link

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    Bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
class A():
    @property
    def a(self) -> float:
        return 0.5

class B():
    @property
    def a(self) -> float:
        return 1.5

class C(A, B):
    is_a:bool = True
    @property
    def a(self) -> float:
        if self.is_a:
            return A.a.fget(self)
        else:
            return B.a.fget(self)


if __name__ == '__main__':
    c = C()
    assert c.a ==0.5
    c.is_a = False
    assert c.a == 1.5
  • What is the actual behavior/output?
warning: Returning Any from function declared to return "float"
error: "Callable[[A], float]" has no attribute "fget"
warning: Returning Any from function declared to return "float"
error: "Callable[[B], float]" has no attribute "fget"
  • What is the behavior/output you expect?
    mypy should pass

  • What are the versions of mypy and Python you are using?
    mypy 0.650
    Python 3.6.5

    Do you see the same issue after installing mypy from Git master?
    Yes

  • What are the mypy flags you are using? (For example --strict-optional)
    no flags.

  • If mypy crashed with a traceback, please paste
    the full traceback below.

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)

@ilevkivskyi
Copy link
Member

Previously I closed #6045 as a duplicate of #220, but now I think the latter is to general, so we can keep this open.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 19, 2019

Similarly, C.prop.__get__ isn't supported.

@PrasadNR
Copy link

PrasadNR commented Mar 23, 2021

I am having this exact issue while setting gradients in PyTorch. Are there any official work-around(s)?

@AlexWaygood AlexWaygood added topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Apr 4, 2022
@eltoder
Copy link

eltoder commented Feb 20, 2023

Duplicate of #8085

LeMyst added a commit to LeMyst/WikibaseIntegrator that referenced this issue Apr 24, 2023
LeMyst added a commit to LeMyst/WikibaseIntegrator that referenced this issue Apr 30, 2023
* Add get_entity_url()

Close #516

* Ignore unsupported mypy

Check python/mypy#6185
@samskiter
Copy link

Seems there's a bunch of related issues to properties - is there any progress?

@PrasadNR
Copy link

PrasadNR commented Dec 1, 2023

Seems there's a bunch of related issues to properties - is there any progress?

Also, any idea as to how this can be "fixed" will be awesome I guess. At-least then, I can try to create my own "PR".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

7 participants