Skip to content

Commit 780e10d

Browse files
🐛 Fixed ignoring unknown-key not silencing the 'Did you mean' message
1 parent 06a3866 commit 780e10d

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

mypy/messages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,17 +1670,16 @@ def typeddict_key_not_found(
16701670
context,
16711671
)
16721672
else:
1673+
err_code = codes.TYPPEDICT_UNKNOWN_KEY if setitem else codes.TYPEDDICT_ITEM
16731674
self.fail(
1674-
f'TypedDict {format_type(typ)} has no key "{item_name}"',
1675-
context,
1676-
code=codes.TYPPEDICT_UNKNOWN_KEY if setitem else codes.TYPEDDICT_ITEM,
1675+
f'TypedDict {format_type(typ)} has no key "{item_name}"', context, code=err_code
16771676
)
16781677
matches = best_matches(item_name, typ.items.keys())
16791678
if matches:
16801679
self.note(
16811680
"Did you mean {}?".format(pretty_seq(matches[:3], "or")),
16821681
context,
1683-
code=codes.TYPEDDICT_ITEM,
1682+
code=err_code,
16841683
)
16851684

16861685
def typeddict_context_ambiguous(self, types: list[TypedDictType], context: Context) -> None:

test-data/unit/check-errorcodes.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,7 @@ class A(TypedDict):
476476
two_commonparts: int
477477

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

0 commit comments

Comments
 (0)