1
+ from __future__ import annotations
2
+
1
3
import inspect
2
4
import sys
3
5
from contextlib import contextmanager
18
20
"hint" : "HINT" ,
19
21
"debug" : "DEBUG" ,
20
22
}
21
- # Python 3.7 ensures iteration order
23
+ # Python 3.7+ ensures iteration order
22
24
for v , level in enumerate (list (_VERBOSITY_TO_LOGLEVEL .values ())):
23
25
_VERBOSITY_TO_LOGLEVEL [v ] = level
24
26
25
27
28
+ # Collected from the print_* functions in matplotlib.backends
29
+ _Format = Union [
30
+ Literal ["png" , "jpg" , "tif" , "tiff" ],
31
+ Literal ["pdf" , "ps" , "eps" , "svg" , "svgz" , "pgf" ],
32
+ Literal ["raw" , "rgba" ],
33
+ ]
34
+
35
+
26
36
class Verbosity (IntEnum ):
27
37
error = 0
28
- warn = 1
38
+ warning = 1
29
39
info = 2
30
40
hint = 3
31
41
debug = 4
32
42
43
+ def __eq__ (self , other : Verbosity | int | str ) -> bool :
44
+ if isinstance (other , Verbosity ):
45
+ return self is other
46
+ if isinstance (other , int ):
47
+ return self .value == other
48
+ if isinstance (other , str ):
49
+ return self .name == other
50
+ return NotImplemented
51
+
33
52
@property
34
53
def level (self ) -> int :
35
54
# getLevelName(str) returns the int level…
36
- return getLevelName (_VERBOSITY_TO_LOGLEVEL [self ])
55
+ return getLevelName (_VERBOSITY_TO_LOGLEVEL [self . name ])
37
56
38
57
@contextmanager
39
- def override (self , verbosity : " Verbosity" ) -> ContextManager [" Verbosity" ]:
58
+ def override (self , verbosity : Verbosity | str | int ) -> ContextManager [Verbosity ]:
40
59
"""\
41
60
Temporarily override verbosity
42
61
"""
@@ -45,6 +64,10 @@ def override(self, verbosity: "Verbosity") -> ContextManager["Verbosity"]:
45
64
settings .verbosity = self
46
65
47
66
67
+ # backwards compat
68
+ Verbosity .warn = Verbosity .warning
69
+
70
+
48
71
def _type_check (var : Any , varname : str , types : Union [type , Tuple [type , ...]]):
49
72
if isinstance (var , types ):
50
73
return
@@ -69,7 +92,7 @@ class ScanpyConfig:
69
92
def __init__ (
70
93
self ,
71
94
* ,
72
- verbosity : str = " warning" ,
95
+ verbosity : Verbosity | int | str = Verbosity . warning ,
73
96
plot_suffix : str = "" ,
74
97
file_format_data : str = "h5ad" ,
75
98
file_format_figs : str = "pdf" ,
@@ -160,7 +183,7 @@ def verbosity(self, verbosity: Union[Verbosity, int, str]):
160
183
self ._verbosity = Verbosity (verbosity_str_options .index (verbosity ))
161
184
else :
162
185
_type_check (verbosity , "verbosity" , (str , int ))
163
- _set_log_level (self , _VERBOSITY_TO_LOGLEVEL [self ._verbosity ])
186
+ _set_log_level (self , _VERBOSITY_TO_LOGLEVEL [self ._verbosity . name ])
164
187
165
188
@property
166
189
def plot_suffix (self ) -> str :
@@ -386,15 +409,6 @@ def categories_to_ignore(self, categories_to_ignore: Iterable[str]):
386
409
# Functions
387
410
# --------------------------------------------------------------------------------
388
411
389
- # Collected from the print_* functions in matplotlib.backends
390
- # fmt: off
391
- _Format = Literal [
392
- 'png' , 'jpg' , 'tif' , 'tiff' ,
393
- 'pdf' , 'ps' , 'eps' , 'svg' , 'svgz' , 'pgf' ,
394
- 'raw' , 'rgba' ,
395
- ]
396
- # fmt: on
397
-
398
412
def set_figure_params (
399
413
self ,
400
414
scanpy : bool = True ,
0 commit comments