|
1 | 1 | import inspect |
2 | 2 | from collections import defaultdict |
3 | 3 | from logging import getLogger |
4 | | -from typing import Any, Awaitable, Callable, Dict, Optional, Union |
| 4 | +from typing import Any, Awaitable, Callable, Dict, Optional, get_type_hints |
5 | 5 |
|
6 | 6 | import pydantic |
7 | 7 | from aiohttp import web |
8 | | -from pydantic.utils import deep_update |
| 8 | +from deepmerge import always_merger |
9 | 9 | from taskiq_dependencies import DependencyGraph |
10 | 10 |
|
11 | 11 | from aiohttp_deps.initializer import InjectableFuncHandler, InjectableViewHandler |
@@ -67,16 +67,11 @@ def _is_optional(annotation: Optional[inspect.Parameter]) -> bool: |
67 | 67 | if annotation is None or annotation.annotation == annotation.empty: |
68 | 68 | return True |
69 | 69 |
|
70 | | - origin = getattr(annotation.annotation, "__origin__", None) |
71 | | - if origin is None: |
72 | | - return False |
| 70 | + def dummy(_var: annotation.annotation) -> None: # type: ignore |
| 71 | + """Dummy function to use for type resolution.""" |
73 | 72 |
|
74 | | - if origin == Union: |
75 | | - args = getattr(annotation.annotation, "__args__", ()) |
76 | | - for arg in args: |
77 | | - if arg is type(None): # noqa: E721, WPS516 |
78 | | - return True |
79 | | - return False |
| 73 | + var = get_type_hints(dummy).get("_var") |
| 74 | + return var == Optional[var] |
80 | 75 |
|
81 | 76 |
|
82 | 77 | def _add_route_def( # noqa: C901 |
@@ -148,7 +143,7 @@ def _add_route_def( # noqa: C901 |
148 | 143 | ) |
149 | 144 |
|
150 | 145 | openapi_schema["paths"][route.resource.canonical].update( |
151 | | - {method.lower(): deep_update(route_info, extra_openapi)}, |
| 146 | + {method.lower(): always_merger.merge(route_info, extra_openapi)}, |
152 | 147 | ) |
153 | 148 |
|
154 | 149 |
|
|
0 commit comments