File: exclude_defaults_none.py

package info (click to toggle)
python-apischema 0.18.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,624 kB
  • sloc: python: 15,266; sh: 7; makefile: 7
file content (13 lines) | stat: -rw-r--r-- 257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
from dataclasses import dataclass

from apischema import serialize


@dataclass
class Foo:
    bar: int = 0
    baz: str | None = None


assert serialize(Foo, Foo(), exclude_defaults=True) == {}
assert serialize(Foo, Foo(), exclude_none=True) == {"bar": 0}