I expected this would do something sane:
from pydantic import BaseModel from typing import Optional, ForwardRef Foo = ForwardRef('Foo') class Foo(BaseModel): foo: Optional[Foo]
Instead it does not:
Traceback (most recent call last): File "./lib/python3.7/site-packages/pydantic/validators.py", line 262, in find_validators if issubclass(type_, val_type): TypeError: issubclass() arg 1 must be a class The above exception was the direct cause of the following exception: Traceback (most recent call last): File "./test.py", line 6, in <module> class Foo(BaseModel): File "./lib/python3.7/site-packages/pydantic/main.py", line 120, in __new__ config=config, File "./lib/python3.7/site-packages/pydantic/fields.py", line 105, in infer schema=schema, File "./lib/python3.7/site-packages/pydantic/fields.py", line 85, in __init__ self.prepare() File "./lib/python3.7/site-packages/pydantic/fields.py", line 133, in prepare self._populate_sub_fields() File "./lib/python3.7/site-packages/pydantic/fields.py", line 177, in _populate_sub_fields ) for t in types_] File "./lib/python3.7/site-packages/pydantic/fields.py", line 177, in <listcomp> ) for t in types_] File "./lib/python3.7/site-packages/pydantic/fields.py", line 85, in __init__ self.prepare() File "./lib/python3.7/site-packages/pydantic/fields.py", line 134, in prepare self._populate_validators() File "./lib/python3.7/site-packages/pydantic/fields.py", line 217, in _populate_validators self.model_config.arbitrary_types_allowed)), File "./lib/python3.7/site-packages/pydantic/validators.py", line 265, in find_validators raise RuntimeError(f'error checking inheritance of {type_!r} (type: {display_as_type(type_)})') from e RuntimeError: error checking inheritance of ForwardRef('Foo') (type: ForwardRef('Foo'))
It looks like ForwardRef isn't resolved (and can't be, in this case, because it isn't defined yet).
gangefors, koliyo, mastergenius, demosdemon and bykof
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4