Skip to content

Commit

Permalink
add test for kw_only
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Jan 26, 2022
1 parent 59e0549 commit 573d7a8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses
import pickle
import sys
from collections.abc import Hashable
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -989,3 +990,17 @@ def __new__(cls, *args, **kwargs):
instance = cls(a=test_string)
assert instance._special_property == 1
assert instance.a == test_string


if sys.version_info >= (3, 10):

def test_kw_only():
@pydantic.dataclasses.dataclass(kw_only=True)
class A:
a: int | None = None
b: str

with pytest.raises(TypeError):
A(1, '')

assert A(b='hi').b == 'hi'

0 comments on commit 573d7a8

Please sign in to comment.