]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
test dataclasses.KW_ONLY
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Feb 2023 14:09:15 +0000 (09:09 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Feb 2023 15:43:33 +0000 (10:43 -0500)
had no test support for this, seems to work.  gets
grabbed in annotations and applied correctly.

Change-Id: I2cd7ad7b376f38f945d2007b316a1316271f9a0f

test/orm/declarative/test_dc_transforms.py

index 0bf601455f24f6fec0d7230fe9235a4ffe74df0c..9b7c72778b3a0cde4f2812018b9f278fd1d07090 100644 (file)
@@ -593,8 +593,8 @@ class DCTransformsTest(AssertsCompiledSQL, fixtures.TestBase):
         a2 = A(id=1, data="foo")
         eq_(a1, a2)
 
-    @testing.only_if(lambda: compat.py310, "python 3.10 is required")
-    def test_kw_only(self, dc_decl_base: Type[MappedAsDataclass]):
+    @testing.requires.python310
+    def test_kw_only_attribute(self, dc_decl_base: Type[MappedAsDataclass]):
         class A(dc_decl_base):
             __tablename__ = "a"
 
@@ -605,6 +605,24 @@ class DCTransformsTest(AssertsCompiledSQL, fixtures.TestBase):
         eq_(fas.args, ["self", "id"])
         eq_(fas.kwonlyargs, ["data"])
 
+    @testing.requires.python310
+    def test_kw_only_dataclass_constant(
+        self, dc_decl_base: Type[MappedAsDataclass]
+    ):
+        class Mixin(MappedAsDataclass):
+            a: Mapped[int] = mapped_column(primary_key=True)
+            b: Mapped[int] = mapped_column(default=1)
+
+        class Child(Mixin, dc_decl_base):
+
+            __tablename__ = "child"
+
+            _: dataclasses.KW_ONLY
+            c: Mapped[int]
+
+        c1 = Child(1, c=5)
+        eq_(c1, Child(a=1, b=1, c=5))
+
     def test_mapped_column_overrides(self, dc_decl_base):
         """test #8688"""