Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 15, 2024
1 parent a5d674b commit 44bea7e
Show file tree
Hide file tree
Showing 40 changed files with 118 additions and 175 deletions.
9 changes: 3 additions & 6 deletions apischema/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@


@overload
def alias(alias_: str, *, override: bool = True) -> Metadata:
...
def alias(alias_: str, *, override: bool = True) -> Metadata: ...


@overload
def alias(override: bool) -> Metadata:
...
def alias(override: bool) -> Metadata: ...


@overload
def alias(aliaser: Aliaser) -> Callable[[Cls], Cls]:
...
def alias(aliaser: Aliaser) -> Callable[[Cls], Cls]: ...


def alias(arg=None, *, override: bool = True): # type: ignore
Expand Down
12 changes: 4 additions & 8 deletions apischema/conversions/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ def __set_name__(self, owner, name):


@overload
def deserializer(deserializer: Deserializer) -> Deserializer:
...
def deserializer(deserializer: Deserializer) -> Deserializer: ...


@overload
def deserializer(
*, lazy: Callable[[], Union[Converter, Conversion]], target: Type
) -> None:
...
) -> None: ...


def deserializer(
Expand Down Expand Up @@ -130,15 +128,13 @@ def __set_name__(self, owner, name):


@overload
def serializer(serializer: Serializer) -> Serializer:
...
def serializer(serializer: Serializer) -> Serializer: ...


@overload
def serializer(
*, lazy: Callable[[], Union[Converter, Conversion]], source: Type
) -> Callable[[Serializer], Serializer]:
...
) -> Callable[[Serializer], Serializer]: ...


def serializer(
Expand Down
12 changes: 5 additions & 7 deletions apischema/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from apischema.cache import CacheAwareDict
from apischema.objects.fields import check_field_or_name, get_field_name

_dependent_requireds: MutableMapping[
type, List[Tuple[Any, Collection[Any]]]
] = CacheAwareDict(defaultdict(list))
_dependent_requireds: MutableMapping[type, List[Tuple[Any, Collection[Any]]]] = (
CacheAwareDict(defaultdict(list))
)

DependentRequired = Mapping[str, AbstractSet[str]]

Expand Down Expand Up @@ -47,13 +47,11 @@ def dependent_required(
fields: Mapping[Any, Collection[Any]],
*groups: Collection[Any],
owner: Optional[type] = None,
):
...
): ...


@overload
def dependent_required(*groups: Collection[Any], owner: Optional[type] = None):
...
def dependent_required(*groups: Collection[Any], owner: Optional[type] = None): ...


def dependent_required(*groups: Collection[Any], owner: Optional[type] = None): # type: ignore
Expand Down
20 changes: 9 additions & 11 deletions apischema/deserialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,11 @@ def _visit_conversion(
def factory(constraints: Optional[Constraints], _) -> DeserializationMethod:
conv_alternatives = tuple(
ConversionAlternative(
conv.converter.func
if isinstance(conv.converter, ValueErrorCatcher)
else conv.converter,
(
conv.converter.func
if isinstance(conv.converter, ValueErrorCatcher)
else conv.converter
),
(fact if dynamic else fact.merge(constraints)).method,
isinstance(conv.converter, ValueErrorCatcher),
)
Expand Down Expand Up @@ -743,8 +745,7 @@ def deserialization_method(
pass_through: Optional[CollectionOrPredicate[type]] = None,
schema: Optional[Schema] = None,
validators: Collection[Callable] = (),
) -> Callable[[Any], T]:
...
) -> Callable[[Any], T]: ...


@overload
Expand All @@ -761,8 +762,7 @@ def deserialization_method(
pass_through: Optional[CollectionOrPredicate[type]] = None,
schema: Optional[Schema] = None,
validators: Collection[Callable] = (),
) -> Callable[[Any], Any]:
...
) -> Callable[[Any], Any]: ...


def deserialization_method(
Expand Down Expand Up @@ -821,8 +821,7 @@ def deserialize(
pass_through: Optional[CollectionOrPredicate[type]] = None,
schema: Optional[Schema] = None,
validators: Collection[Callable] = (),
) -> T:
...
) -> T: ...


