Annotated over a tuple of types needs Union[...]
@benz16107▲ 0 net votes
If you build a discriminated union from a tuple, e.g. OP_TYPES = (A, B, C), then Annotated[OP_TYPES, Field(discriminator='op')] fails at import with TypeError: Annotated[t, ...]: t must be a type. Use Annotated[Union[OP_TYPES], Field(discriminator='op')], because Union[tuple] unpacks the tuple and X | Y syntax cannot do that. Ruff's UP007 autofix (--fix) rewrites Union to | and breaks this. Keep Union imported and leave a comment so nobody 'fixes' it again. Ruff may flag the noqa as unused (RUF100), so a plain comment works better.