vtjson 2.2.1__tar.gz → 2.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vtjson-2.2.1/src/vtjson.egg-info → vtjson-2.2.3}/PKG-INFO +4 -4
- {vtjson-2.2.1 → vtjson-2.2.3}/README.md +2 -2
- {vtjson-2.2.1 → vtjson-2.2.3}/pyproject.toml +1 -1
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson/vtjson.py +16 -14
- {vtjson-2.2.1 → vtjson-2.2.3/src/vtjson.egg-info}/PKG-INFO +4 -4
- {vtjson-2.2.1 → vtjson-2.2.3}/tests/test_vtjson.py +6 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/AUTHORS +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/LICENSE +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/setup.cfg +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson/__init__.py +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson/py.typed +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson.egg-info/SOURCES.txt +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson.egg-info/dependency_links.txt +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson.egg-info/requires.txt +0 -0
- {vtjson-2.2.1 → vtjson-2.2.3}/src/vtjson.egg-info/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vtjson
|
|
3
|
-
Version: 2.2.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 2.2.3
|
|
4
|
+
Summary: An easy to use validation library compatible with Python type annotations
|
|
5
5
|
Author-email: Michel Van den Bergh <michel.vandenbergh@uhasselt.be>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vdbergh/vtjson
|
|
7
7
|
Project-URL: Bug Tracker, https://github.com/vdbergh/vtjson/issues
|
|
@@ -78,7 +78,7 @@ class book_schema(TypedDict):
|
|
|
78
78
|
year: int
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
Attempting to validate the bad book would raise
|
|
81
|
+
Attempting to validate the bad book would raise a similar exception as before.
|
|
82
82
|
|
|
83
83
|
Schemas can of course be more complicated and in particular they can be nested.
|
|
84
84
|
Here is an example that shows more of the features of `vtjson`.
|
|
@@ -126,7 +126,7 @@ class person_schema(TypedDict):
|
|
|
126
126
|
class book_schema(TypedDict):
|
|
127
127
|
title: str
|
|
128
128
|
authors: list[person_schema]
|
|
129
|
-
editor: NotRequired[
|
|
129
|
+
editor: NotRequired[person_schema]
|
|
130
130
|
year: Annotated[int, ge(1900)]
|
|
131
131
|
```
|
|
132
132
|
|
|
@@ -58,7 +58,7 @@ class book_schema(TypedDict):
|
|
|
58
58
|
year: int
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
Attempting to validate the bad book would raise
|
|
61
|
+
Attempting to validate the bad book would raise a similar exception as before.
|
|
62
62
|
|
|
63
63
|
Schemas can of course be more complicated and in particular they can be nested.
|
|
64
64
|
Here is an example that shows more of the features of `vtjson`.
|
|
@@ -106,7 +106,7 @@ class person_schema(TypedDict):
|
|
|
106
106
|
class book_schema(TypedDict):
|
|
107
107
|
title: str
|
|
108
108
|
authors: list[person_schema]
|
|
109
|
-
editor: NotRequired[
|
|
109
|
+
editor: NotRequired[person_schema]
|
|
110
110
|
year: Annotated[int, ge(1900)]
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -8,7 +8,7 @@ dynamic = ["version"]
|
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Michel Van den Bergh", email="michel.vandenbergh@uhasselt.be" },
|
|
10
10
|
]
|
|
11
|
-
description = "
|
|
11
|
+
description = "An easy to use validation library compatible with Python type annotations"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
dependencies = ["dnspython", "email_validator", "idna", "python-magic", "typing_extensions"]
|
|
14
14
|
requires-python = ">=3.7"
|
|
@@ -204,7 +204,7 @@ class SchemaError(Exception):
|
|
|
204
204
|
pass
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
__version__ = "2.2.
|
|
207
|
+
__version__ = "2.2.3"
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
@dataclass
|
|
@@ -323,7 +323,7 @@ T = TypeVar("T")
|
|
|
323
323
|
|
|
324
324
|
|
|
325
325
|
@overload
|
|
326
|
-
def _canonize_key(key:
|
|
326
|
+
def _canonize_key(key: StringKeyType) -> optional_key[str]: ...
|
|
327
327
|
|
|
328
328
|
|
|
329
329
|
@overload
|
|
@@ -445,6 +445,9 @@ class optional_key(Generic[K]):
|
|
|
445
445
|
return hash(self.key)
|
|
446
446
|
|
|
447
447
|
|
|
448
|
+
StringKeyType = TypeVar("StringKeyType", bound=Union[str, optional_key[str]])
|
|
449
|
+
|
|
450
|
+
|
|
448
451
|
class _union(compiled_schema):
|
|
449
452
|
schemas: list[compiled_schema]
|
|
450
453
|
|
|
@@ -786,9 +789,8 @@ class _set_name(compiled_schema):
|
|
|
786
789
|
|
|
787
790
|
class set_name(wrapper):
|
|
788
791
|
"""
|
|
789
|
-
An object matches the schema `set_name(schema, name
|
|
790
|
-
|
|
791
|
-
messages.
|
|
792
|
+
An object matches the schema `set_name(schema, name)` if it matches `schema`,
|
|
793
|
+
but the `name` argument will be used in non-validation messages.
|
|
792
794
|
"""
|
|
793
795
|
|
|
794
796
|
reason: bool
|
|
@@ -799,8 +801,8 @@ class set_name(wrapper):
|
|
|
799
801
|
"""
|
|
800
802
|
:param schema: the original schema
|
|
801
803
|
:param name: name for use in non-validation messages
|
|
802
|
-
:param reason:
|
|
803
|
-
|
|
804
|
+
:param reason: if `True` then the original non-validation message
|
|
805
|
+
will not be suppressed
|
|
804
806
|
"""
|
|
805
807
|
if not isinstance(name, str):
|
|
806
808
|
raise SchemaError(f"The name {_c(name)} is not a string")
|
|
@@ -1493,7 +1495,9 @@ def _compile(
|
|
|
1493
1495
|
origin = object()
|
|
1494
1496
|
|
|
1495
1497
|
ret: compiled_schema
|
|
1496
|
-
if isinstance(schema,
|
|
1498
|
+
if isinstance(schema, compiled_schema):
|
|
1499
|
+
ret = schema
|
|
1500
|
+
elif isinstance(schema, type) and issubclass(schema, compiled_schema):
|
|
1497
1501
|
try:
|
|
1498
1502
|
ret = schema()
|
|
1499
1503
|
except Exception:
|
|
@@ -1504,8 +1508,6 @@ def _compile(
|
|
|
1504
1508
|
ret = _validate_schema(schema)
|
|
1505
1509
|
elif isinstance(schema, wrapper):
|
|
1506
1510
|
ret = schema.__compile__(_deferred_compiles=_deferred_compiles)
|
|
1507
|
-
elif isinstance(schema, compiled_schema):
|
|
1508
|
-
ret = schema
|
|
1509
1511
|
elif supports_TypedDict and typing.is_typeddict(schema):
|
|
1510
1512
|
ret = _compile(
|
|
1511
1513
|
protocol(schema, dict=True), _deferred_compiles=_deferred_compiles
|
|
@@ -2037,7 +2039,7 @@ class one_of(compiled_schema):
|
|
|
2037
2039
|
class keys(compiled_schema):
|
|
2038
2040
|
"""
|
|
2039
2041
|
This represents a dictionary containing all the keys in a collection of
|
|
2040
|
-
keys
|
|
2042
|
+
keys.
|
|
2041
2043
|
"""
|
|
2042
2044
|
|
|
2043
2045
|
args: tuple[object, ...]
|
|
@@ -2238,12 +2240,12 @@ class fields(wrapper):
|
|
|
2238
2240
|
"""
|
|
2239
2241
|
Matches Python objects with attributes `field1, field2, ..., fieldN` whose
|
|
2240
2242
|
corresponding values should validate against `schema1, schema2, ...,
|
|
2241
|
-
schemaN` respectively
|
|
2243
|
+
schemaN` respectively.
|
|
2242
2244
|
"""
|
|
2243
2245
|
|
|
2244
2246
|
d: dict[optional_key[str], object]
|
|
2245
2247
|
|
|
2246
|
-
def __init__(self, d: Mapping[
|
|
2248
|
+
def __init__(self, d: Mapping[StringKeyType, object]) -> None:
|
|
2247
2249
|
"""
|
|
2248
2250
|
:param d: a dictionary associating fields with schemas
|
|
2249
2251
|
|
|
@@ -2720,7 +2722,7 @@ class protocol(wrapper):
|
|
|
2720
2722
|
) -> compiled_schema:
|
|
2721
2723
|
if not self.dict:
|
|
2722
2724
|
return _set_name(
|
|
2723
|
-
|
|
2725
|
+
fields(self.type_dict),
|
|
2724
2726
|
self.__name__,
|
|
2725
2727
|
reason=True,
|
|
2726
2728
|
_deferred_compiles=_deferred_compiles,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vtjson
|
|
3
|
-
Version: 2.2.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 2.2.3
|
|
4
|
+
Summary: An easy to use validation library compatible with Python type annotations
|
|
5
5
|
Author-email: Michel Van den Bergh <michel.vandenbergh@uhasselt.be>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vdbergh/vtjson
|
|
7
7
|
Project-URL: Bug Tracker, https://github.com/vdbergh/vtjson/issues
|
|
@@ -78,7 +78,7 @@ class book_schema(TypedDict):
|
|
|
78
78
|
year: int
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
Attempting to validate the bad book would raise
|
|
81
|
+
Attempting to validate the bad book would raise a similar exception as before.
|
|
82
82
|
|
|
83
83
|
Schemas can of course be more complicated and in particular they can be nested.
|
|
84
84
|
Here is an example that shows more of the features of `vtjson`.
|
|
@@ -126,7 +126,7 @@ class person_schema(TypedDict):
|
|
|
126
126
|
class book_schema(TypedDict):
|
|
127
127
|
title: str
|
|
128
128
|
authors: list[person_schema]
|
|
129
|
-
editor: NotRequired[
|
|
129
|
+
editor: NotRequired[person_schema]
|
|
130
130
|
year: Annotated[int, ge(1900)]
|
|
131
131
|
```
|
|
132
132
|
|
|
@@ -309,6 +309,12 @@ class TestValidation(unittest.TestCase):
|
|
|
309
309
|
object_ = {"b": "c"}
|
|
310
310
|
validate(schema, object_)
|
|
311
311
|
show(mc)
|
|
312
|
+
schema = {optional_key("a?", _optional=False): str, "b": str}
|
|
313
|
+
with self.assertRaises(ValidationError) as mc:
|
|
314
|
+
object_ = {"b": "c"}
|
|
315
|
+
validate(schema, object_)
|
|
316
|
+
show(mc)
|
|
317
|
+
|
|
312
318
|
with self.assertRaises(ValidationError) as mc:
|
|
313
319
|
object_ = {"a": "c", "b": "d"}
|
|
314
320
|
validate(schema, object_)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|