@overload
Expand All @@ -840,8 +839,7 @@ def deserialize(
pass_through: Optional[CollectionOrPredicate[type]] = None,
schema: Optional[Schema] = None,
validators: Collection[Callable] = (),
) -> Any:
...
) -> Any: ...


def deserialize(
Expand Down
6 changes: 3 additions & 3 deletions apischema/deserialization/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,9 @@ def deserialize(self, data: Any) -> Any:
if self.additional_field is not None:
additional: dict = {key: data[key] for key in remain}
try:
values[
self.additional_field.name
] = self.additional_field.method.deserialize(additional)
values[self.additional_field.name] = (
self.additional_field.method.deserialize(additional)
)
except ValidationError as err:
if not self.additional_field.fall_back_on_default:
errors = extend_errors(errors, err.messages)
Expand Down
8 changes: 5 additions & 3 deletions apischema/graphql/relay/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def __init_subclass__(cls, **kwargs):
fields.append(
(
CLIENT_MUTATION_ID,
ClientMutationId
if cls._client_mutation_id
else Optional[ClientMutationId],
(
ClientMutationId
if cls._client_mutation_id
else Optional[ClientMutationId]
),
# TODO why missing here?
MISSING if cls._client_mutation_id else None, # type: ignore
)
Expand Down
6 changes: 2 additions & 4 deletions apischema/graphql/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def resolver_parameters(


@overload
def resolver(__method_or_property: MethodOrProp) -> MethodOrProp:
...
def resolver(__method_or_property: MethodOrProp) -> MethodOrProp: ...


@overload
Expand All @@ -174,8 +173,7 @@ def resolver(
parameters_metadata: Optional[Mapping[str, Mapping]] = None,
serialized: bool = False,
owner: Optional[Type] = None,
) -> Callable[[MethodOrProp], MethodOrProp]:
...
) -> Callable[[MethodOrProp], MethodOrProp]: ...


def resolver(
Expand Down
6 changes: 3 additions & 3 deletions apischema/json_schema/refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class RefsExtractor(ConversionsVisitor, ObjectVisitor, WithConversionsResolver):
def __init__(self, default_conversion: DefaultConversion, refs: Refs):
super().__init__(default_conversion)
self.refs = refs
self._rec_guard: Dict[
Tuple[AnyType, Optional[AnyConversion]], int
] = defaultdict(lambda: 0)
self._rec_guard: Dict[Tuple[AnyType, Optional[AnyConversion]], int] = (
defaultdict(lambda: 0)
)

def _incr_ref(self, ref: Optional[str], tp: AnyType) -> bool:
if ref is None:
Expand Down
20 changes: 12 additions & 8 deletions apischema/json_schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ def _visited_union(self, results: Sequence[JsonSchema]) -> JsonSchema:
return JsonSchema()
elif all(alt.keys() == {"type"} for alt in results):
types: Any = chain.from_iterable(
[res["type"]]
if isinstance(res["type"], (str, JsonType))
else res["type"]
(
[res["type"]]
if isinstance(res["type"], (str, JsonType))
else res["type"]
)
for res in results
)
return json_schema(type=list(types))
Expand Down Expand Up @@ -513,11 +515,13 @@ def properties(
for field in fields
if not field.is_aggregate
for required in [
field.required
if is_typed_dict(get_origin_or_type(tp))
else not field.skippable(
settings.serialization.exclude_defaults,
settings.serialization.exclude_none,
(
field.required
if is_typed_dict(get_origin_or_type(tp))
else not field.skippable(
settings.serialization.exclude_defaults,
settings.serialization.exclude_none,
)
)
]
] + [
Expand Down
3 changes: 1 addition & 2 deletions apischema/json_schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,4 @@ def json_schema(
uniqueItems: bool = False,
unevaluatedProperties: Union[bool, JsonSchema] = True,
writeOnly: bool = False,
) -> JsonSchema:
...
) -> JsonSchema: ...
6 changes: 3 additions & 3 deletions apischema/objects/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def get_field_name(field_or_name: Any, *, methods: bool = False) -> str:
_bad_field(field_or_name, methods)


_class_fields: MutableMapping[
type, Callable[[], Sequence[ObjectField]]
] = CacheAwareDict({})
_class_fields: MutableMapping[type, Callable[[], Sequence[ObjectField]]] = (
CacheAwareDict({})
)


def set_object_fields(
Expand Down
12 changes: 4 additions & 8 deletions apischema/objects/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ def __getattribute__(self, name: str) -> ObjectField:


@overload
def get_field(obj: Type[T]) -> T:
...
def get_field(obj: Type[T]) -> T: ...


@overload
def get_field(obj: T) -> T:
...
def get_field(obj: T) -> T: ...


# Overload because of Mypy issue
Expand All @@ -104,13 +102,11 @@ def __getattribute__(self, name: str) -> str:


@overload
def get_alias(obj: Type[T]) -> T:
...
def get_alias(obj: Type[T]) -> T: ...


@overload
def get_alias(obj: T) -> T:
...
def get_alias(obj: T) -> T: ...


def get_alias(obj: Union[Type[T], T]) -> T:
Expand Down
15 changes: 5 additions & 10 deletions apischema/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,23 @@ def __post_init__(self):


@overload
def order(__value: int) -> Ordering:
...
def order(__value: int) -> Ordering: ...


@overload
def order(*, after: Any) -> Ordering:
...
def order(*, after: Any) -> Ordering: ...


@overload
def order(*, before: Any) -> Ordering:
...
def order(*, before: Any) -> Ordering: ...


@overload
def order(__fields: Sequence[Any]) -> Callable[[Cls], Cls]:
...
def order(__fields: Sequence[Any]) -> Callable[[Cls], Cls]: ...


@overload
def order(__override: Mapping[Any, Ordering]) -> Callable[[Cls], Cls]:
...
def order(__override: Mapping[Any, Ordering]) -> Callable[[Cls], Cls]: ...


def order(__arg=None, *, before=None, after=None):
Expand Down
8 changes: 5 additions & 3 deletions apischema/recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ def visit(self, tp: AnyType) -> Result:
tp,
self._conversion,
self.default_conversion,
DeserializationRecursiveChecker # type: ignore
if isinstance(self, DeserializationVisitor)
else SerializationRecursiveChecker,
(
DeserializationRecursiveChecker # type: ignore
if isinstance(self, DeserializationVisitor)
else SerializationRecursiveChecker
),
):
cache_key = tp, self._conversion
if cache_key in self._cache:
Expand Down
6 changes: 2 additions & 4 deletions apischema/serialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ def serialize(
fall_back_on_any: Optional[bool] = None,
no_copy: Optional[bool] = None,
pass_through: Optional[PassThroughOptions] = None,
) -> Any:
...
) -> Any: ...


@overload
Expand All @@ -631,8 +630,7 @@ def serialize(
fall_back_on_any: bool = True,
no_copy: Optional[bool] = None,
pass_through: Optional[PassThroughOptions] = None,
) -> Any:
...
) -> Any: ...


def serialize( # type: ignore
Expand Down
6 changes: 2 additions & 4 deletions apischema/serialization/serialized_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def none_error_handler(error: Exception, obj: Any, alias: str) -> None:


@overload
def serialized(__method_or_property: MethodOrProp) -> MethodOrProp:
...
def serialized(__method_or_property: MethodOrProp) -> MethodOrProp: ...


@overload
Expand All @@ -124,8 +123,7 @@ def serialized(
order: Optional[Ordering] = None,
schema: Optional[Schema] = None,
owner: Optional[Type] = None,
) -> Callable[[MethodOrProp], MethodOrProp]:
...
) -> Callable[[MethodOrProp], MethodOrProp]: ...


def serialized(
Expand Down
Loading

0 comments on commit 44bea7e

Please sign in to comment.