]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
refactor: Add type hints to lib.sqlalchemy.ext.compiler
authorKevin Kirsche <kevin.kirsche@one.verizon.com>
Fri, 20 Sep 2024 14:12:18 +0000 (10:12 -0400)
committerKevin Kirsche <kevin.kirsche@one.verizon.com>
Fri, 20 Sep 2024 14:12:18 +0000 (10:12 -0400)
lib/sqlalchemy/ext/compiler.py

index 01462ad0b48a6f6b4dbb6dc9948675a5ff1fb268..6f5b773747b993d050e2862560f1424a7ba531ed 100644 (file)
@@ -452,15 +452,22 @@ Example usage::
     )
 
 """
+from typing import Any
+from typing import Callable # TODO: Change to collections.abc when 3.8 support is dropped
+from typing import Type # TODO: Change to builtins.type when 3.8 support is dropped
+from typing import TypeVar
+
 from .. import exc
 from ..sql import sqltypes
 
+_F = TypeVar("_F", bound=Callable[..., Any])
+
 
-def compiles(class_, *specs):
+def compiles(class_: Type[Any], *specs: str) -> Callable[[_F], _F]:
     """Register a function as a compiler for a
     given :class:`_expression.ClauseElement` type."""
 
-    def decorate(fn):
+    def decorate(fn: _F) -> _F:
         # get an existing @compiles handler
         existing = class_.__dict__.get("_compiler_dispatcher", None)
 
@@ -505,7 +512,7 @@ def compiles(class_, *specs):
     return decorate
 
 
-def deregister(class_):
+def deregister(class_: Type[Any]) -> None:
     """Remove all custom compilers associated with a given
     :class:`_expression.ClauseElement` type.
 
@@ -517,7 +524,7 @@ def deregister(class_):
 
 
 class _dispatcher:
-    def __init__(self):
+    def __init__(self) -> None:
         self.specs = {}
 
     def __call__(self, element, compiler, **kw):