11import os
2- import sys
3- from typing import (
4- TYPE_CHECKING ,
5- Any ,
6- Dict ,
7- Final ,
8- Iterable ,
9- Literal ,
10- Optional ,
11- Sequence ,
12- Tuple ,
13- )
2+ import warnings
3+ from collections .abc import Iterable , Sequence
4+ from typing import TYPE_CHECKING , Any , Final , Literal , Optional
145
156import matplotlib as mpl
167import numpy as np
2415
2516_CMYT_PREFIX : Final [str ] = "cmyt."
2617
27- ColorDict = Dict [Literal ["red" , "green" , "blue" , "alpha" ], Sequence [Tuple [float , ...]]]
18+ ColorDict = dict [Literal ["red" , "green" , "blue" , "alpha" ], Sequence [tuple [float , ...]]]
2819
2920# this is used in cmyt.cm to programmatically import all cmaps
3021cmyt_cmaps = frozenset (
@@ -59,20 +50,22 @@ def unprefix_name(name: str) -> str:
5950 >>> unprefix_name("arbre")
6051 'arbre'
6152 """
62- if sys .version_info >= (3 , 9 ):
63- return name .removeprefix (_CMYT_PREFIX )
64- else :
65- if name .startswith (_CMYT_PREFIX ):
66- return name [len (_CMYT_PREFIX ) :]
67- return name
53+ warnings .warn (
54+ "cmyt.utils.unprefix_name is deprecated since version 1.4.0 "
55+ "and will be removed in a future version. "
56+ "Instead, use name.removeprefix('cmyt.')" ,
57+ category = DeprecationWarning ,
58+ stacklevel = 2 ,
59+ )
60+ return name .removeprefix (_CMYT_PREFIX )
6861
6962
7063def register_colormap (
7164 name : str ,
7265 * ,
7366 color_dict : Optional [ColorDict ] = None ,
7467 colors : Optional [np .ndarray ] = None ,
75- ) -> Tuple [Colormap , Colormap ]:
68+ ) -> tuple [Colormap , Colormap ]:
7669 name = prefix_name (name )
7770
7871 if color_dict is not None and colors is not None :
@@ -91,8 +84,8 @@ def register_colormap(
9184 mpl .colormaps .register (cmap_r )
9285
9386 # return cmaps with unprefixed names for registration as importable objects
94- cmap .name = unprefix_name ( cmap .name )
95- cmap_r .name = unprefix_name ( cmap_r .name )
87+ cmap .name = cmap .name . removeprefix ( _CMYT_PREFIX )
88+ cmap_r .name = cmap_r .name . removeprefix ( _CMYT_PREFIX )
9689 return cmap , cmap_r
9790
9891
@@ -184,7 +177,9 @@ def create_cmap_overview(
184177 for rgb , _ax in zip (RGBs , _axes ):
185178 _ax .axis ("off" )
186179 show_cmap (_ax , rgb )
187- ax .text (ax .get_xlim ()[1 ] * 1.02 , 0 , unprefix_name (name ), fontsize = 10 )
180+ ax .text (
181+ ax .get_xlim ()[1 ] * 1.02 , 0 , name .removeprefix (_CMYT_PREFIX ), fontsize = 10
182+ )
188183
189184 fig .tight_layout (h_pad = 0.2 )
190185 fig .subplots_adjust (top = 0.9 , bottom = 0.05 , right = 0.85 , left = 0.05 )
0 commit comments