Skip to content

Commit

Permalink
Bumped version up to 1.2.9. Formatted code and made docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
sg495 committed Feb 20, 2024
1 parent 4590eaa commit 1aea7a3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
7 changes: 7 additions & 0 deletions docs/api/typing_validation.validation_failure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ FailureTreeVisitor
:show-inheritance:
:members:

InvalidNumpyDTypeValidationFailure
----------------------------------

.. autoclass:: typing_validation.validation_failure.InvalidNumpyDTypeValidationFailure
:show-inheritance:
:members:

MissingKeysValidationFailure
----------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = "1.2.4"
release = "1.2.9"
# The short X.Y version.
version = "1.2.4"
version = "1.2.9"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion typing_validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Runtime validation using type hints.
"""

__version__ = "1.2.4"
__version__ = "1.2.9"

from .inspector import TypeInspector, UnsupportedType
from .validation import (
Expand Down
14 changes: 8 additions & 6 deletions typing_validation/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ def _repr(
name = param.__name__
bound = param.__bound__
if bound is None:
lines = [indent+f"TypeVar({name!r})"]
lines = [indent + f"TypeVar({name!r})"]
else:
bound_lines, idx = self._repr(idx + 1, level + 1)
lines = [
indent+f"TypeVar({name!r}, bound=",
indent + f"TypeVar({name!r}, bound=",
*bound_lines,
indent+")"
indent + ")",
]
return lines, idx
if tag == "union":
Expand Down Expand Up @@ -423,9 +423,11 @@ def _repr(
return lines, idx
assert isinstance(param, int)
lines = [
indent + f"{pending_type.__name__}["
if pending_type is not None
else indent + "Tuple["
(
indent + f"{pending_type.__name__}["
if pending_type is not None
else indent + "Tuple["
)
]
for _ in range(param):
item_lines, idx = self._repr(idx + 1, level + 1)
Expand Down
16 changes: 15 additions & 1 deletion typing_validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
from keyword import iskeyword
import sys
import typing
from typing import Any, ForwardRef, Hashable, Optional, TypeVar, Union, get_type_hints
from typing import (
Any,
ForwardRef,
Hashable,
Optional,
TypeVar,
Union,
get_type_hints,
)
import typing_extensions

from .validation_failure import (
Expand Down Expand Up @@ -220,6 +228,7 @@ def _type_error(
setattr(error, "validation_failure", validation_failure)
return error


def _typevar_error(val: Any, t: Any, bound_error: TypeError) -> TypeError:
assert hasattr(bound_error, "validation_failure"), bound_error
cause = getattr(bound_error, "validation_failure")
Expand All @@ -229,6 +238,7 @@ def _typevar_error(val: Any, t: Any, bound_error: TypeError) -> TypeError:
setattr(error, "validation_failure", validation_failure)
return error


def _idx_type_error(
val: Any, t: Any, idx_error: TypeError, *, idx: int, ordered: bool
) -> TypeError:
Expand Down Expand Up @@ -524,6 +534,7 @@ def _extract_dtypes(t: Any) -> typing.Sequence[Any]:
dtype for member in t.__args__ for dtype in _extract_dtypes(member)
]
import numpy as np # pylint: disable = import-outside-toplevel

if hasattr(t, "__origin__"):
t_origin = t.__origin__
if t_origin in {
Expand All @@ -542,8 +553,10 @@ def _extract_dtypes(t: Any) -> typing.Sequence[Any]:
return [t]
raise TypeError()


def _validate_numpy_array(val: Any, t: Any) -> None:
import numpy as np # pylint: disable = import-outside-toplevel

if not isinstance(val, TypeInspector):
_validate_type(val, np.ndarray)
assert hasattr(t, "__args__"), _missing_args_msg(t)
Expand Down Expand Up @@ -588,6 +601,7 @@ def _validate_typevar(val: Any, t: TypeVar) -> None:
except TypeError as e:
raise _typevar_error(val, t, e) from None


# def _validate_callable(val: Any, t: Any) -> None:
# """
# Callable validation
Expand Down
6 changes: 3 additions & 3 deletions typing_validation/validation_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def __repr__(self) -> str:

def _str_type_descr(self, type_quals: tuple[str, ...] = ()) -> str:
descr = (
"type alias" if isinstance(self.t, str)
else "type variable" if isinstance(self.t, TypeVar)
else "type"
"type alias"
if isinstance(self.t, str)
else "type variable" if isinstance(self.t, TypeVar) else "type"
)
if type_quals:
descr = " ".join(type_quals) + " " + descr
Expand Down

0 comments on commit 1aea7a3

Please sign in to comment.