File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 5
5
import sys
6
6
from collections .abc import Iterator
7
7
from configparser import ConfigParser
8
- from typing import Any , Callable , cast
8
+ from typing import Any , Callable
9
9
10
10
from mypy .errorcodes import ErrorCode
11
11
from mypy .expandtype import expand_type , expand_type_by_instance
@@ -339,7 +339,10 @@ def expand_type(
339
339
if include_root_type and isinstance (expanded_type , Instance ) and is_root_model (expanded_type .type ):
340
340
# When a root model is used as a field, Pydantic allows both an instance of the root model
341
341
# as well as instances of the `root` field type:
342
- root_type = cast (Type , expanded_type .type ['root' ].type )
342
+ root_type = expanded_type .type ['root' ].type
343
+ if root_type is None :
344
+ # Happens if the hint for 'root' has unsolved forward references
345
+ return expanded_type
343
346
expanded_root_type = expand_type_by_instance (root_type , expanded_type )
344
347
expanded_type = UnionType ([expanded_type , expanded_root_type ])
345
348
return expanded_type
You can’t perform that action at this time.
0 commit comments