Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 2, 2021

Description

Fixes #11093

I explained what I analyzed about the issue in the comment #11093 (comment), so I would appreciate if someone could take a loot at it together with this PR.

Clearly, my fix is nothing but a workaround for the specific case in the issue, but surprisingly there is no regression in exisiting tests. So, I made this PR anyway as a starting point to ask some opinions about the issue itself. (Also, maybe CI will show me some regression).

It's highly likely that I'm missing some important use of SemanticAnalyzer.translate_dict_call, but I couldn't figure it out by myself.

Thanks a lot for the review!

Test Plan

I added new tests in check-type-aliases.test:

  • testTypeAliasDictNoVarAnnotatedError,
  • testTypeAliasListNoVarAnnotatedError.

I think the relevant existing tests are mostly in check-typeddict.test and especially this test case:

  • testCanCreateTypedDictInstanceWithDictCall.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this pull request Nov 3, 2025
Resolves a bad false negative and a false positive

Previously, for `D = dict[str, str]` we would require a type annotation
for `d = D()` and we would fail to error on `D(x=1)`

Fixes python#11093, fixes python#11246
@ilevkivskyi
Copy link
Member

This is superseded by #20170

wyattscarpenter pushed a commit to wyattscarpenter/mypy that referenced this pull request Nov 3, 2025
Resolves a bad false negative and a false positive

Previously, for `D = dict[str, str]` we would require a type annotation
for `d = D()` and we would fail to error on `D(x=1)`

Fixes python#11093, fixes python#11246, fixes python#13320, fixes python#16047
@hi-ogawa hi-ogawa deleted the 11093-type-alias-dict-call-expr branch November 4, 2025 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need type annotation for predefined dict generic (3.9)

2 participants