Add "is invariant" warning to Set as well as List for situations where a Collection should be used
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
mypy has a lovely warning about List being invariant in situations like this:
ls: List[int] = [1, 2, 3]
def process(stuff: List[Union[int, str]]):
...
process(ls) # type error here, w/ nice explanation of invariance and suggestion to use Sequence
However, it does not have the same warning when Set is used in the same way:
s: Set[int] = {1, 2, 3}
def process(stuff: Set[Union[int, str]]):
...
process(s) # merely states that the type is incompatible, no mention of invariance
Would be nice if the same warning mechanism could trigger here, suggesting Collection.
Pitch
Hopefully this is a simple widening of a rule that's special-cased for lists to get sets too? Not sure if other types like Dict/Tuple might be included too; I haven't tested them. If it's a lot of effort probably not worth it.
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 damit, die bestehende Warnung zur Invarianz von List und ihre Tests zu finden; das Issue nennt keine bestimmten Dateien oder Einstiegspunkte. Erweitere dasselbe Warnverhalten auf Set und verifiziere, dass die Diagnose die Invarianz erklärt und Collection vorschlägt, wie im Beispiel gezeigt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100