From: Federico Caselli Date: Fri, 8 Sep 2023 20:05:33 +0000 (+0200) Subject: more covariant typing tests X-Git-Tag: rel_2_0_21~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8503dc2e948908199cd8ba4e6b1d1ddcf92f4020;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git more covariant typing tests Change-Id: Ib469e4807ac3eb2181b8083e8ef5772636a48a88 --- diff --git a/test/typing/plain_files/orm/mapped_covariant.py b/test/typing/plain_files/orm/mapped_covariant.py index 58cc1ab6c2..1a17ee3848 100644 --- a/test/typing/plain_files/orm/mapped_covariant.py +++ b/test/typing/plain_files/orm/mapped_covariant.py @@ -1,13 +1,17 @@ """Tests Mapped covariance.""" +from datetime import datetime from typing import Protocol +from typing import Union from sqlalchemy import ForeignKey +from sqlalchemy import func +from sqlalchemy import Nullable from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped from sqlalchemy.orm import mapped_column from sqlalchemy.orm import relationship - +from sqlalchemy.sql.elements import SQLCoreOperations # Protocols @@ -51,3 +55,18 @@ class Child(Base): assert get_parent_name(Child(parent=Parent(name="foo"))) == "foo" + +# other test + + +class NullableModel(DeclarativeBase): + not_null: Mapped[datetime] + nullable: Mapped[Union[datetime, None]] + + +test = NullableModel() +test.not_null = func.now() +test.nullable = func.now() + +nullable_now: SQLCoreOperations[Union[datetime, None]] = Nullable(func.now()) +test.nullable = Nullable(func.now())