Skip to content

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

Open

Description

@NiklasRosenstein

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions