Skip to content

Commit 4e20a5d

Browse files
committed
Clean up Literal types.
Literal types with multiple parameters are automatically Union's.
1 parent 20e5c16 commit 4e20a5d

File tree

7 files changed

+13
-19
lines changed

7 files changed

+13
-19
lines changed

tcod/_internal.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
import functools
44
import warnings
5-
from typing import Any, AnyStr, Callable, TypeVar, Union, cast
5+
from typing import Any, AnyStr, Callable, TypeVar, cast
66

77
import numpy as np
88
from typing_extensions import Literal, NoReturn
@@ -43,9 +43,7 @@ def pending_deprecate(
4343
return deprecate(message, category, stacklevel)
4444

4545

46-
def verify_order(
47-
order: Union[Literal["C"], Literal["F"]]
48-
) -> Union[Literal["C"], Literal["F"]]:
46+
def verify_order(order: Literal["C", "F"]) -> Literal["C", "F"]:
4947
order = order.upper() # type: ignore
5048
if order not in ("C", "F"):
5149
raise TypeError("order must be 'C' or 'F', not %r" % (order,))

tcod/console.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(
9393
self,
9494
width: int,
9595
height: int,
96-
order: Union[Literal["C"], Literal["F"]] = "C",
96+
order: Literal["C", "F"] = "C",
9797
buffer: Optional[np.ndarray] = None,
9898
):
9999
self._key_color = None # type: Optional[Tuple[int, int, int]]
@@ -133,7 +133,7 @@ def __init__(
133133

134134
@classmethod
135135
def _from_cdata(
136-
cls, cdata: Any, order: Union[Literal["C"], Literal["F"]] = "C"
136+
cls, cdata: Any, order: Literal["C", "F"] = "C"
137137
) -> "Console":
138138
"""Return a Console instance which wraps this `TCOD_Console*` object."""
139139
if isinstance(cdata, cls):
@@ -144,9 +144,7 @@ def _from_cdata(
144144
return self
145145

146146
@classmethod
147-
def _get_root(
148-
cls, order: Optional[Union[Literal["C"], Literal["F"]]] = None
149-
) -> "Console":
147+
def _get_root(cls, order: Optional[Literal["C", "F"]] = None) -> "Console":
150148
"""Return a root console singleton with valid buffers.
151149
152150
This function will also update an already active root console.
@@ -161,9 +159,7 @@ def _get_root(
161159
self._init_setup_console_data(self._order)
162160
return self
163161

164-
def _init_setup_console_data(
165-
self, order: Union[Literal["C"], Literal["F"]] = "C"
166-
) -> None:
162+
def _init_setup_console_data(self, order: Literal["C", "F"] = "C") -> None:
167163
"""Setup numpy arrays over libtcod data buffers."""
168164
global _root_console
169165
self._key_color = None

tcod/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
""" # noqa: E501
5050
import os
5151
import sys
52-
from typing import Any, Iterable, List, Optional, Tuple, Union
52+
from typing import Any, Iterable, List, Optional, Tuple
5353

5454
from typing_extensions import Literal
5555

@@ -269,7 +269,7 @@ def new_console(
269269
min_columns: int = 1,
270270
min_rows: int = 1,
271271
magnification: float = 1.0,
272-
order: Union[Literal["C"], Literal["F"]] = "C",
272+
order: Literal["C", "F"] = "C",
273273
) -> tcod.console.Console:
274274
"""Return a new console sized for this context.
275275

tcod/libtcodpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def console_init_root(
880880
title: Optional[str] = None,
881881
fullscreen: bool = False,
882882
renderer: Optional[int] = None,
883-
order: Union[Literal["C"], Literal["F"]] = "C",
883+
order: Literal["C", "F"] = "C",
884884
vsync: Optional[bool] = None,
885885
) -> tcod.console.Console:
886886
"""Set up the primary display and return the root console.

tcod/map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
"""
55
import warnings
6-
from typing import Any, Tuple, Union
6+
from typing import Any, Tuple
77

88
import numpy as np
99
from typing_extensions import Literal
@@ -73,7 +73,7 @@ def __init__(
7373
self,
7474
width: int,
7575
height: int,
76-
order: Union[Literal["C"], Literal["F"]] = "C",
76+
order: Literal["C", "F"] = "C",
7777
):
7878
warnings.warn(
7979
"This class may perform poorly and is no longer needed.",

tcod/noise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def grid(
442442
shape: Tuple[int, ...],
443443
scale: Union[Tuple[float, ...], float],
444444
origin: Optional[Tuple[int, ...]] = None,
445-
indexing: Union[Literal["ij"], Literal["xy"]] = "xy",
445+
indexing: Literal["ij", "xy"] = "xy",
446446
) -> Tuple[np.ndarray, ...]:
447447
"""A helper function for generating a grid of noise samples.
448448

tcod/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def get_path(self, x: int, y: int) -> List[Tuple[int, int]]:
312312
def maxarray(
313313
shape: Tuple[int, ...],
314314
dtype: Any = np.int32,
315-
order: Union[Literal["C"], Literal["F"]] = "C",
315+
order: Literal["C", "F"] = "C",
316316
) -> np.ndarray:
317317
"""Return a new array filled with the maximum finite value for `dtype`.
318318

0 commit comments

Comments
 (0)