Quantcast
Channel: Python type hint for classes that support __getitem__ - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Liran Funaro for Python type hint for classes that support __getitem__

$
0
0

This will work for dict and list, but not for any generic type:

from typing import Any, Mapping, Sequence, Union

def my_function(hasitems: Union[Mapping, Sequence], locator: Any) -> Any:
    return hasitems[locator]

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>