Skip to content

Commit caa7bb5

Browse files
committed
removed some unnecessary checks
1 parent bf5e61e commit caa7bb5

File tree

5 files changed

+10
-47
lines changed

5 files changed

+10
-47
lines changed

ellar/common/interfaces/context.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from ellar.common.constants import empty_receive
55
from ellar.common.types import T, TReceive, TScope, TSend
6-
from ellar.di import injectable, request_scope
76
from starlette.requests import empty_send
87
from starlette.responses import Response
98

@@ -40,7 +39,6 @@ def get_client(self) -> "WebSocket":
4039
"""Returns WebSocket instance"""
4140

4241

43-
@injectable(scope=request_scope)
4442
class IHostContext(ABC, metaclass=ABCMeta):
4543
@abstractmethod
4644
def get_service_provider(self) -> "EllarInjector":
@@ -75,7 +73,6 @@ def user(self, value: t.Any) -> None:
7573
"""Sets user identity"""
7674

7775

78-
@injectable(scope=request_scope)
7976
class IExecutionContext(IHostContext, ABC):
8077
@abstractmethod
8178
def get_handler(self) -> t.Callable:
@@ -136,8 +133,8 @@ def create_context_type(self, context: IHostContext) -> T:
136133

137134

138135
class IHTTPConnectionContextFactory(SubHostContextFactory[IHTTPHostContext], ABC):
139-
context_typ: t.Type[IHTTPHostContext]
136+
"""HttpContext Factory Interface"""
140137

141138

142139
class IWebSocketContextFactory(SubHostContextFactory[IWebSocketHostContext], ABC):
143-
context_type: t.Type[IWebSocketHostContext]
140+
"""WebsocketContext Factory Interface"""

ellar/common/params/args/base.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050

5151

5252
def add_get_resolver_generator(
53-
param: params.ParamFieldInfo, resolver_gen: t.Type[BulkArgsResolverGenerator]
53+
param: t.Type[params.ParamFieldInfo],
54+
resolver_gen: t.Type[BulkArgsResolverGenerator],
5455
) -> None:
5556
"""
5657
Add a custom Bulk resolver generator a custom route function parameter field type
@@ -384,20 +385,6 @@ async def resolve_body(self, ctx: IExecutionContext) -> ResolverResult:
384385
"""Body Resolver Implementation"""
385386
return ResolverResult({}, [], {})
386387

387-
def __deepcopy__(
388-
self, memodict: t.Optional[t.Dict] = None
389-
) -> "EndpointArgsModel": # pragma: no cover
390-
if memodict is None:
391-
memodict = {}
392-
return self.__copy__(memodict)
393-
394-
def __copy__(
395-
self, memodict: t.Optional[t.Dict] = None
396-
) -> "EndpointArgsModel": # pragma: no cover
397-
if memodict is None:
398-
memodict = {}
399-
return self
400-
401388
def build_body_field(self) -> None: # pragma: no cover
402389
raise NotImplementedError
403390

ellar/common/params/resolvers/parameter.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,8 @@ async def resolve_handle(
276276

277277
if (
278278
value is None
279-
or (
280-
isinstance(self.model_field.field_info.resolver, FormParameterResolver)
281-
and value == ""
282-
)
283-
or (
284-
isinstance(self.model_field.field_info.resolver, FormParameterResolver)
285-
and is_sequence_field(self.model_field)
286-
and len(value) == 0
287-
)
279+
or value == ""
280+
or (is_sequence_field(self.model_field) and len(value) == 0)
288281
):
289282
if self.model_field.required:
290283
return ResolverResult(

ellar/pydantic/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import types
22
import typing as t
33

4+
from pydantic.fields import FieldInfo
45
from pydantic_core import PydanticUndefined, PydanticUndefinedType
56
from pydantic_core import Url as Url
67

78
UnionType = getattr(types, "UnionType", t.Union)
89
NoneType = getattr(types, "NoneType", type(None))
10+
FieldInfoType = t.TypeVar("FieldInfoType", bound=FieldInfo)
911

1012
IncEx = t.Union[t.Set[int], t.Set[str], t.Dict[int, t.Any], t.Dict[str, t.Any]]
1113

12-
1314
Required = PydanticUndefined
1415
Undefined = PydanticUndefined
1516
UndefinedType = PydanticUndefinedType

ellar/pydantic/utils.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import typing as t
22
from collections import deque
3-
from copy import copy
43
from dataclasses import is_dataclass
54

65
from pydantic import (
@@ -21,9 +20,6 @@
2120
from .fields import ModelField
2221
from .types import NoneType, Undefined, UnionType
2322

24-
FieldInfoType = t.TypeVar("FieldInfoType", bound=FieldInfo)
25-
26-
2723
sequence_annotation_to_type = {
2824
t.Sequence: list,
2925
t.List: list,
@@ -98,17 +94,6 @@ def get_definitions(
9894
return field_mapping, definitions # type: ignore[return-value]
9995

10096

101-
def copy_from_field_info(
102-
*, from_: FieldInfo, to_: t.Type[t.Union[FieldInfoType, FieldInfo]], **kwargs: t.Any
103-
) -> t.Union[FieldInfoType, FieldInfo]:
104-
# copy_of_from = copy(from_)
105-
_attributes_set = getattr(from_, "_attributes_set", {})
106-
_attributes_set.update(kwargs)
107-
new_field = to_(**_attributes_set)
108-
new_field.metadata = copy(from_.metadata)
109-
return new_field
110-
111-
11297
def is_scalar_field(field: ModelField) -> bool:
11398
from ellar.common.params.params import BodyFieldInfo, WsBodyFieldInfo
11499

@@ -251,14 +236,14 @@ def is_bytes_annotation(annotation: t.Any) -> bool:
251236
return False
252237

253238

254-
def __default_skip(type_: t.Any) -> bool:
239+
def __default_skip__(type_: t.Any) -> bool:
255240
return False
256241

257242

258243
def search_in_annotation(
259244
annotations: t.Sequence[t.Any],
260245
lookup: t.Tuple,
261-
skip: t.Callable[..., bool] = __default_skip,
246+
skip: t.Callable[..., bool] = __default_skip__,
262247
) -> t.Union[bool, t.Any]:
263248
for item in annotations:
264249
item_origin = get_origin(item) or item

0 commit comments

Comments
 (0)