Skip to content

Commit d8dc5c6

Browse files
committed
Try out Literals for better type narrowing
1 parent 3fa7f05 commit d8dc5c6

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

xarray/core/options.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# TODO: Remove this check once python 3.7 is not supported:
55
if sys.version_info >= (3, 8):
6-
from typing import TYPE_CHECKING, TypedDict, Union
6+
from typing import TYPE_CHECKING, Literal, TypedDict, Union
77

88
if TYPE_CHECKING:
99
try:
@@ -12,19 +12,19 @@
1212
Colormap = str
1313

1414
class T_Options(TypedDict):
15-
arithmetic_join: str
15+
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
1616
cmap_divergent: Union[str, "Colormap"]
1717
cmap_sequential: Union[str, "Colormap"]
1818
display_max_rows: int
19-
display_style: str
19+
display_style: Literal["text", "html"]
2020
display_width: int
21-
display_expand_attrs: Union[str, bool]
22-
display_expand_coords: Union[str, bool]
23-
display_expand_data_vars: Union[str, bool]
24-
display_expand_data: Union[str, bool]
21+
display_expand_attrs: Literal["default", True, False]
22+
display_expand_coords: Literal["default", True, False]
23+
display_expand_data_vars: Literal["default", True, False]
24+
display_expand_data: Literal["default", True, False]
2525
enable_cftimeindex: bool
2626
file_cache_maxsize: int
27-
keep_attrs: Union[str, bool]
27+
keep_attrs: Literal["default", True, False]
2828
warn_for_unclosed_files: bool
2929
use_bottleneck: bool
3030

@@ -34,7 +34,7 @@ class T_Options(TypedDict):
3434
# `TypedDict` without requiring typing_extensions as a required dependency
3535
# to _run_ the code (it is required to type-check).
3636
try:
37-
from typing import TYPE_CHECKING, Union
37+
from typing import TYPE_CHECKING, Literal, Union
3838

3939
from typing_extensions import TypedDict
4040

@@ -45,19 +45,19 @@ class T_Options(TypedDict):
4545
Colormap = str
4646

4747
class T_Options(TypedDict):
48-
arithmetic_join: str
48+
arithmetic_join: Literal["inner", "outer", "left", "right", "exact"]
4949
cmap_divergent: Union[str, "Colormap"]
5050
cmap_sequential: Union[str, "Colormap"]
5151
display_max_rows: int
52-
display_style: str
52+
display_style: Literal["text", "html"]
5353
display_width: int
54-
display_expand_attrs: Union[str, bool]
55-
display_expand_coords: Union[str, bool]
56-
display_expand_data_vars: Union[str, bool]
57-
display_expand_data: Union[str, bool]
54+
display_expand_attrs: Literal["default", True, False]
55+
display_expand_coords: Literal["default", True, False]
56+
display_expand_data_vars: Literal["default", True, False]
57+
display_expand_data: Literal["default", True, False]
5858
enable_cftimeindex: bool
5959
file_cache_maxsize: int
60-
keep_attrs: Union[str, bool]
60+
keep_attrs: Literal["default", True, False]
6161
warn_for_unclosed_files: bool
6262
use_bottleneck: bool
6363

0 commit comments

Comments
 (0)