Browse Source

Remove unused import, make changes in `models.py`

pull/9753/head
Yurii Motov 9 months ago
parent
commit
a5f119963a
  1. 27
      fastapi/dependencies/models.py
  2. 1
      fastapi/dependencies/utils.py

27
fastapi/dependencies/models.py

@ -1,7 +1,7 @@
import inspect import inspect
import sys import sys
from dataclasses import dataclass, field from dataclasses import dataclass, field
from functools import cached_property from functools import cached_property, partial
from typing import Any, Callable, List, Optional, Sequence, Union from typing import Any, Callable, List, Optional, Sequence, Union
from fastapi._compat import ModelField from fastapi._compat import ModelField
@ -53,25 +53,34 @@ class Dependant:
@cached_property @cached_property
def is_gen_callable(self) -> bool: def is_gen_callable(self) -> bool:
if inspect.isgeneratorfunction(self.call): use_call: Any = self.call
if isinstance(self.call, partial):
use_call = self.call.func
if inspect.isgeneratorfunction(use_call):
return True return True
dunder_call = getattr(self.call, "__call__", None) # noqa: B004 dunder_call = getattr(use_call, "__call__", None) # noqa: B004
return inspect.isgeneratorfunction(dunder_call) return inspect.isgeneratorfunction(dunder_call)
@cached_property @cached_property
def is_async_gen_callable(self) -> bool: def is_async_gen_callable(self) -> bool:
if inspect.isasyncgenfunction(self.call): use_call: Any = self.call
if isinstance(self.call, partial):
use_call = self.call.func
if inspect.isasyncgenfunction(use_call):
return True return True
dunder_call = getattr(self.call, "__call__", None) # noqa: B004 dunder_call = getattr(use_call, "__call__", None) # noqa: B004
return inspect.isasyncgenfunction(dunder_call) return inspect.isasyncgenfunction(dunder_call)
@cached_property @cached_property
def is_coroutine_callable(self) -> bool: def is_coroutine_callable(self) -> bool:
if inspect.isroutine(self.call): use_call: Any = self.call
return iscoroutinefunction(self.call) if isinstance(self.call, partial):
if inspect.isclass(self.call): use_call = self.call.func
if inspect.isroutine(use_call):
return iscoroutinefunction(use_call)
if inspect.isclass(use_call):
return False return False
dunder_call = getattr(self.call, "__call__", None) # noqa: B004 dunder_call = getattr(use_call, "__call__", None) # noqa: B004
return iscoroutinefunction(dunder_call) return iscoroutinefunction(dunder_call)
@cached_property @cached_property

1
fastapi/dependencies/utils.py

@ -2,7 +2,6 @@ import inspect
from contextlib import AsyncExitStack, contextmanager from contextlib import AsyncExitStack, contextmanager
from copy import copy, deepcopy from copy import copy, deepcopy
from dataclasses import dataclass from dataclasses import dataclass
from functools import partial
from typing import ( from typing import (
Any, Any,
Callable, Callable,

Loading…
Cancel
Save