Skip to content

Commit

Permalink
ensuring warning free serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Jan 21, 2025
1 parent 2d0b850 commit 327c60a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/serializers/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,26 @@ class Model:
m = v.validate_python({'extra': 'extra'})

assert s.to_python(m) == {'extra': 'extra bam!'}


@pytest.mark.filterwarnings('error')
def test_initvar_not_required_on_ser() -> None:
@dataclasses.dataclass
class Model:
x: int
y: dataclasses.InitVar[str]

schema = core_schema.dataclass_schema(
Model,
core_schema.dataclass_args_schema(
'Model',
[
core_schema.dataclass_field(name='x', schema=core_schema.int_schema()),
core_schema.dataclass_field(name='y', init_only=True, schema=core_schema.str_schema()),
],
),
['x'],
)

s = SchemaSerializer(schema)
assert s.to_python(Model(x=1, y='a')) == {'x': 1}

0 comments on commit 327c60a

Please sign in to comment.