Fix dict body validation x2
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "megasniff"
|
name = "megasniff"
|
||||||
version = "0.2.6"
|
version = "0.2.6.post1"
|
||||||
description = "Library for in-time codegened type validation"
|
description = "Library for in-time codegened type validation"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "nikto_b", email = "niktob560@yandex.ru" }
|
{ name = "nikto_b", email = "niktob560@yandex.ru" }
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ from typing import get_args, Union, Annotated, Sequence, TypeAliasType, \
|
|||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
from .utils import *
|
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']]
|
JsonObject: TypeAlias = Union[None, bool, int, float, str, list['JsonObject'], dict[str, 'JsonObject']]
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ if not isinstance({{from_container}}, dict):
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
for k_{{hashname(unwrapping)}}, v_{{hashname(unwrapping)}} in {{from_container}}.items():
|
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.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 %}
|
{%- endset %}
|
||||||
{{out}}
|
{{out}}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|||||||
@@ -44,6 +44,20 @@ def test_unions():
|
|||||||
assert a['a'] == '42a'
|
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
|
@dataclass
|
||||||
class CircA:
|
class CircA:
|
||||||
b: CircB
|
b: CircB
|
||||||
|
|||||||
Reference in New Issue
Block a user