55"""
66
77import warnings
8- from typing import Any , Optional , Tuple # noqa: F401
8+ from typing import Any , Optional , Tuple , Union # noqa: F401
99
1010import numpy as np
11+ from typing_extensions import Literal
1112
1213import tcod ._internal
1314import tcod .constants
@@ -92,7 +93,7 @@ def __init__(
9293 self ,
9394 width : int ,
9495 height : int ,
95- order : str = "C" ,
96+ order : Union [ Literal [ "C" ], Literal [ "F" ]] = "C" ,
9697 buffer : Optional [np .ndarray ] = None ,
9798 ):
9899 self ._key_color = None # type: Optional[Tuple[int, int, int]]
@@ -131,7 +132,9 @@ def __init__(
131132 self .clear ()
132133
133134 @classmethod
134- def _from_cdata (cls , cdata : Any , order : str = "C" ) -> "Console" :
135+ def _from_cdata (
136+ cls , cdata : Any , order : Union [Literal ["C" ], Literal ["F" ]] = "C"
137+ ) -> "Console" :
135138 """Return a Console instance which wraps this `TCOD_Console*` object."""
136139 if isinstance (cdata , cls ):
137140 return cdata
@@ -141,7 +144,9 @@ def _from_cdata(cls, cdata: Any, order: str = "C") -> "Console":
141144 return self
142145
143146 @classmethod
144- def _get_root (cls , order : Optional [str ] = None ) -> "Console" :
147+ def _get_root (
148+ cls , order : Optional [Union [Literal ["C" ], Literal ["F" ]]] = None
149+ ) -> "Console" :
145150 """Return a root console singleton with valid buffers.
146151
147152 This function will also update an already active root console.
@@ -156,7 +161,9 @@ def _get_root(cls, order: Optional[str] = None) -> "Console":
156161 self ._init_setup_console_data (self ._order )
157162 return self
158163
159- def _init_setup_console_data (self , order : str = "C" ) -> None :
164+ def _init_setup_console_data (
165+ self , order : Union [Literal ["C" ], Literal ["F" ]] = "C"
166+ ) -> None :
160167 """Setup numpy arrays over libtcod data buffers."""
161168 global _root_console
162169 self ._key_color = None
@@ -195,7 +202,7 @@ def bg(self) -> np.ndarray:
195202 ``console.bg[x, y, channel] # order='F'``.
196203
197204 """
198- bg = self ._tiles ["bg" ][..., :3 ]
205+ bg = self ._tiles ["bg" ][..., :3 ] # type: np.ndarray
199206 if self ._order == "F" :
200207 bg = bg .transpose (1 , 0 , 2 )
201208 return bg
@@ -209,7 +216,7 @@ def fg(self) -> np.ndarray:
209216 Index this array with ``console.fg[i, j, channel] # order='C'`` or
210217 ``console.fg[x, y, channel] # order='F'``.
211218 """
212- fg = self ._tiles ["fg" ][..., :3 ]
219+ fg = self ._tiles ["fg" ][..., :3 ] # type: np.ndarray
213220 if self ._order == "F" :
214221 fg = fg .transpose (1 , 0 , 2 )
215222 return fg
0 commit comments