Skip to content

Commit 1aea7a3

Browse files
committed
Bumped version up to 1.2.9. Formatted code and made docs.
1 parent 4590eaa commit 1aea7a3

6 files changed

+36
-13
lines changed

docs/api/typing_validation.validation_failure.rst

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ FailureTreeVisitor
1515
:show-inheritance:
1616
:members:
1717

18+
InvalidNumpyDTypeValidationFailure
19+
----------------------------------
20+
21+
.. autoclass:: typing_validation.validation_failure.InvalidNumpyDTypeValidationFailure
22+
:show-inheritance:
23+
:members:
24+
1825
MissingKeysValidationFailure
1926
----------------------------
2027

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
# built documents.
3434
#
3535
# The full version, including alpha/beta/rc tags.
36-
release = "1.2.4"
36+
release = "1.2.9"
3737
# The short X.Y version.
38-
version = "1.2.4"
38+
version = "1.2.9"
3939

4040

4141
# -- General configuration ---------------------------------------------------

typing_validation/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Runtime validation using type hints.
33
"""
44

5-
__version__ = "1.2.4"
5+
__version__ = "1.2.9"
66

77
from .inspector import TypeInspector, UnsupportedType
88
from .validation import (

typing_validation/inspector.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ def _repr(
332332
name = param.__name__
333333
bound = param.__bound__
334334
if bound is None:
335-
lines = [indent+f"TypeVar({name!r})"]
335+
lines = [indent + f"TypeVar({name!r})"]
336336
else:
337337
bound_lines, idx = self._repr(idx + 1, level + 1)
338338
lines = [
339-
indent+f"TypeVar({name!r}, bound=",
339+
indent + f"TypeVar({name!r}, bound=",
340340
*bound_lines,
341-
indent+")"
341+
indent + ")",
342342
]
343343
return lines, idx
344344
if tag == "union":
@@ -423,9 +423,11 @@ def _repr(
423423
return lines, idx
424424
assert isinstance(param, int)
425425
lines = [
426-
indent + f"{pending_type.__name__}["
427-
if pending_type is not None
428-
else indent + "Tuple["
426+
(
427+
indent + f"{pending_type.__name__}["
428+
if pending_type is not None
429+
else indent + "Tuple["
430+
)
429431
]
430432
for _ in range(param):
431433
item_lines, idx = self._repr(idx + 1, level + 1)

typing_validation/validation.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
from keyword import iskeyword
1111
import sys
1212
import typing
13-
from typing import Any, ForwardRef, Hashable, Optional, TypeVar, Union, get_type_hints
13+
from typing import (
14+
Any,
15+
ForwardRef,
16+
Hashable,
17+
Optional,
18+
TypeVar,
19+
Union,
20+
get_type_hints,
21+
)
1422
import typing_extensions
1523

1624
from .validation_failure import (
@@ -220,6 +228,7 @@ def _type_error(
220228
setattr(error, "validation_failure", validation_failure)
221229
return error
222230

231+
223232
def _typevar_error(val: Any, t: Any, bound_error: TypeError) -> TypeError:
224233
assert hasattr(bound_error, "validation_failure"), bound_error
225234
cause = getattr(bound_error, "validation_failure")
@@ -229,6 +238,7 @@ def _typevar_error(val: Any, t: Any, bound_error: TypeError) -> TypeError:
229238
setattr(error, "validation_failure", validation_failure)
230239
return error
231240

241+
232242
def _idx_type_error(
233243
val: Any, t: Any, idx_error: TypeError, *, idx: int, ordered: bool
234244
) -> TypeError:
@@ -524,6 +534,7 @@ def _extract_dtypes(t: Any) -> typing.Sequence[Any]:
524534
dtype for member in t.__args__ for dtype in _extract_dtypes(member)
525535
]
526536
import numpy as np # pylint: disable = import-outside-toplevel
537+
527538
if hasattr(t, "__origin__"):
528539
t_origin = t.__origin__
529540
if t_origin in {
@@ -542,8 +553,10 @@ def _extract_dtypes(t: Any) -> typing.Sequence[Any]:
542553
return [t]
543554
raise TypeError()
544555

556+
545557
def _validate_numpy_array(val: Any, t: Any) -> None:
546558
import numpy as np # pylint: disable = import-outside-toplevel
559+
547560
if not isinstance(val, TypeInspector):
548561
_validate_type(val, np.ndarray)
549562
assert hasattr(t, "__args__"), _missing_args_msg(t)
@@ -588,6 +601,7 @@ def _validate_typevar(val: Any, t: TypeVar) -> None:
588601
except TypeError as e:
589602
raise _typevar_error(val, t, e) from None
590603

604+
591605
# def _validate_callable(val: Any, t: Any) -> None:
592606
# """
593607
# Callable validation

typing_validation/validation_failure.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def __repr__(self) -> str:
197197

198198
def _str_type_descr(self, type_quals: tuple[str, ...] = ()) -> str:
199199
descr = (
200-
"type alias" if isinstance(self.t, str)
201-
else "type variable" if isinstance(self.t, TypeVar)
202-
else "type"
200+
"type alias"
201+
if isinstance(self.t, str)
202+
else "type variable" if isinstance(self.t, TypeVar) else "type"
203203
)
204204
if type_quals:
205205
descr = " ".join(type_quals) + " " + descr

0 commit comments

Comments
 (0)