]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix `RowMapping`'s `Mapping` type to reflect that it supports `Column`s or strings
authorAndy Freeland <andy@andyfreeland.net>
Thu, 20 Apr 2023 17:41:39 +0000 (13:41 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 20 Apr 2023 18:55:21 +0000 (20:55 +0200)
commitc1125288e3c413d868070995b308085d2ddf402e
treecb8e1e04ed56a67d7ddd9bd19c2e727206fa95c1
parentfc2bcead435a9bf0a2de8e9b15a1bd835f9d7fe4
Fix `RowMapping`'s `Mapping` type to reflect that it supports `Column`s or strings

### Description

I ran into this originally in sqlalchemy2-stubs: https://github.com/sqlalchemy/sqlalchemy2-stubs/pull/251, where `RowMapping` only supported string keys according to the type hints. I ran into a similar issue here upgrading our application where because `RowMapping` subclassed `Mapping[str, Any]`, `Row._mapping.get()` would fail to typecheck when used with `Column` objects.

This patch adds a test to verify that `Row._mapping.get()` continues to work with both strings and `Column`s, though it doesn't look like mypy checks types in the tests.

Fixes #9644.

### 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 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: #9643
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9643
Pull-request-sha: 6c33fe534cf457d6b5c73f4830a64880830f0f56

Change-Id: I1009c6defff109d73f13a9e8c51641009e6a79e2
doc/build/changelog/unreleased_20/9644.rst [new file with mode: 0644]
lib/sqlalchemy/engine/row.py
test/ext/mypy/plain_files/typed_results.py
test/sql/test_resultset.py