Skip to content

Commit ba9aa63

Browse files
fix TypedDict with wide context bug
1 parent 2e62e5f commit ba9aa63

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mypy/constraints.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,10 @@ def visit_typeddict_type(self, template: TypedDictType) -> list[Constraint]:
13581358
# NOTE: Non-matching keys are ignored. Compatibility is checked
13591359
# elsewhere so this shouldn't be unsafe.
13601360
for item_name, template_item_type, actual_item_type in template.zip(actual):
1361-
res.extend(infer_constraints(template_item_type, actual_item_type, self.direction))
1361+
# Value type is invariant, so irrespective of the direction, we constraint
1362+
# both above and below.
1363+
res.extend(infer_constraints(template_item_type, actual_item_type, SUBTYPE_OF))
1364+
res.extend(infer_constraints(template_item_type, actual_item_type, SUPERTYPE_OF))
13621365
return res
13631366
elif isinstance(actual, AnyType):
13641367
return self.infer_against_any(template.items.values(), actual)

0 commit comments

Comments
 (0)