MCPcopy
hub / github.com/pydantic/pydantic / test_self_forward_ref_local

Function test_self_forward_ref_local

tests/test_forward_ref.py:156–174  ·  view source on GitHub ↗
(create_module)

Source from the content-addressed store, hash-verified

154
155
156def test_self_forward_ref_local(create_module):
157 @create_module
158 def module():
159 from typing import ForwardRef
160
161 from pydantic import BaseModel
162
163 def main():
164 Foo = ForwardRef('Foo')
165
166 class Foo(BaseModel):
167 a: int = 123
168 b: Foo = None
169
170 return Foo
171
172 Foo = module.main()
173 assert Foo().model_dump() == {'a': 123, 'b': None}
174 assert Foo(b={'a': '321'}).model_dump() == {'a': 123, 'b': {'a': 321, 'b': None}}
175
176
177def test_forward_ref_dataclass(create_module):

Callers

nothing calls this directly

Calls 2

FooClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected