MCPcopy
hub / github.com/pydantic/pydantic / test_custom_init_signature

Function test_custom_init_signature

tests/test_model_signature.py:49–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47
48
49def test_custom_init_signature():
50 class MyModel(BaseModel):
51 id: int
52 name: str = 'John Doe'
53 f__: str = Field(alias='foo')
54
55 model_config = ConfigDict(extra='allow')
56
57 def __init__(self, id: int = 1, bar=2, *, baz: Any, **data):
58 super().__init__(id=id, **data)
59 self.bar = bar
60 self.baz = baz
61
62 sig = signature(MyModel)
63 assert _equals(
64 map(str, sig.parameters.values()),
65 ('id: int = 1', 'bar=2', 'baz: Any', "name: str = 'John Doe'", 'foo: str', '**data'),
66 )
67
68 assert _equals(str(sig), "(id: int = 1, bar=2, *, baz: Any, name: str = 'John Doe', foo: str, **data) -> None")
69
70
71def test_custom_init_signature_with_no_var_kw():

Callers

nothing calls this directly

Calls 2

valuesMethod · 0.80
_equalsFunction · 0.70

Tested by

no test coverage detected