Make Mapped covariant
#10287
Closed
RomeoDespres
started this conversation in
Ideas
Replies: 1 comment 8 replies
-
|
hi - seems like this would be fine. For typing related PRs we would add your example above to likely a new file |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi friends, I've noticed that
Mappedis currently invariant with its type parameter. What would you think of making it covariant?I came accross this when trying to build protocols to represent some of my data tables. I was trying to write a protocol representing a table, and then another protocol representing another table that has the first protocol as a relationship. Complete example below.
The aim is to be able to write general helper functions (like
get_parent_name) that operate on table protocols instead of actual tables.The code above runs fine but does not type-check because of the invariance of
Mapped:With a few changes in sqlalchemy source code I've managed to make
Mappedcovariant and mypy run fine on the codebase + this example. Not sure though if there are some deeper implications. If you think it's interesting I can submit a PR and keep on discussing thereBeta Was this translation helpful? Give feedback.
All reactions