]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add tests and fix issues
authorKai Mueller <15907922+kasium@users.noreply.github.com>
Tue, 30 Nov 2021 14:59:33 +0000 (14:59 +0000)
committerKai Mueller <15907922+kasium@users.noreply.github.com>
Tue, 30 Nov 2021 14:59:33 +0000 (14:59 +0000)
lib/sqlalchemy/orm/decl_api.py
test/orm/declarative/test_typing_py3k.py

index 25de0fb405cc0fac1bfd5ce1fc3259941b2ff95f..b5bfb0380fc25042b68e00c1f0a1a602dc45648b 100644 (file)
@@ -809,7 +809,7 @@ class registry(object):
         class_dict["__abstract__"] = True
         if mapper:
             class_dict["__mapper_cls__"] = mapper
-        if cls.__class_getitem__:
+        if hasattr(cls, "__class_getitem__"):
             class_dict["__class_getitem__"] = cls.__class_getitem__
 
         return metaclass(name, bases, class_dict)
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96629f58abebed83189e1d54d2b32e208712307c 100644 (file)
@@ -0,0 +1,19 @@
+from typing import TypeVar, Generic, Type
+from sqlalchemy import Column, Integer
+from sqlalchemy.orm import as_declarative
+
+
+def test_class_getitem():
+    T = TypeVar("T", bound="CommonBase")
+
+    class CommonBase(Generic[T]):
+        @classmethod
+        def boring(cls: Type[T]) -> Type[T]:
+            return cls
+
+    @as_declarative()
+    class Base(CommonBase[T]):
+        pass
+
+    class Tab(Base["Tab"]):
+        a = Column(Integer, primary_key=True)