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

Support Annotated values around None and Union types #8720

Open
jptrindade opened this issue Feb 10, 2025 · 0 comments
Open

Support Annotated values around None and Union types #8720

jptrindade opened this issue Feb 10, 2025 · 0 comments

Comments

@jptrindade
Copy link
Contributor

jptrindade commented Feb 10, 2025

At the moment we only partially support Annotated around None or Union types, the simpler and more common cases. However, we are not parsing correctly nested unions and annotated optional values.

Here are some examples that we wish to support:

 import typing
import inmanta.ast.type
from inmanta import plugins
from inmanta import ast


dsl_type: ast.type.Type = plugins.to_dsl_type(int | typing.Annotated[str | None, "some-annotation"], None, None)
# assert isinstance(dsl_type, ast.type.NullableType) # fails

dsl_type2: ast.type.Type = plugins.to_dsl_type(int | typing.Annotated[str | float, "some-annotation"], None, None)
assert isinstance(dsl_type2, ast.type.Union)
# assert len(dsl_type.types) == 3  # fails
assert isinstance(normalize_dsl_type(dsl_type2), ast.type.Union)
# assert len(normalize_dsl_type(dsl_type2).types) == 3  # fails

Slack thread: https://inmanta.slack.com/archives/CKRF0C8R3/p1738855256781129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant