matplotlib / matplotlib/cmocean

Static type checkers can't recognize colormaps

Offen
#120 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
269
Forks
54
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Static type checkers like MyPy or Pylance can't recognize variables created dynamically with [`locals().update(cmap_d)`](https://github.com/matplotlib/cmocean/blob/59c35002c3aa5296b65d9646e52604c627441eb6/cmocean/cm.py#L84). Past just type checking, Pylance can't even recognize that colormaps exist, e.g., `cmocean.cm.balance` produces an [attribute access issue error](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportAttributeAccessIssue.md) in Pylance.

Matplotlib colormaps have the same issue, which they solve by including a stub file [cm.pyi](https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/cm.pyi) that defines the attributes and types.

If there's interest in include a cm.pyi file here, it is straightforward to generate one automatically based on the colormaps defined in `cmap_d` and I'd be happy to make a PR with the details.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Untersuche cmocean/cm.py und die Definition von cmap_d, um zu sehen, wie Colormaps dynamisch erstellt werden. Vergleiche den referenzierten Matplotlib-cm.pyi-Stub und bestimme, wie ein generierter Stub die Colormap-Attribute und -Typen offenlegen würde; als erledigt gilt dies, wenn MyPy und Pylance Einträge wie cmocean.cm.balance erkennen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.