]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix typing for `hybrid_property.__set__` to properly validate setter values
authorMicah Denbraver <micah.denbraver@whatnot.com>
Wed, 20 Aug 2025 20:58:02 +0000 (16:58 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Wed, 20 Aug 2025 21:08:30 +0000 (23:08 +0200)
commit7a68e2aeffd43fc5b78df6182969e031e31043b9
treee8d83d425b5190977eb606a46148c1569a2b1191
parent9bd8f205edae4d8fab3b7d188c2c809176edbaae
Fix typing for `hybrid_property.__set__` to properly validate setter values

While iterating on some typing improvements, my colleague @seamuswn pointed out mypy wasn't catching when values with invalid types were set using a `hybrid_property` setter. I believe this is all that's needed to fix the typing.

### Description
Adjust `hybrid_property.__set__` to expect a value of the type that matches the generic's type variable.

### 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:

- [x] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
- [ ] 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: #12814
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12814
Pull-request-sha: 8a17b26aea264acf70c52de324b8ccb92b469f2d

Change-Id: Ic99ccc68a32354ef6fe013ec17242058ad2d6d63
lib/sqlalchemy/ext/hybrid.py
test/typing/plain_files/ext/hybrid/hybrid_five.py [new file with mode: 0644]
test/typing/plain_files/ext/hybrid/hybrid_two.py