Skip to content
Discussion options

You must be logged in to vote

Hi,

I don't think this is solvable out of the box without specifically catering for this use case

An option could be to trade type ignores when setting the "shortcut" type for type ignores in the model definition using something like this

if TYPE_CHECKING:

    _T_co = TypeVar("_T_co", covariant=True)

    class MappedAndString(orm.Mapped[_T_co]):
        if TYPE_CHECKING:

            def __set__(
                self,
                instance: sa.Any,
                value: SQLCoreOperations[_T_co] | _T_co | str,
            ) -> None: ...

else:
    MappedAndString = orm.Mapped

you then use it as

class User(Base):
    __tablename__ = "user_account"
    id: Mapped[int] = mapped_column(p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lelit
Comment options

lelit Feb 24, 2026
Collaborator Author

Answer selected by lelit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants