Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved signature parsing: support for Annotated, Paramspec, NewType, TypeVarTuple #283

Merged
merged 12 commits into from Jun 16, 2022

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Jun 15, 2022

Prior to this, the presence of ParamSpecArgs or ParamSpecKwargs in a signature being parsed by builds would cause an unhashable type error.

This PR fixes this bug and adds support for extracting information from Annotated and NewType, and adds support for extrapolating from variadic tuples (e.g. Tuple[int, *Ts])

Test cases are also added for Protocol and TypeVar

Before

# `sanitized_type` is applied to types by `hydra_zen.builds` when parsing target signatures

>>> sanitized_type(Annotated[int, range(10)])
Any

>>> sanitized_type(NewType("H", str))
Any

>>> sanitized_type(Tuple[*Ts])
Tuple[Any]

>>> sanitized_type(P.args)  # error
>>> sanitized_type(P.kwargs)  # error

After

>>> sanitized_type(Annotated[int, range(10)])
int

>>> sanitized_type(NewType("H", str))
str

>>> sanitized_type(Tuple[*Ts])
Tuple[Any, ...]

>>> sanitized_type(P.args)
Any

>>> sanitized_type(P.kwargs)
Any

@rsokl rsokl added bug Something isn't working enhancement New feature or request labels Jun 15, 2022
@rsokl rsokl changed the title Add support for Annotated, Paramspec, NewType, TypeVarTuple Improved signature parsing: support for Annotated, Paramspec, NewType, TypeVarTuple Jun 15, 2022
@rsokl rsokl merged commit 2492973 into main Jun 16, 2022
@rsokl rsokl deleted the expand-type-support branch June 16, 2022 13:42
@rsokl rsokl added this to the hydra-zen 0.8.0 milestone Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant