type inference failure on custom iterable class unpacking
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
When unpacking a custom iterable class to build another iterable, mypy does not correctly infer the resulting type i.e. CustomIter[CustomIter[_T]] is equal to CustomIter[_T] (that should not be true)
To Reproduce
Expected Behavior
Nested iterable unpacking type checking works fine when using standard types (e.g. list[list[_T]]) however custom iterable classes should have the same behavior.
Actual Behavior
As presented on the playground proof-of-concept the issue is that mypy does not mark the failure on this incorrectly defined function:
def case_1(iter_of_iter: CustomIter[list[int]]) -> CustomIter[int]:
# Mypy fails
#
# Mypy does not flag that the return type does not match.
# It is `CustomIter[list[int]]` instead of `CustomIter[int]`
return CustomIter.new(*iter_of_iter)
Your Environment
- details available on the playground example.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verlinkten mypy-play-Proof-of-Concept und reproduziere den Fehler unter den darin angegebenen strikten Flags. Verfolge, wie das Entpacken eines CustomIter[CustomIter[_T]] inferiert wird, und überprüfe anschließend, dass der fehlerhafte Fall abgelehnt wird, während verschachtelte Standard-Iterables ihr bisheriges Verhalten beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100