]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix type hint of `key` on `Visitable.__class_getitem__()`
authorJordan Macdonald <macdjord@gmail.com>
Wed, 16 Aug 2023 15:00:59 +0000 (11:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Aug 2023 02:29:03 +0000 (22:29 -0400)
Fixed the type annotation for ``__class_getitem__()`` as applied to the
``Visitable`` class at the base of expression constructs to accept ``Any``
for a key, rather than ``str``, which helps with some IDEs such as PyCharm
when attempting to write typing annotations for SQL constructs which
include generic selectors.  Pull request courtesy Jordan Macdonald.

Fixes: #9878
Closes: #9881
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9881
Pull-request-sha: 5aefaaf1065d1f946137a8b2f5be0767856cf9b0

Change-Id: I956e6d41142c50d870a142c3e99567a7ed2f7114

doc/build/changelog/unreleased_20/9878.rst [new file with mode: 0644]
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/sql/visitors.py

diff --git a/doc/build/changelog/unreleased_20/9878.rst b/doc/build/changelog/unreleased_20/9878.rst
new file mode 100644 (file)
index 0000000..0b6901e
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+    :tags: bug, typing
+    :tickets: 9878
+
+    Fixed the type annotation for ``__class_getitem__()`` as applied to the
+    ``Visitable`` class at the base of expression constructs to accept ``Any``
+    for a key, rather than ``str``, which helps with some IDEs such as PyCharm
+    when attempting to write typing annotations for SQL constructs which
+    include generic selectors.  Pull request courtesy Jordan Macdonald.
+
index e6b67b326c32b9c752dc043911c4656a1a1d5ae2..1b378f3c8d7f0ba46bd2bc89244fa7eb627edcc1 100644 (file)
@@ -1556,7 +1556,7 @@ class registry:
 
         if hasattr(cls, "__class_getitem__"):
 
-            def __class_getitem__(cls: Type[_T], key: str) -> Type[_T]:
+            def __class_getitem__(cls: Type[_T], key: Any) -> Type[_T]:
                 # allow generic classes in py3.9+
                 return cls
 
index 69dc6a827c3b31c5e959326c61a854454c49dc4f..8020181a2999f80397774786112e5979613b8986 100644 (file)
@@ -146,7 +146,7 @@ class Visitable:
             cls._original_compiler_dispatch
         ) = _compiler_dispatch
 
-    def __class_getitem__(cls, key: str) -> Any:
+    def __class_getitem__(cls, key: Any) -> Any:
         # allow generic classes in py3.9+
         return cls