Skip to content
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

dict() should support anything with .keys() and __getitem__ #4409

Closed
Akuli opened this issue Aug 7, 2020 · 1 comment · Fixed by #4470
Closed

dict() should support anything with .keys() and __getitem__ #4409

Akuli opened this issue Aug 7, 2020 · 1 comment · Fixed by #4470
Labels
stubs: false positive Type checkers report false errors

Comments

@Akuli
Copy link
Collaborator

Akuli commented Aug 7, 2020

from typing import List
class Foo:
    def keys(self) -> List[str]:
        return ['a', 'b', 'c']
    def __getitem__(self, key: str) -> str:
        return f'value of {key}'
print(dict(Foo()))   # {'a': 'value of a', 'b': 'value of b', 'c': 'value of c'}

works at runtime but fails type check

tkinter widgets are like this, they aren't Mapping but they have .keys() and __getitem__

@Akuli Akuli changed the title dict() should anything with .keys() and __getitem__ dict() should support anything with .keys() and __getitem__ Aug 7, 2020
@srittau
Copy link
Collaborator

srittau commented Aug 7, 2020

Sounds reasonable. See also #3576 and #4325.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants