Skip to content

TypedDict.keys() and items() should return KeysView and ItemsView #3473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
crusaderky opened this issue Nov 20, 2019 · 2 comments · Fixed by #3529
Closed

TypedDict.keys() and items() should return KeysView and ItemsView #3473

crusaderky opened this issue Nov 20, 2019 · 2 comments · Fixed by #3529

Comments

@crusaderky
Copy link
Contributor

Reopened from python/mypy#7845 as requested

mypy incorrectly believes that TypedDict.keys() and TypedDict.items() return an AbstractSet, whereas it should be more accurately a KeysView and a ItemsView respectively:

from typing_extensions import TypedDict

class D(TypedDict):
    x: int

d: D
reveal_type(d.keys())
reveal_type(d.items())
reveal_type(d.values())

Output:

7: note: Revealed type is 'typing.AbstractSet[builtins.str*]'
8: note: Revealed type is 'typing.AbstractSet[Tuple[builtins.str*, builtins.object*]]'
9: note: Revealed type is 'typing.ValuesView[builtins.object*]'

Expected output:

7: note: Revealed type is 'typing.KeysView[builtins.str*]'
8: note: Revealed type is 'typing.ItemsView[builtins.str*, builtins.object*]'
9: note: Revealed type is 'typing.ValuesView[builtins.object*]'
@JukkaL
Copy link
Contributor

JukkaL commented Nov 21, 2019

This can actually be implemented by modifying the typeshed stub for typing (look for _TypedDict). Feel free to send a typeshed PR or create a typeshed issue.

@JukkaL JukkaL closed this as completed Nov 21, 2019
@ilevkivskyi
Copy link
Member

@JukkaL GitHub now supports direct transfer of issues between repos, I think it makes sense to just move it to typeshed.

@ilevkivskyi ilevkivskyi reopened this Nov 21, 2019
@ilevkivskyi ilevkivskyi transferred this issue from python/mypy Nov 21, 2019
hauntsaninja pushed a commit to hauntsaninja/typeshed that referenced this issue Dec 6, 2019
hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Dec 8, 2019
The signature of TypedDict's keys, values, items will be updated in
typeshed in:
python/typeshed#3529

The relevant issue is:
python/typeshed#3473
hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Dec 8, 2019
The signature of TypedDict's keys, values, items will be updated in
typeshed in:
python/typeshed#3529

The relevant issue is:
python/typeshed#3473

That PR fails testTypedDictMappingMethods
https://travis-ci.org/python/typeshed/builds/621439570

Tested by using my patched version of typeshed:
ln -sf ~/typeshed mypy/typeshed
pytest -n0 -k testTypedDictMappingMethods
JelleZijlstra pushed a commit that referenced this issue Mar 14, 2020
JelleZijlstra pushed a commit to python/mypy that referenced this issue Mar 14, 2020
The signature of TypedDict's keys, values, items will be updated in
typeshed in:
python/typeshed#3529

The relevant issue is:
python/typeshed#3473

That PR fails testTypedDictMappingMethods
https://travis-ci.org/python/typeshed/builds/621439570

Tested by using my patched version of typeshed:
ln -sf ~/typeshed mypy/typeshed
pytest -n0 -k testTypedDictMappingMethods

Co-authored-by: hauntsaninja <>
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 a pull request may close this issue.

3 participants