Skip to content

Commit

Permalink
🐛 Fixed ignoring unknown-key not silencing the 'Did you mean' message
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquimEsteves committed Dec 8, 2022
1 parent 06a3866 commit 780e10d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 3 additions & 4 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,17 +1670,16 @@ def typeddict_key_not_found(
context,
)
else:
err_code = codes.TYPPEDICT_UNKNOWN_KEY if setitem else codes.TYPEDDICT_ITEM
self.fail(
f'TypedDict {format_type(typ)} has no key "{item_name}"',
context,
code=codes.TYPPEDICT_UNKNOWN_KEY if setitem else codes.TYPEDDICT_ITEM,
f'TypedDict {format_type(typ)} has no key "{item_name}"', context, code=err_code
)
matches = best_matches(item_name, typ.items.keys())
if matches:
self.note(
"Did you mean {}?".format(pretty_seq(matches[:3], "or")),
context,
code=codes.TYPEDDICT_ITEM,
code=err_code,
)

def typeddict_context_ambiguous(self, types: list[TypedDictType], context: Context) -> None:
Expand Down
4 changes: 1 addition & 3 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ class A(TypedDict):
two_commonparts: int

a: A = {'one_commonpart': 1, 'two_commonparts': 2}
a['other_commonpart'] = 3 # type: ignore[typeddict-unknown-key] \
# N: Did you mean "one_commonpart" or "two_commonparts"? \
# N: Error code "typeddict-item" not covered by "type: ignore" comment
a['other_commonpart'] = 3 # type: ignore[typeddict-unknown-key]
not_exist = a['not_exist'] # type: ignore[typeddict-item]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
Expand Down

0 comments on commit 780e10d

Please sign in to comment.