Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pytype/overlays/typed_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def make_class_from_pyi(self, cls_name, pytd_cls):
)

for c in pytd_cls.constants:
typ = self.ctx.convert.constant_to_value(c.type)
# The field types may refer back to the class being built.
with self.ctx.allow_recursive_convert():
typ = self.ctx.convert.constant_to_value(c.type)
props.add(c.name, typ, total)

# Process base classes and generate the __init__ signature.
Expand Down
18 changes: 18 additions & 0 deletions pytype/tests/test_typed_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,24 @@ class Bar:
""",
)

def test_recursive(self):
with self.DepTree([(
"foo.pyi",
"""
from typing import Union, Optional
from typing_extensions import TypedDict
class Foo(TypedDict, total=False):
name: str
nested: 'Foo'
""",
)]):
self.CheckWithErrors("""
import foo
foo.Foo(name='foo', a=1) # wrong-keyword-args
# 'nested' cannot be checked because Foo is recursive.
foo.Foo(name='foo', nested=45)
""")

def test_total_false(self):
with self.DepTree([
(
Expand Down
Loading