Concrete class considered abstract when base class has additional python type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
When using a TypeVar from an abstract class, and the abstract class additionally inherits from some integrated types (I found dict, int, str, set; not float), mypy incorrectly alarms about instantiating an abstract class.
To Reproduce
from abc import ABC, abstractmethod
from typing import TypeVar, Type
class User(ABC, dict): # removing dict makes mypy happy
@abstractmethod
def method(self):
...
class BasicUser(User):
def method(self):
print('basic')
U = TypeVar('U', bound=User)
def new_user(user_class: Type[U]) -> U:
user = user_class()
return user
joe = new_user(BasicUser)
Expected Behavior
It should not report an error, as it does not when inheriting from another class or just ABC.
Actual Behavior
test.py:20: error: Cannot instantiate abstract class "User" with abstract attribute "method" [abstract]
Your Environment
- Mypy version used: 0.990
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10.8
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo la riproduzione fornita in test.py con mypy 0.990 e conferma l'errore relativo alla classe astratta per BasicUser. Traccia la gestione dei bound di TypeVar, dei metodi astratti e delle classi base integrate aggiuntive, quindi aggiungi un test di regressione che mostri che new_user(BasicUser) viene accettato senza la diagnosi errata.
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