From: Mike Bayer Date: Tue, 14 Feb 2023 14:09:15 +0000 (-0500) Subject: test dataclasses.KW_ONLY X-Git-Tag: rel_2_0_4~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05eb969a778121ecab621652400904a8983749e9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git test dataclasses.KW_ONLY had no test support for this, seems to work. gets grabbed in annotations and applied correctly. Change-Id: I2cd7ad7b376f38f945d2007b316a1316271f9a0f --- diff --git a/test/orm/declarative/test_dc_transforms.py b/test/orm/declarative/test_dc_transforms.py index 0bf601455f..9b7c72778b 100644 --- a/test/orm/declarative/test_dc_transforms.py +++ b/test/orm/declarative/test_dc_transforms.py @@ -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"""