typing_inspect icon indicating copy to clipboard operation
typing_inspect copied to clipboard

`typing_inspect.get_args` `Annotated` metadata args

Open anders-kiaer opened this issue 4 years ago • 1 comments

Is typing_inspect.get_args expected to also return metadata args for Annotated?

Python 3.9.5:

>>> import typing
>>>
>>> A = typing.Annotated[int, "some_metadata"]
>>>
>>> typing.get_args(A)
(<class 'int'>, 'some_metadata')

Python 3.8.6:

>>> import typing_extensions  # 3.10.0.2
>>> import typing_inspect  # 0.7.1
>>> 
>>> A = typing_extensions.Annotated[int, "some_metadata"]
>>>
>>> typing_inspect.get_args(A)
(<class 'int'>,)

anders-kiaer avatar Oct 20 '21 08:10 anders-kiaer

I think it should only return the actual type argument (i.e. (int,) in this case). Also IIUC it used to work in 3.8 by accident, please feel free to submit a PR fixing this (probably by introducing some dedicated support for Annotated)

ilevkivskyi avatar Oct 25 '21 15:10 ilevkivskyi