]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Add support for typing.Literal in Mapped
authorFrederik Aalund <fpa@sbtinstruments.com>
Mon, 30 Jan 2023 16:50:40 +0000 (11:50 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 1 Feb 2023 03:02:30 +0000 (22:02 -0500)
commit8e890609eb47f5a273e695154cf143af56807921
tree2b687da911107a5c4e86231a1241c5a6ee4dae3f
parenta21c715b7a89b0619db0d2d5b31617d17b25a27a
Add support for typing.Literal in Mapped

Added support for :pep:`586` ``Literal`` to be used in the
:paramref:`_orm.registry.type_annotation_map` as well as within
:class:`.Mapped` constructs. To use custom types such as these, they must
appear explicitly within the :paramref:`_orm.registry.type_annotation_map`
to be mapped.  Pull request courtesy Frederik Aalund.

As part of this change, the support for :class:`.sqltypes.Enum` in the
:paramref:`_orm.registry.type_annotation_map` has been expanded to include
support for ``Literal[]`` types consisting of string values to be used,
in addition to ``enum.Enum`` datatypes.    If a ``Literal[]`` datatype
is used within ``Mapped[]`` that is not linked in
:paramref:`_orm.registry.type_annotation_map` to a specific datatype,
a :class:`.sqltypes.Enum` will be used by default.

Fixed issue involving the use of :class:`.sqltypes.Enum` within the
:paramref:`_orm.registry.type_annotation_map` where the
:paramref:`_sqltypes.Enum.native_enum` parameter would not be correctly
copied to the mapped column datatype, if it were overridden
as stated in the documentation to set this parameter to False.

Fixes: #9187
Fixes: #9200
Closes: #9191
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9191
Pull-request-sha: 7d13f705307bf62560fc831f6f049a425d411374

Change-Id: Ife3ba2655f4897f806d6a9cf0041c69fd4f39e9d
doc/build/changelog/unreleased_20/9187.rst [new file with mode: 0644]
doc/build/orm/declarative_tables.rst
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/decl_base.py
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/util/typing.py
test/orm/declarative/test_tm_future_annotations_sync.py
test/orm/declarative/test_typed_mapping.py