|
6 | 6 | # TODO: Remove this check once python 3.7 is not supported: |
7 | 7 | if sys.version_info >= (3, 8): |
8 | 8 | from typing import TYPE_CHECKING, Literal, TypedDict, Union |
| 9 | +else: |
| 10 | + from typing import TYPE_CHECKING, Union |
9 | 11 |
|
10 | | - if TYPE_CHECKING: |
11 | | - try: |
12 | | - from matplotlib.colors import Colormap |
13 | | - except ImportError: |
14 | | - Colormap = str |
15 | | - |
16 | | - class T_Options(TypedDict): |
17 | | - arithmetic_join: Literal["inner", "outer", "left", "right", "exact"] |
18 | | - cmap_divergent: Union[str, "Colormap"] |
19 | | - cmap_sequential: Union[str, "Colormap"] |
20 | | - display_max_rows: int |
21 | | - display_style: Literal["text", "html"] |
22 | | - display_width: int |
23 | | - display_expand_attrs: Literal["default", True, False] |
24 | | - display_expand_coords: Literal["default", True, False] |
25 | | - display_expand_data_vars: Literal["default", True, False] |
26 | | - display_expand_data: Literal["default", True, False] |
27 | | - enable_cftimeindex: bool |
28 | | - file_cache_maxsize: int |
29 | | - keep_attrs: Literal["default", True, False] |
30 | | - warn_for_unclosed_files: bool |
31 | | - use_bottleneck: bool |
| 12 | + from typing_extensions import Literal, TypedDict |
32 | 13 |
|
33 | 14 |
|
34 | | -else: |
35 | | - # See GH5624, this is a convoluted way to allow type-checking to use |
36 | | - # `TypedDict` and `Literal` without requiring typing_extensions as a |
37 | | - # required dependency to _run_ the code (it is required to type-check). |
| 15 | +if TYPE_CHECKING: |
38 | 16 | try: |
39 | | - from typing import TYPE_CHECKING, Union |
40 | | - |
41 | | - from typing_extensions import Literal, TypedDict |
42 | | - |
43 | | - if TYPE_CHECKING: |
44 | | - try: |
45 | | - from matplotlib.colors import Colormap |
46 | | - except ImportError: |
47 | | - Colormap = str |
48 | | - |
49 | | - class T_Options(TypedDict): |
50 | | - arithmetic_join: Literal["inner", "outer", "left", "right", "exact"] |
51 | | - cmap_divergent: Union[str, "Colormap"] |
52 | | - cmap_sequential: Union[str, "Colormap"] |
53 | | - display_max_rows: int |
54 | | - display_style: Literal["text", "html"] |
55 | | - display_width: int |
56 | | - display_expand_attrs: Literal["default", True, False] |
57 | | - display_expand_coords: Literal["default", True, False] |
58 | | - display_expand_data_vars: Literal["default", True, False] |
59 | | - display_expand_data: Literal["default", True, False] |
60 | | - enable_cftimeindex: bool |
61 | | - file_cache_maxsize: int |
62 | | - keep_attrs: Literal["default", True, False] |
63 | | - warn_for_unclosed_files: bool |
64 | | - use_bottleneck: bool |
65 | | - |
| 17 | + from matplotlib.colors import Colormap |
66 | 18 | except ImportError: |
67 | | - from typing import TYPE_CHECKING, Any, Dict, Hashable |
68 | | - |
69 | | - if TYPE_CHECKING: |
70 | | - raise |
71 | | - else: |
72 | | - T_Options = Dict[Hashable, Any] |
| 19 | + Colormap = str |
| 20 | + |
| 21 | + |
| 22 | +class T_Options(TypedDict): |
| 23 | + arithmetic_join: Literal["inner", "outer", "left", "right", "exact"] |
| 24 | + cmap_divergent: Union[str, "Colormap"] |
| 25 | + cmap_sequential: Union[str, "Colormap"] |
| 26 | + display_max_rows: int |
| 27 | + display_style: Literal["text", "html"] |
| 28 | + display_width: int |
| 29 | + display_expand_attrs: Literal["default", True, False] |
| 30 | + display_expand_coords: Literal["default", True, False] |
| 31 | + display_expand_data_vars: Literal["default", True, False] |
| 32 | + display_expand_data: Literal["default", True, False] |
| 33 | + enable_cftimeindex: bool |
| 34 | + file_cache_maxsize: int |
| 35 | + keep_attrs: Literal["default", True, False] |
| 36 | + warn_for_unclosed_files: bool |
| 37 | + use_bottleneck: bool |
73 | 38 |
|
74 | 39 |
|
75 | 40 | OPTIONS: T_Options = { |
|
0 commit comments