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

FakeHint is not correctly evaluated when passed to function calls inside annotation #29

Open
NiklasRosenstein opened this issue Mar 6, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@NiklasRosenstein
Copy link
Owner

NiklasRosenstein commented Mar 6, 2024

Example:

plugins: list[Annotated[Plugin, Union("<import>", discriminator_key="fqn", style=Union.FLAT)]]

Results in:

databind.core.converter.ConversionError: unsupported Union.style: FakeHint(flat, args=None)

Trace:
  In "etc/nox-server.toml"
    $: TypeHint(nox_server.config.Config)
    .server: TypeHint(nox_server.config.ServerConfig)
    .plugins: TypeHint(typing.List[typing.Annotated[nox_server.plugin.Plugin, Union(members=ImportUnionMembers(), style=FakeHint(flat, args=None), discriminator_key='fqn', nesting_key=None)]])
    [0]: TypeHint(typing.Annotated[nox_server.plugin.Plugin, Union(members=ImportUnionMembers(), style=FakeHint(flat, args=None), discriminator_key='fqn', nesting_key=None)])

A workaround is to move the annotation into a type alias that is evaluated immediately:

_DeserializablePlugin = Annotated[Plugin, Union("<import>", discriminator_key="fqn", style=Union.FLAT)]
plugins: list[_DeserializePlugin]
@NiklasRosenstein NiklasRosenstein added the bug Something isn't working label Mar 6, 2024
@NiklasRosenstein NiklasRosenstein self-assigned this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant