|
23 | 23 | ] |
24 | 24 |
|
25 | 25 | # the possible types for an individual HTTP header |
26 | | -# This should be a Union, but mypy doesn't pass unless it's a TypeVar. |
27 | | -HeaderValue = t.Union[str, list[str], tuple[str, ...]] |
| 26 | +HeaderValue = str | list[str] | tuple[str, ...] |
28 | 27 |
|
29 | 28 | # the possible types for HTTP headers |
30 | 29 | HeadersValue = t.Union[ |
|
47 | 46 | # callback annotated with flask.Response fail type checking. |
48 | 47 | ResponseClass = t.TypeVar("ResponseClass", bound="Response") |
49 | 48 |
|
50 | | -AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named |
51 | | -AfterRequestCallable = t.Union[ |
52 | | - t.Callable[[ResponseClass], ResponseClass], |
53 | | - t.Callable[[ResponseClass], t.Awaitable[ResponseClass]], |
54 | | -] |
55 | | -BeforeFirstRequestCallable = t.Union[ |
56 | | - t.Callable[[], None], t.Callable[[], t.Awaitable[None]] |
57 | | -] |
58 | | -BeforeRequestCallable = t.Union[ |
59 | | - t.Callable[[], t.Optional[ResponseReturnValue]], |
60 | | - t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]], |
61 | | -] |
| 49 | +AppOrBlueprintKey = str | None # The App key is None, whereas blueprints are named |
| 50 | +AfterRequestCallable = ( |
| 51 | + t.Callable[[ResponseClass], ResponseClass] |
| 52 | + | t.Callable[[ResponseClass], t.Awaitable[ResponseClass]] |
| 53 | +) |
| 54 | +BeforeFirstRequestCallable = t.Callable[[], None] | t.Callable[[], t.Awaitable[None]] |
| 55 | +BeforeRequestCallable = ( |
| 56 | + t.Callable[[], ResponseReturnValue | None] |
| 57 | + | t.Callable[[], t.Awaitable[ResponseReturnValue | None]] |
| 58 | +) |
62 | 59 | ShellContextProcessorCallable = t.Callable[[], dict[str, t.Any]] |
63 | | -TeardownCallable = t.Union[ |
64 | | - t.Callable[[t.Optional[BaseException]], None], |
65 | | - t.Callable[[t.Optional[BaseException]], t.Awaitable[None]], |
66 | | -] |
67 | | -TemplateContextProcessorCallable = t.Union[ |
68 | | - t.Callable[[], dict[str, t.Any]], |
69 | | - t.Callable[[], t.Awaitable[dict[str, t.Any]]], |
70 | | -] |
| 60 | +TeardownCallable = ( |
| 61 | + t.Callable[[BaseException | None], None] |
| 62 | + | t.Callable[[BaseException | None], t.Awaitable[None]] |
| 63 | +) |
| 64 | +TemplateContextProcessorCallable = ( |
| 65 | + t.Callable[[], dict[str, t.Any]] | t.Callable[[], t.Awaitable[dict[str, t.Any]]] |
| 66 | +) |
71 | 67 | TemplateFilterCallable = t.Callable[..., t.Any] |
72 | 68 | TemplateGlobalCallable = t.Callable[..., t.Any] |
73 | 69 | TemplateTestCallable = t.Callable[..., bool] |
74 | 70 | URLDefaultCallable = t.Callable[[str, dict[str, t.Any]], None] |
75 | | -URLValuePreprocessorCallable = t.Callable[ |
76 | | - [t.Optional[str], t.Optional[dict[str, t.Any]]], None |
77 | | -] |
| 71 | +URLValuePreprocessorCallable = t.Callable[[str | None, dict[str, t.Any] | None], None] |
78 | 72 |
|
79 | 73 | # This should take Exception, but that either breaks typing the argument |
80 | 74 | # with a specific exception, or decorating multiple times with different |
81 | 75 | # exceptions (and using a union type on the argument). |
82 | 76 | # https://github.com/pallets/flask/issues/4095 |
83 | 77 | # https://github.com/pallets/flask/issues/4295 |
84 | 78 | # https://github.com/pallets/flask/issues/4297 |
85 | | -ErrorHandlerCallable = t.Union[ |
86 | | - t.Callable[[t.Any], ResponseReturnValue], |
87 | | - t.Callable[[t.Any], t.Awaitable[ResponseReturnValue]], |
88 | | -] |
| 79 | +ErrorHandlerCallable = ( |
| 80 | + t.Callable[[t.Any], ResponseReturnValue] |
| 81 | + | t.Callable[[t.Any], t.Awaitable[ResponseReturnValue]] |
| 82 | +) |
89 | 83 |
|
90 | | -RouteCallable = t.Union[ |
91 | | - t.Callable[..., ResponseReturnValue], |
92 | | - t.Callable[..., t.Awaitable[ResponseReturnValue]], |
93 | | -] |
| 84 | +RouteCallable = ( |
| 85 | + t.Callable[..., ResponseReturnValue] |
| 86 | + | t.Callable[..., t.Awaitable[ResponseReturnValue]] |
| 87 | +) |
0 commit comments