Browse Source

The code has been refactored

pull/6038/head
yyklimenko 2 years ago
parent
commit
d2ec5d6620
  1. 11
      fastapi/dependencies/protocols.py
  2. 9
      fastapi/dependencies/stubs.py
  3. 10
      fastapi/dependencies/utils.py

11
fastapi/dependencies/protocols.py

@ -0,0 +1,11 @@
from typing import Any, Tuple
from typing_extensions import Protocol
class GenericTypeProtocol(Protocol):
class OriginTypeProtocol(Protocol):
__parameters__: Tuple[Any]
__origin__: OriginTypeProtocol
__args__: Tuple[Any]

9
fastapi/dependencies/stubs.py

@ -1,9 +0,0 @@
from typing import Any, Tuple
class GenericTypeStub:
class OriginTypeStub:
__parameters__: Tuple[Any]
__origin__: OriginTypeStub
__args__: Tuple[Any]

10
fastapi/dependencies/utils.py

@ -26,7 +26,7 @@ from fastapi.concurrency import (
contextmanager_in_threadpool, contextmanager_in_threadpool,
) )
from fastapi.dependencies.models import Dependant, SecurityRequirement from fastapi.dependencies.models import Dependant, SecurityRequirement
from fastapi.dependencies.stubs import GenericTypeStub from fastapi.dependencies.protocols import GenericTypeProtocol
from fastapi.logger import logger from fastapi.logger import logger
from fastapi.security.base import SecurityBase from fastapi.security.base import SecurityBase
from fastapi.security.oauth2 import OAuth2, SecurityScopes from fastapi.security.oauth2 import OAuth2, SecurityScopes
@ -264,14 +264,12 @@ def substitute_generic_type(annotation: Any, typevars: Dict[str, Any]) -> Any:
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature: def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
typevars = None typevars = None
if is_generic_type(call): if is_generic_type(call):
generic: GenericTypeStub = cast(GenericTypeStub, call) generic: GenericTypeProtocol = cast(GenericTypeProtocol, call)
origin: Any = generic.__origin__
typevars = { typevars = {
typevar.__name__: value typevar.__name__: value
for typevar, value in zip( for typevar, value in zip(origin.__parameters__, generic.__args__)
generic.__origin__.__parameters__, generic.__args__
)
} }
origin: Any = generic.__origin__
call = origin.__init__ call = origin.__init__
signature = inspect.signature(call) signature = inspect.signature(call)

Loading…
Cancel
Save