summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/decl_base.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2022-11-26 19:24:49 +0100
committerFederico Caselli <cfederico87@gmail.com>2022-11-26 19:25:37 +0100
commit25c2b7dd105a6622eff2c7631d3c2d6eb978dc1f (patch)
tree46ae527de593ddcbfcf115ca7d61edad9aa083b5 /lib/sqlalchemy/orm/decl_base.py
parent34e29f7b225cf1305e151af9d03ef95f42a9dbcc (diff)
downloadsqlalchemy-25c2b7dd105a6622eff2c7631d3c2d6eb978dc1f.tar.gz
Add new script to sync test files adding future annotation
Create a new test file test_tm_future_annotations_sync.py that's obtained from test_tm_future_annotations.py by using the new script sync_test_files. This files includes the ``from __future__ import annotations`` It also turns out we had some bugs in there and we can also support some additional typing things Change-Id: Iac005df206d45a55345d9d88d67a80ce799d449f
Diffstat (limited to 'lib/sqlalchemy/orm/decl_base.py')
-rw-r--r--lib/sqlalchemy/orm/decl_base.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py
index 268a1d57a..c23ea0311 100644
--- a/lib/sqlalchemy/orm/decl_base.py
+++ b/lib/sqlalchemy/orm/decl_base.py
@@ -64,6 +64,8 @@ from ..sql.schema import Column
from ..sql.schema import Table
from ..util import topological
from ..util.typing import _AnnotationScanType
+from ..util.typing import de_stringify_annotation
+from ..util.typing import is_fwd_ref
from ..util.typing import Protocol
from ..util.typing import TypedDict
from ..util.typing import typing_get_args
@@ -1120,6 +1122,15 @@ class _ClassScanMapperConfig(_MapperConfig):
if attr_value is None:
for elem in typing_get_args(extracted_mapped_annotation):
+ if isinstance(elem, str) or is_fwd_ref(
+ elem, check_generic=True
+ ):
+ elem = de_stringify_annotation(
+ self.cls,
+ elem,
+ originating_class.__module__,
+ include_generic=True,
+ )
# look in Annotated[...] for an ORM construct,
# such as Annotated[int, mapped_column(primary_key=True)]
if isinstance(elem, _IntrospectsAnnotations):