Fix dict body validation x2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "megasniff"
|
||||
version = "0.2.6"
|
||||
version = "0.2.6.post1"
|
||||
description = "Library for in-time codegened type validation"
|
||||
authors = [
|
||||
{ name = "nikto_b", email = "niktob560@yandex.ru" }
|
||||
|
||||
@@ -13,6 +13,10 @@ from typing import get_args, Union, Annotated, Sequence, TypeAliasType, \
|
||||
import jinja2
|
||||
|
||||
from .utils import *
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import importlib.util
|
||||
|
||||
JsonObject: TypeAlias = Union[None, bool, int, float, str, list['JsonObject'], dict[str, 'JsonObject']]
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ if not isinstance({{from_container}}, dict):
|
||||
{% endif %}
|
||||
for k_{{hashname(unwrapping)}}, v_{{hashname(unwrapping)}} in {{from_container}}.items():
|
||||
{{ render_unwrap(unwrapping.key_unwrap, 'k_' + hashname(unwrapping), 'k_' + hashname(unwrapping)) | indent(4) }}
|
||||
{{ render_unwrap(unwrapping.value_unwrap, 'v_' + hashname(unwrapping), into_container + '[v_' + hashname(unwrapping) + ']') | indent(4) }}
|
||||
{{ render_unwrap(unwrapping.value_unwrap, 'v_' + hashname(unwrapping), into_container + '[k_' + hashname(unwrapping) + ']') | indent(4) }}
|
||||
{%- endset %}
|
||||
{{out}}
|
||||
{%- endmacro %}
|
||||
|
||||
@@ -44,6 +44,20 @@ def test_unions():
|
||||
assert a['a'] == '42a'
|
||||
|
||||
|
||||
def test_dict_body():
|
||||
@dataclass
|
||||
class A:
|
||||
a: dict[str, float]
|
||||
|
||||
defl = SchemaDeflatorGenerator()
|
||||
fn = defl.schema_to_deflator(A)
|
||||
|
||||
a = fn(A({'1': 1.1, '2': 2.2}))
|
||||
print(a)
|
||||
assert a['a']['1'] == 1.1
|
||||
assert a['a']['2'] == 2.2
|
||||
|
||||
|
||||
@dataclass
|
||||
class CircA:
|
||||
b: CircB
|
||||
|
||||
Reference in New Issue
Block a user