diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 1752a4dc1ab..2eaf0bcde77 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -185,7 +185,7 @@ def proxy_set(self) -> FrozenSet[ColumnElement[Any]]: raise NotImplementedError() @classmethod - def _create_singleton(cls): + def _create_singleton(cls) -> None: obj = object.__new__(cls) obj.__init__() # type: ignore diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index a416b6ac096..078ce2bad72 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -4,7 +4,6 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php -# mypy: allow-untyped-defs, allow-untyped-calls """Core SQL expression elements, including :class:`_expression.ClauseElement`, :class:`_expression.ColumnElement`, and derived classes. @@ -80,11 +79,16 @@ from ..util.typing import Self if typing.TYPE_CHECKING: + from re import Match + from typing import NoReturn + from ._typing import _ColumnExpressionArgument from ._typing import _ColumnExpressionOrStrLabelArgument from ._typing import _InfoType from ._typing import _PropagateAttrsType from ._typing import _TypeEngineArgument + from .annotation import SupportsAnnotations + from .base import _EntityNamespace from .cache_key import _CacheKeyTraversalType from .cache_key import CacheKey from .compiler import Compiled @@ -100,10 +104,14 @@ from .selectable import FromClause from .selectable import NamedFromClause from .selectable import TextualSelect + from .sqltypes import Boolean + from .sqltypes import NullType + from .sqltypes import String from .sqltypes import TupleType from .type_api import TypeEngine from .visitors import _CloneCallableType from .visitors import _TraverseInternalsType + from .visitors import anon_map from ..engine import Connection from ..engine import Dialect from ..engine import Engine @@ -408,7 +416,11 @@ def _clone(self, **kw: Any) -> Self: c._is_clone_of = cc if cc is not None else self return c - def _negate_in_binary(self, negated_op, original_op): + def _negate_in_binary( + self, + negated_op: OperatorType, + original_op: OperatorType, + ) -> Self: """a hook to allow the right side of a binary expression to respond to a negation of the binary expression. @@ -417,7 +429,7 @@ def _negate_in_binary(self, negated_op, original_op): """ return self - def _with_binary_element_type(self, type_): + def _with_binary_element_type(self, type_: Any) -> Any: """in the context of binary expression, convert the type of this object to the one given. @@ -427,7 +439,7 @@ def _with_binary_element_type(self, type_): return self @property - def _constructor(self): + def _constructor(self) -> Any: """return the 'constructor' for this ClauseElement. This is for the purposes for creating a new object of @@ -439,7 +451,7 @@ def _constructor(self): return self.__class__ @HasMemoized.memoized_attribute - def _cloned_set(self): + def _cloned_set(self) -> Set[ClauseElement]: """Return the set consisting all cloned ancestors of this ClauseElement. @@ -462,13 +474,13 @@ def _cloned_set(self): return s @property - def entity_namespace(self): + def entity_namespace(self) -> Union[_EntityNamespace, NoReturn]: raise AttributeError( "This SQL expression has no entity namespace " "with which to filter from." ) - def __getstate__(self): + def __getstate__(self) -> Dict[str, Any]: d = self.__dict__.copy() d.pop("_is_clone_of", None) d.pop("_generate_cache_key", None) @@ -680,7 +692,7 @@ def _compile_w_cache( return compiled_sql, extracted_params, cache_hit - def __invert__(self): + def __invert__(self) -> Union[operators.Operators, ClauseElement]: # undocumented element currently used by the ORM for # relationship.contains() if hasattr(self, "negation_clause"): @@ -693,10 +705,10 @@ def _negate(self) -> ClauseElement: assert isinstance(grouped, ColumnElement) return UnaryExpression(grouped, operator=operators.inv) - def __bool__(self): + def __bool__(self) -> bool: raise TypeError("Boolean value of this clause is not defined") - def __repr__(self): + def __repr__(self) -> str: friendly = self.description if friendly is None: return object.__repr__(self) @@ -1365,7 +1377,7 @@ def _non_anon_label(self) -> Optional[str]: """ return getattr(self, "name", None) - _render_label_in_columns_clause = True + _render_label_in_columns_clause: bool = True """A flag used by select._columns_plus_names that helps to determine we are actually going to render in terms of "SELECT AS