dgilland / pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.
http://pydash.readthedocs.io
MIT License
1.28k stars 89 forks source link

Type overloading for get #212

Closed Drvanon closed 7 months ago

Drvanon commented 7 months ago

Currently the type overloading for get is interacts mostly with List types. However I frequently use it in mappings as well. e.g.

capitalized_a = py_({lower: upper for lower in "abcdefg"}).get("a").value()

However since the obj type here is at most this:

pydash.objects.get(obj: Any, path: Hashable | List[Hashable], default: Any = None) → Any

I don't get type annotations.

I would suggest the following annotation:

pydash.objects.get(obj: Mapping[T, T2], path: Hashable | List[Hashable], default: Any = None) → T2

Typing this out I am starting to realize why you might not be able to do this, since the path might be deeper than the T2. Oh well.