Skip to content

Commit

Permalink
Suggest solutions for a typo in a key of a TypedDict (#8483)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemethf authored Mar 6, 2020
1 parent d2e984a commit 1180a9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@ def typeddict_key_not_found(
item_name, format_item_name_list(typ.items.keys())), context)
else:
self.fail("TypedDict {} has no key '{}'".format(format_type(typ), item_name), context)
matches = best_matches(item_name, typ.items.keys())
if matches:
self.note("Did you mean {}?".format(pretty_seq(matches[:3], "or")), context)

def typeddict_context_ambiguous(
self,
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ reveal_type(c[u'value']) # N: Revealed type is 'builtins.int'
from mypy_extensions import TypedDict
TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
p: TaggedPoint
p['z'] # E: TypedDict "TaggedPoint" has no key 'z'
p['typ'] # E: TypedDict "TaggedPoint" has no key 'typ' \
# N: Did you mean "type"?
[builtins fixtures/dict.pyi]

[case testTypedDictWithUnicodeName]
Expand Down

0 comments on commit 1180a9d

Please sign in to comment.