|
| 1 | +from __future__ import annotations |
1 | 2 | from typing import Union, Dict, List, Tuple, Callable, Optional, Any, TYPE_CHECKING |
| 3 | +from typing_extensions import Literal, TypedDict, TypeAlias |
| 4 | +from bottle import Bottle |
2 | 5 |
|
3 | 6 | # This business is slightly awkward, but needed for backward compatibility, |
4 | | -# because Python < 3.7 doesn't have __future__/annotations, and <3.10 doesn't |
5 | | -# support TypeAlias. |
| 7 | +# because Python <3.10 doesn't support TypeAlias, jinja2 may not be available |
| 8 | +# at runtime, and geventwebsocket.websocket doesn't have type annotations so |
| 9 | +# that direct imports will raise an error. |
6 | 10 | if TYPE_CHECKING: |
7 | 11 | from jinja2 import Environment |
8 | | - try: |
9 | | - from typing import TypeAlias # Introduced in Python 3.10 |
10 | | - JinjaEnvironmentT: TypeAlias = Environment |
11 | | - except ImportError: |
12 | | - JinjaEnvironmentT = Environment # type: ignore |
| 12 | + JinjaEnvironmentT: TypeAlias = Environment |
13 | 13 | from geventwebsocket.websocket import WebSocket |
14 | | - WebSocketT = WebSocket |
| 14 | + WebSocketT: TypeAlias = WebSocket |
15 | 15 | else: |
16 | | - JinjaEnvironmentT = None |
17 | | - WebSocketT = Any |
| 16 | + JinjaEnvironmentT: TypeAlias = Any |
| 17 | + WebSocketT: TypeAlias = Any |
18 | 18 |
|
19 | | -OptionsDictT = Dict[ |
20 | | - str, |
21 | | - Optional[ |
22 | | - Union[ |
23 | | - str, bool, int, float, |
24 | | - List[str], Tuple[int, int], Dict[str, Tuple[int, int]], |
25 | | - Callable[..., Any], JinjaEnvironmentT |
26 | | - ] |
27 | | - ] |
28 | | - ] |
| 19 | +OptionsDictT = TypedDict( |
| 20 | + 'OptionsDictT', |
| 21 | + { |
| 22 | + 'mode': Optional[Union[str, Literal[False]]], |
| 23 | + 'host': str, |
| 24 | + 'port': int, |
| 25 | + 'block': bool, |
| 26 | + 'jinja_templates': Optional[str], |
| 27 | + 'cmdline_args': List[str], |
| 28 | + 'size': Optional[Tuple[int, int]], |
| 29 | + 'position': Optional[Tuple[int, int]], |
| 30 | + 'geometry': Dict[str, Tuple[int, int]], |
| 31 | + 'close_callback': Optional[Callable[..., Any]], |
| 32 | + 'app_mode': bool, |
| 33 | + 'all_interfaces': bool, |
| 34 | + 'disable_cache': bool, |
| 35 | + 'default_path': str, |
| 36 | + 'app': Bottle, |
| 37 | + 'shutdown_delay': float, |
| 38 | + 'suppress_error': bool, |
| 39 | + 'jinja_env': JinjaEnvironmentT, |
| 40 | + }, |
| 41 | + total=False |
| 42 | +) |
0 commit comments