-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
InstrumentedAttribute should also be covariant on its input type #11112
Labels
PRs (with tests!) welcome
a fix or feature which is appropriate to be implemented by volunteers
typing
pep -484 typing issues. independent of "mypy"
Comments
ejlangev
added
requires triage
New issue that requires categorization
typing
pep -484 typing issues. independent of "mypy"
labels
Mar 6, 2024
zzzeek
added
PRs (with tests!) welcome
a fix or feature which is appropriate to be implemented by volunteers
and removed
requires triage
New issue that requires categorization
labels
Mar 6, 2024
feel free to send a PR, including a test as you see in the change you refer to. I'd put it in the same mapped_covariant file for succinctness |
Will do! |
3 tasks
Filed: #11113 |
sqlalchemy-bot
pushed a commit
that referenced
this issue
Mar 13, 2024
<!-- Provide a general summary of your proposed changes in the Title field above --> Allows mapped relationships to use covariant types which makes it possible to define methods that operate on relationships in a typesafe way ### Description See: #11112 for a more in depth explanation. Just changed the type parameter in `InstrumentedAttribute` from `_T` to `_T_co`. ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #11113 Pull-request: #11113 Pull-request-sha: 3c100f2 Change-Id: Iff715c24f1556d5604dcd33661a0ee7232b9404b
sqlalchemy-bot
pushed a commit
that referenced
this issue
Mar 13, 2024
<!-- Provide a general summary of your proposed changes in the Title field above --> Allows mapped relationships to use covariant types which makes it possible to define methods that operate on relationships in a typesafe way ### Description See: #11112 for a more in depth explanation. Just changed the type parameter in `InstrumentedAttribute` from `_T` to `_T_co`. ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #11113 Pull-request: #11113 Pull-request-sha: 3c100f2 Change-Id: Iff715c24f1556d5604dcd33661a0ee7232b9404b (cherry picked from commit 058e10f)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
PRs (with tests!) welcome
a fix or feature which is appropriate to be implemented by volunteers
typing
pep -484 typing issues. independent of "mypy"
Ensure stubs packages are not installed
sqlalchemy-stubs
andsqlalchemy2-stubs
are not compatible with v2)Verify if the api is typed
Describe the typing issue
InstrumentedAttribute
is defined asIn #10289, many of the types related to
Mapped
were made to be covariant which is helpful for user facing types. In my case I want to define a function that operates on relationship fields of my models generically. Roughly this:But I can't do that because the TypeVar passed into the
InstrumentedAttribute
class is not covariant. Allowing this I think should be as simple as changingclass InstrumentedAttribute(QueryableAttribute[_T]):
intoclass InstrumentedAttribute(QueryableAttribute[_T_co]):
To Reproduce
Error
Versions
Additional context
The type checker is correct here, the type definitions are (I think) unnecessarily limiting.
The text was updated successfully, but these errors were encountered: