matplotlib / matplotlib/cmocean

Static type checkers can't recognize colormaps

未关闭
#120 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
269
派生
54
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

检查 cmocean/cm.py 和 cmap_d 的定义,了解色彩图是如何动态创建的。对照所引用的 Matplotlib cm.pyi 存根,确定生成的存根将如何公开色彩图属性和类型;当 MyPy 和 Pylance 能识别 cmocean.cm.balance 等条目时即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
功能
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。