"Invalid base class" raised when Base Class is a class field

Aperta
#3,587 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Start by running the provided reproducer with mypy and compare how the module-level Base and Types.Base are resolved when used as class bases. Trace the type-checking path for class fields and base-class validation. Done means the reproducer accepts Fails(Types.Base) without the invalid-type or invalid-base-class errors while preserving the existing reveal types.

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

Descrizione

needs discussion topic-inheritance

Repro:

class Foo:
    pass

Base = Foo

class Types:
    Base = Foo

reveal_type(Base)
reveal_type(Types.Base)

class Works(Base):
    pass

class Fails(Types.Base):
    pass

Results in:

test_cast.py:9: error: Revealed type is 'def () -> test_cast.Foo'
test_cast.py:10: error: Revealed type is 'def () -> test_cast.Foo'
test_cast.py:15: error: Invalid type "Base"
test_cast.py:15: error: Invalid base class

What's odd is that mypy recognizes Base and Types.Base as having identical types yet accepts Base as a base class but not Types.Base

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

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.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.