python / python/mypy

property fail on fget, fset

Aperta
#6,185 6 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug false-positive priority-1-normal topic-descriptors topic-runtime-semantics
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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.)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo mypy sulla riproduzione minima nell’issue e confronta la gestione dell’accesso a una property tramite A.a.fget e B.a.fget. Traccia il percorso del controllo dei tipi per i descrittori di property e gli attributi chiamabili; il lavoro è completato quando l’esempio passa con gli attesi tipi di ritorno float.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.