Skip to content

Commit

Permalink
Support for python 3.10 match statement (#10191)
Browse files Browse the repository at this point in the history
  • Loading branch information
freundTech authored Jan 18, 2022
1 parent 1aa9cf9 commit 9b63751
Show file tree
Hide file tree
Showing 39 changed files with 3,620 additions and 133 deletions.
285 changes: 216 additions & 69 deletions mypy/checker.py

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,11 @@ def nonliteral_tuple_index_helper(self, left_type: TupleType, index: Expression)
else:
return union

def visit_typeddict_index_expr(self, td_type: TypedDictType, index: Expression) -> Type:
def visit_typeddict_index_expr(self, td_type: TypedDictType,
index: Expression,
local_errors: Optional[MessageBuilder] = None
) -> Type:
local_errors = local_errors or self.msg
if isinstance(index, (StrExpr, UnicodeExpr)):
key_names = [index.value]
else:
Expand All @@ -3097,14 +3101,14 @@ def visit_typeddict_index_expr(self, td_type: TypedDictType, index: Expression)
and key_type.fallback.type.fullname != 'builtins.bytes'):
key_names.append(key_type.value)
else:
self.msg.typeddict_key_must_be_string_literal(td_type, index)
local_errors.typeddict_key_must_be_string_literal(td_type, index)
return AnyType(TypeOfAny.from_error)

value_types = []
for key_name in key_names:
value_type = td_type.items.get(key_name)
if value_type is None:
self.msg.typeddict_key_not_found(td_type, key_name, index)
local_errors.typeddict_key_not_found(td_type, key_name, index)
return AnyType(TypeOfAny.from_error)
else:
value_types.append(value_type)
Expand Down
Loading

0 comments on commit 9b63751

Please sign in to comment.