Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding stub file of cm.py #110

Closed
beskep opened this issue Dec 20, 2023 · 3 comments · Fixed by #112
Closed

Adding stub file of cm.py #110

beskep opened this issue Dec 20, 2023 · 3 comments · Fixed by #112
Labels
feature request New idea or feature request

Comments

@beskep
Copy link
Contributor

beskep commented Dec 20, 2023

Is your feature request related to a problem? Please describe.

Adding stub file of cm.py would be very helpful for auto completing and type checking.

Describe the solution you would like

cm.pyi would be like the following:

from matplotlib.colors import ListedColormap as LC

CMAP_DCT = dict[str, LC]
cmap_d: CMAP_DCT
cmap_cd: dict[str, CMAP_DCT]

amber: LC
amber_r: LC
amethyst: LC
amethyst_r: LC
apple: LC
apple_r: LC
arctic: LC
arctic_r: LC

I generated the stub file with this script:

from pathlib import Path

import cmasher.cm as cmrcm
from cmasher._known_cmap_types import _CMASHER_BUILTIN_MAP_TYPES

if __name__ == "__main__":
    pyi = Path(cmrcm.__file__).with_suffix(".pyi")

    with pyi.open("w", encoding="utf-8") as f:
        f.write(
            """from matplotlib.colors import ListedColormap as LC

CMAP_DCT = dict[str, LC]
cmap_d: CMAP_DCT
cmap_cd: dict[str, CMAP_DCT]

"""
        )

        for cmap in _CMASHER_BUILTIN_MAP_TYPES:
            if cmap.startswith("cmr."):
                continue

            f.write(f"{cmap}: LC\n")
            f.write(f"{cmap}_r: LC\n")

Additional context

image

@beskep beskep added the feature request New idea or feature request label Dec 20, 2023
@neutrinoceros
Copy link
Collaborator

This would be a useful addition indeed, PR welcome !
The script used for generation would need to be added to scripts too.

@beskep
Copy link
Contributor Author

beskep commented Dec 20, 2023

#111 Thank you for kind response. This is my first PR :)

@neutrinoceros
Copy link
Collaborator

closed in #112 , thanks again !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New idea or feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants