Skip to content

Commit

Permalink
update dev deps (#45)
Browse files Browse the repository at this point in the history
* update dev deps

* fix types

* wip

* wip

* fix generics

* versions

* typing.tuple
  • Loading branch information
keithasaurus authored Aug 19, 2024
1 parent e87258a commit 777f3d9
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 582 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "Koda Validate"
copyright = "2023, Keith Philpott"
copyright = "2024, Keith Philpott"
author = "Keith Philpott"
release = "4.1.1"
release = "4.2.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion examples/django_example/django_example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

urlpatterns = [
path("contact", contact),
path("contact-async", contact_async), # type: ignore[arg-type]
path("contact-async", contact_async),
]
11 changes: 11 additions & 0 deletions examples/exact_item_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from koda_validate import (
ExactItemCount,
ListValidator,
StringValidator,
UniformTupleValidator,
)

list_validator = ListValidator(StringValidator(), predicates=[ExactItemCount(1)])
u_tuple_validator = UniformTupleValidator(
StringValidator(), predicates=[ExactItemCount(1)]
)
9 changes: 3 additions & 6 deletions koda_validate/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ def __init__(
self,
*,
into: Callable[[T1], Ret],
keys: Tuple[
KeyValidator[T1],
],
keys: Tuple[KeyValidator[T1],],
validate_object: Optional[Callable[[Ret], Optional[ErrType]]] = None,
validate_object_async: Optional[
Callable[[Ret], Awaitable[Optional[ErrType]]]
Expand Down Expand Up @@ -867,7 +865,6 @@ def __init__(
] = None,
fail_on_unknown_keys: bool = False,
) -> None:

self.into = into
# needs to be `Any` until we have variadic generics presumably
self.keys: Tuple[KeyValidator[Any], ...] = keys
Expand All @@ -891,8 +888,8 @@ def __init__(

for key, val in keys:
is_required = not isinstance(val, KeyNotRequired)
self._fast_keys_sync.append((key, _wrap_sync_validator(val), is_required)) # type: ignore # noqa: E501
self._fast_keys_async.append((key, _wrap_async_validator(val), is_required)) # type: ignore # noqa: E501
self._fast_keys_sync.append((key, _wrap_sync_validator(val), is_required))
self._fast_keys_async.append((key, _wrap_async_validator(val), is_required))
self._key_set.add(key)

self._unknown_keys_err: ExtraKeysErr = ExtraKeysErr(self._key_set)
Expand Down
17 changes: 3 additions & 14 deletions koda_validate/generic.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from decimal import Decimal
from typing import (
Any,
ClassVar,
Hashable,
List,
Optional,
Set,
Sized,
Tuple,
Type,
TypeVar,
)
from typing import Any, ClassVar, Hashable, List, Optional, Set, Tuple, Type, TypeVar
from uuid import UUID

from koda import Thunk
Expand Down Expand Up @@ -227,10 +216,10 @@ def __call__(self, val: ListOrTupleOrSetAny) -> bool:


@dataclass
class ExactItemCount(Predicate[Sized]):
class ExactItemCount(Predicate[ListOrTupleOrSetAny]):
item_count: int

def __call__(self, val: Sized) -> bool:
def __call__(self, val: ListOrTupleOrSetAny) -> bool:
return len(val) == self.item_count


Expand Down
9 changes: 5 additions & 4 deletions koda_validate/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
ReturnOverrideKey = Tuple[Literal["return_key"]]
RETURN_OVERRIDE_KEY: ReturnOverrideKey = ("return_key",)

OverridesDict = Dict[Union[str, ReturnOverrideKey], Validator[Any]]
OverridesDictKey = Union[str, ReturnOverrideKey]
OverridesDict = Dict[OverridesDictKey, Validator[Any]]


def resolve_signature_typehint_default(annotation: Any) -> Validator[Any]:
Expand Down Expand Up @@ -100,7 +101,7 @@ def resolve_signature_typehint_default(annotation: Any) -> Validator[Any]:
def _get_validator(
overrides: OverridesDict,
typehint_resolver: Callable[[Any], Validator[Any]],
param_name: str,
param_name: OverridesDictKey,
annotation: Any,
) -> Validator[Any]:
return (
Expand Down Expand Up @@ -382,12 +383,12 @@ def validate_signature(

def inner(func_inner: _DecoratedFunc) -> _DecoratedFunc:
# there may be a good way to replace this cast with ParamSpec in the future
return cast(_DecoratedFunc, _wrap_fn_partial(func_inner))
return _wrap_fn_partial(func_inner)

return inner
else:
# there may be a good way to replace this cast with ParamSpec in the future
return cast(_DecoratedFunc, _wrap_fn_partial(func))
return _wrap_fn_partial(func)


def _trunc_str(s: str, max_chars: int) -> str:
Expand Down
2 changes: 1 addition & 1 deletion koda_validate/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
self.fields = fields
self.validate_object = validate_object
self.coerce = coerce
self._len_predicate = ExactItemCount(len(fields))
self._len_predicate: Predicate[Tuple[Any, ...]] = ExactItemCount(len(fields))
self._wrapped_fields_sync = [_wrap_sync_validator(v) for v in fields]
self._wrapped_fields_async = [_wrap_async_validator(v) for v in fields]

Expand Down
Loading

0 comments on commit 777f3d9

Please sign in to comment.