summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-06-27 12:56:27 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-06-28 13:36:06 -0400
commit5950a9d05f1cc123009223baa1915cc15f3340a7 (patch)
treec8468c6724b6832d08b483f463005884ad3bacdb /lib/sqlalchemy/testing
parentf19e50ab75cfc904acef31434c92542f3ab50d61 (diff)
downloadsqlalchemy-5950a9d05f1cc123009223baa1915cc15f3340a7.tar.gz
merge column args from Annotated left side
because we are forced by pep-681 to use the argument "default", we need a way to have client Column default separate from a dataclasses level default. Also, pep-681 does not support deriving the descriptor function from Annotated, so allow a brief right side mapped_column() to be present that will have more column-centric arguments from the left side Annotated to be merged. Change-Id: I039be1628d498486ba013b2798e1392ed1cd7f9f
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/schema.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py
index 46cbf4759..6a13fc905 100644
--- a/lib/sqlalchemy/testing/schema.py
+++ b/lib/sqlalchemy/testing/schema.py
@@ -15,9 +15,9 @@ from . import exclusions
from .. import event
from .. import schema
from .. import types as sqltypes
+from ..orm import mapped_column as _orm_mapped_column
from ..util import OrderedDict
-
__all__ = ["Table", "Column"]
table_options = {}
@@ -60,15 +60,31 @@ def Table(*args, **kw) -> schema.Table:
return schema.Table(*args, **kw)
+def mapped_column(*args, **kw):
+ """An orm.mapped_column wrapper/hook for dialect-specific tweaks."""
+
+ return _schema_column(_orm_mapped_column, args, kw)
+
+
def Column(*args, **kw):
"""A schema.Column wrapper/hook for dialect-specific tweaks."""
+ return _schema_column(schema.Column, args, kw)
+
+
+def _schema_column(factory, args, kw):
test_opts = {k: kw.pop(k) for k in list(kw) if k.startswith("test_")}
if not config.requirements.foreign_key_ddl.enabled_for_config(config):
args = [arg for arg in args if not isinstance(arg, schema.ForeignKey)]
- col = schema.Column(*args, **kw)
+ construct = factory(*args, **kw)
+
+ if factory is schema.Column:
+ col = construct
+ else:
+ col = construct.column
+
if test_opts.get("test_needs_autoincrement", False) and kw.get(
"primary_key", False
):
@@ -94,7 +110,7 @@ def Column(*args, **kw):
)
event.listen(col, "after_parent_attach", add_seq, propagate=True)
- return col
+ return construct
class eq_type_affinity: