File: lazy_as_object.py

package info (click to toggle)
python-apischema 0.18.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,608 kB
  • sloc: python: 15,266; sh: 7; makefile: 7
file content (14 lines) | stat: -rw-r--r-- 372 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from apischema import deserialize, serialize
from apischema.objects import ObjectField, set_object_fields


class Foo:
    def __init__(self, bar: int):
        self.bar = bar


set_object_fields(Foo, lambda: [ObjectField("bar", int, required=True)])

foo = deserialize(Foo, {"bar": 0})
assert type(foo) == Foo and foo.bar == 0
assert serialize(Foo, Foo(0)) == {"bar": 0}