I didn't implement any good helper function because I couldn't figure out the idiomatic way to traverse type hints at runtime. It would be very easy to add a "get_extras(t: typing.<Type>) -> Tuple[Any, ...]" function. Would that work? On Mon, May 27, 2019 at 10:20 PM Jakub Stasiak <jakub@stasiak.at> wrote:
On 27 May 2019, at 22:44, Till <till.varoquaux@gmail.com> wrote:
Thanks to Ivan and Jakub I was able to land a (python 3.7 and up) implementation in typing_extension. If you get the library directly from GitHub you can try it out and give your feedback. Till
Happy to help. I just modified Injector locally to use this and everything works as expected – nicely done!
One thing that I’m curious about – what’s the recommended way to see if we’re dealing with Annotated-wrapped type or just a type at runtime? This is what I did:
from typing_extensions import _Annotated
things = get_type_hints(…, include_extras=True) for k, v in things.items(): if isinstance(v, _Annotated): # special logic here
Best, Jakub