vtjson 2.2.4__tar.gz → 2.2.5__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: vtjson
3
- Version: 2.2.4
3
+ Version: 2.2.5
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
@@ -17,6 +17,7 @@ Requires-Dist: email_validator
17
17
  Requires-Dist: idna
18
18
  Requires-Dist: python-magic
19
19
  Requires-Dist: typing_extensions
20
+ Dynamic: license-file
20
21
 
21
22
  # vtjson
22
23
 
@@ -204,7 +204,7 @@ class SchemaError(Exception):
204
204
  pass
205
205
 
206
206
 
207
- __version__ = "2.2.4"
207
+ __version__ = "2.2.5"
208
208
 
209
209
 
210
210
  @dataclass
@@ -2175,6 +2175,7 @@ class _cond(compiled_schema):
2175
2175
 
2176
2176
  class cond(wrapper):
2177
2177
  """
2178
+ Args is a list of tuples `(if_schema, then_schema)`.
2178
2179
  An object is successively validated against `if_schema1`, `if_schema2`,
2179
2180
  ... until a validation succeeds. When this happens the object should match
2180
2181
  the corresponding `then_schema`. If no `if_schema` succeeds then the
@@ -2243,8 +2244,9 @@ class _fields(compiled_schema):
2243
2244
 
2244
2245
  class fields(wrapper, Generic[StringKeyType]):
2245
2246
  """
2246
- Matches Python objects with attributes `field1, field2, ..., fieldN` whose
2247
- corresponding values should validate against `schema1, schema2, ...,
2247
+ `d` is a dictionary `{"field1": schema1, ...}`.
2248
+ This matches Python objects with attributes `field1, field2, ..., fieldN`
2249
+ whose corresponding values should validate against `schema1, schema2, ...,
2248
2250
  schemaN` respectively.
2249
2251
  """
2250
2252
 
@@ -2306,16 +2308,16 @@ class _filter(compiled_schema):
2306
2308
  obj = self.filter(obj)
2307
2309
  except Exception as e:
2308
2310
  return (
2309
- f"Applying {self.filter_name} to {name} "
2311
+ f"Applying {repr(self.filter_name)} to {name} "
2310
2312
  f"(value: {_c(obj)}) failed: {str(e)}"
2311
2313
  )
2312
2314
  name = f"{self.filter_name}({name})"
2313
- return self.schema.__validate__(obj, name="object", strict=strict, subs=subs)
2315
+ return self.schema.__validate__(obj, name=name, strict=strict, subs=subs)
2314
2316
 
2315
2317
 
2316
2318
  class filter(wrapper):
2317
2319
  """
2318
- Applies `callable` to the object and validates the result with `schema`.
2320
+ Applies `filter` to the object and validates the result with `schema`.
2319
2321
  If the callable throws an exception then validation fails.
2320
2322
  """
2321
2323
 
@@ -2751,6 +2753,9 @@ class protocol(wrapper):
2751
2753
  if not isinstance(dict, bool):
2752
2754
  raise SchemaError("bool flag is not a bool")
2753
2755
 
2756
+ if not hasattr(schema, "__annotations__"):
2757
+ raise SchemaError("schema does not have type annotations")
2758
+
2754
2759
  self.dict = dict
2755
2760
  self.schema = schema
2756
2761
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: vtjson
3
- Version: 2.2.4
3
+ Version: 2.2.5
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
@@ -17,6 +17,7 @@ Requires-Dist: email_validator
17
17
  Requires-Dist: idna
18
18
  Requires-Dist: python-magic
19
19
  Requires-Dist: typing_extensions
20
+ Dynamic: license-file
20
21
 
21
22
  # vtjson
22
23
 
@@ -964,7 +964,6 @@ class TestValidation(unittest.TestCase):
964
964
  def test_make_type(self) -> None:
965
965
  schema: object
966
966
  object_: object
967
- global url
968
967
  schema = {"a": 1}
969
968
  t = make_type(schema, "example", debug=True)
970
969
  self.assertTrue(t.__name__ == "example")
@@ -2314,7 +2313,7 @@ class TestValidation(unittest.TestCase):
2314
2313
  if not vtjson.supports_structural:
2315
2314
  with self.assertRaises(SchemaError) as mc_:
2316
2315
  schema = protocol(dummy)
2317
- validate(schema, "a")
2316
+ compile(schema)
2318
2317
  show(mc_)
2319
2318
  return
2320
2319
 
@@ -2324,7 +2323,6 @@ class TestValidation(unittest.TestCase):
2324
2323
 
2325
2324
  with self.assertRaises(SchemaError) as mc_:
2326
2325
  schema = protocol({})
2327
- validate(schema, "a")
2328
2326
  show(mc_)
2329
2327
 
2330
2328
  schema = protocol(dummy)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes