Skip to content

Conversation

ddfisher
Copy link
Collaborator

This means mypy will no longer give Need type annotation for variable errors for assignments with values of type Generator[str, None, None] or List[None] or similar. However, lists, sets, and dicts that are initialized with None values that were previously inferred may now need type annotations. I.e. constructs that look like:

x = [None]
x.append(0)

will now be type errors unless they have explicit annotations.

Supplants #2225. Fixes #2246. Fixes #2195. Fixes #2258.

reveal_type(x) # E: Revealed type is 'builtins.dict[Union[builtins.str, builtins.None], Union[builtins.int, builtins.None]]'
[builtins fixtures/dict.pyi]
[out]
main:2: error: Invalid index type "str" for "dict"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

off-topic: this ought to be "key type" not "index type".

@gvanrossum gvanrossum merged commit ad62a08 into master Oct 22, 2016
@gvanrossum gvanrossum deleted the none-collection-annotation branch October 22, 2016 00:18
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.

2 participants