Skip to content

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

Description

@Akuli
fromtypingimportListclassFoo:
defkeys(self) ->List[str]:
return ['a', 'b', 'c']
def__getitem__(self, key: str) ->str:
returnf'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__

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions