vtjson 2.2.2__py3-none-any.whl → 2.2.3__py3-none-any.whl

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/vtjson.py CHANGED
@@ -204,7 +204,7 @@ class SchemaError(Exception):
204
204
  pass
205
205
 
206
206
 
207
- __version__ = "2.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: str | optional_key[str]) -> optional_key[str]: ...
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, reason=False)` if it
790
- matches `schema`, but the `name` argument will be used in non-validation
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: indicates whether the original non-validation message
803
- should be suppressed
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, type) and issubclass(schema, compiled_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[str | optional_key[str], object]) -> None:
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
- _fields(self.type_dict),
2725
+ fields(self.type_dict),
2724
2726
  self.__name__,
2725
2727
  reason=True,
2726
2728
  _deferred_compiles=_deferred_compiles,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vtjson
3
- Version: 2.2.2
3
+ Version: 2.2.3
4
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
@@ -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 the same exception as before.
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[list[person_schema]]
129
+ editor: NotRequired[person_schema]
130
130
  year: Annotated[int, ge(1900)]
131
131
  ```
132
132
 
@@ -0,0 +1,9 @@
1
+ vtjson/__init__.py,sha256=oLX4JH6_R7dYtTiGfBG3pQGR21IArspifdmZilbuGOw,68
2
+ vtjson/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ vtjson/vtjson.py,sha256=fH8mrDASyEATdvx_ZRNUG5iuMrmLNu-vYw6vrVGXZ1k,86316
4
+ vtjson-2.2.3.dist-info/AUTHORS,sha256=qmxaXxaIO-YPNHJAZ0dcCrnPCs1x9ocbtMksiy4i80M,21
5
+ vtjson-2.2.3.dist-info/LICENSE,sha256=n7xW-zX8xBLHzCdqWIMRuMzBD_ACLcNCwio0LEkKt1o,1077
6
+ vtjson-2.2.3.dist-info/METADATA,sha256=Tljh-yBYXaG0hkFR8n4Yu-gkn_YIhcU5iVvL21JUdAg,3958
7
+ vtjson-2.2.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ vtjson-2.2.3.dist-info/top_level.txt,sha256=9DlSF3l63igcvnYPcj117F2hzOW4Nx0N-JBoW3jjBZM,7
9
+ vtjson-2.2.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- vtjson/__init__.py,sha256=oLX4JH6_R7dYtTiGfBG3pQGR21IArspifdmZilbuGOw,68
2
- vtjson/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- vtjson/vtjson.py,sha256=_NcOEWxuqZiVJQSn0ZoI9eGxL5GsbtacWIb-BwTPzTY,86274
4
- vtjson-2.2.2.dist-info/AUTHORS,sha256=qmxaXxaIO-YPNHJAZ0dcCrnPCs1x9ocbtMksiy4i80M,21
5
- vtjson-2.2.2.dist-info/LICENSE,sha256=n7xW-zX8xBLHzCdqWIMRuMzBD_ACLcNCwio0LEkKt1o,1077
6
- vtjson-2.2.2.dist-info/METADATA,sha256=reeTR8tvW1KdngstUC6dTdOas_8NXHqdRroKLH_eUfU,3963
7
- vtjson-2.2.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
- vtjson-2.2.2.dist-info/top_level.txt,sha256=9DlSF3l63igcvnYPcj117F2hzOW4Nx0N-JBoW3jjBZM,7
9
- vtjson-2.2.2.dist-info/RECORD,,
File without changes