summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/base.py')
-rw-r--r--lib/sqlalchemy/sql/base.py40
1 files changed, 16 insertions, 24 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py
index 96ebc7824..1752a4dc1 100644
--- a/lib/sqlalchemy/sql/base.py
+++ b/lib/sqlalchemy/sql/base.py
@@ -134,6 +134,10 @@ def _is_has_entity_namespace(element: Any) -> TypeGuard[_HasEntityNamespace]:
return hasattr(element, "entity_namespace")
+# Remove when https://github.com/python/mypy/issues/14640 will be fixed
+_Self = TypeVar("_Self", bound=Any)
+
+
class Immutable:
"""mark a ClauseElement as 'immutable' when expressions are cloned.
@@ -157,7 +161,7 @@ class Immutable:
def params(self, *optionaldict, **kwargs):
raise NotImplementedError("Immutable objects do not support copying")
- def _clone(self: Self, **kw: Any) -> Self:
+ def _clone(self: _Self, **kw: Any) -> _Self:
return self
def _copy_internals(
@@ -222,7 +226,7 @@ _SelfGenerativeType = TypeVar("_SelfGenerativeType", bound="_GenerativeType")
class _GenerativeType(compat_typing.Protocol):
- def _generate(self: _SelfGenerativeType) -> _SelfGenerativeType:
+ def _generate(self) -> Self:
...
@@ -692,14 +696,11 @@ class CompileState:
return decorate
-SelfGenerative = TypeVar("SelfGenerative", bound="Generative")
-
-
class Generative(HasMemoized):
"""Provide a method-chaining pattern in conjunction with the
@_generative decorator."""
- def _generate(self: SelfGenerative) -> SelfGenerative:
+ def _generate(self) -> Self:
skip = self._memoized_keys
cls = self.__class__
s = cls.__new__(cls)
@@ -972,9 +973,6 @@ class ExecutableOption(HasCopyInternals):
return c
-SelfExecutable = TypeVar("SelfExecutable", bound="Executable")
-
-
class Executable(roles.StatementRole):
"""Mark a :class:`_expression.ClauseElement` as supporting execution.
@@ -1052,9 +1050,7 @@ class Executable(roles.StatementRole):
return self.__visit_name__
@_generative
- def options(
- self: SelfExecutable, *options: ExecutableOption
- ) -> SelfExecutable:
+ def options(self, *options: ExecutableOption) -> Self:
"""Apply options to this statement.
In the general sense, options are any kind of Python object
@@ -1090,9 +1086,7 @@ class Executable(roles.StatementRole):
return self
@_generative
- def _set_compile_options(
- self: SelfExecutable, compile_options: CacheableOptions
- ) -> SelfExecutable:
+ def _set_compile_options(self, compile_options: CacheableOptions) -> Self:
"""Assign the compile options to a new value.
:param compile_options: appropriate CacheableOptions structure
@@ -1103,9 +1097,7 @@ class Executable(roles.StatementRole):
return self
@_generative
- def _update_compile_options(
- self: SelfExecutable, options: CacheableOptions
- ) -> SelfExecutable:
+ def _update_compile_options(self, options: CacheableOptions) -> Self:
"""update the _compile_options with new keys."""
assert self._compile_options is not None
@@ -1114,10 +1106,10 @@ class Executable(roles.StatementRole):
@_generative
def _add_context_option(
- self: SelfExecutable,
+ self,
callable_: Callable[[CompileState], None],
cache_args: Any,
- ) -> SelfExecutable:
+ ) -> Self:
"""Add a context option to this statement.
These are callable functions that will
@@ -1133,7 +1125,7 @@ class Executable(roles.StatementRole):
@overload
def execution_options(
- self: SelfExecutable,
+ self,
*,
compiled_cache: Optional[CompiledCacheType] = ...,
logging_token: str = ...,
@@ -1151,15 +1143,15 @@ class Executable(roles.StatementRole):
is_delete_using: bool = ...,
is_update_from: bool = ...,
**opt: Any,
- ) -> SelfExecutable:
+ ) -> Self:
...
@overload
- def execution_options(self: SelfExecutable, **opt: Any) -> SelfExecutable:
+ def execution_options(self, **opt: Any) -> Self:
...
@_generative
- def execution_options(self: SelfExecutable, **kw: Any) -> SelfExecutable:
+ def execution_options(self, **kw: Any) -> Self:
"""Set non-SQL options for the statement which take effect during
execution.