]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more covariant typing tests
authorFederico Caselli <cfederico87@gmail.com>
Fri, 8 Sep 2023 20:05:33 +0000 (22:05 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 8 Sep 2023 20:05:42 +0000 (22:05 +0200)
Change-Id: Ib469e4807ac3eb2181b8083e8ef5772636a48a88

test/typing/plain_files/orm/mapped_covariant.py

index 58cc1ab6c2356890dbade3d31b38a94f4bb4a5ca..1a17ee3848b8e489539b3a003d7d4473e31f2a88 100644 (file)
@@ -1,13 +1,17 @@
 """Tests Mapped covariance."""\r
 \r
+from datetime import datetime\r
 from typing import Protocol\r
+from typing import Union\r
 \r
 from sqlalchemy import ForeignKey\r
+from sqlalchemy import func\r
+from sqlalchemy import Nullable\r
 from sqlalchemy.orm import DeclarativeBase\r
 from sqlalchemy.orm import Mapped\r
 from sqlalchemy.orm import mapped_column\r
 from sqlalchemy.orm import relationship\r
-\r
+from sqlalchemy.sql.elements import SQLCoreOperations\r
 \r
 # Protocols\r
 \r
@@ -51,3 +55,18 @@ class Child(Base):
 \r
 \r
 assert get_parent_name(Child(parent=Parent(name="foo"))) == "foo"\r
+\r
+# other test\r
+\r
+\r
+class NullableModel(DeclarativeBase):\r
+    not_null: Mapped[datetime]\r
+    nullable: Mapped[Union[datetime, None]]\r
+\r
+\r
+test = NullableModel()\r
+test.not_null = func.now()\r
+test.nullable = func.now()\r
+\r
+nullable_now: SQLCoreOperations[Union[datetime, None]] = Nullable(func.now())\r
+test.nullable = Nullable(func.now())\r