]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Detection of PEP 604 union syntax.
authorPeter Schutt <peter.github@proton.me>
Thu, 1 Sep 2022 23:11:40 +0000 (19:11 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Thu, 1 Sep 2022 23:11:40 +0000 (19:11 -0400)
commitc3cfee5b00a40790c18d444a1ea1454aafc27889
treef6a557b289d5a4c567b70c207ec887c1bd18a08d
parentd3e0b8e750d864766148cdf1a658a601079eed46
Detection of PEP 604 union syntax.

### Description

Fixes #8478

Handle `UnionType` as arguments to `Mapped`, e.g., `Mapped[str | None]`:

- adds `utils.typing.is_optional_union()` used to detect if a column should be nullable.
- adds `"UnionType"` to `utils.typing.is_optional()` names.
- uses `get_origin()` in `utils.typing.is_origin_of()` as `UnionType` has no `__origin__` attribute.
- tests with runtime type and postponed annotations and guard the tests running with `compat.py310`.

### 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: #8479
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8479
Pull-request-sha: 12417654822272c5847e684c53677f665553ef0e

Change-Id: Ib3248043dd4a97324ac592c048385006536b2d49
lib/sqlalchemy/orm/properties.py
lib/sqlalchemy/util/typing.py
test/orm/declarative/test_typed_mapping.py