--- /dev/null
+.. change::
+ :tags: usecase, typing
+ :tickets: 10054
+
+ Improved typing when using standalone operator functions from
+ ``sqlalchemy.sql.operators`` such as ``sqlalchemy.sql.operators.eq``.
def operate(
self, op: OperatorType, *other: Any, **kwargs: Any
) -> ColumnElement[Any]:
- return op(self.comparator, *other, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(self.comparator, *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def reverse_operate(
self, op: OperatorType, other: Any, **kwargs: Any
) -> ColumnElement[Any]:
- return op(other, self.comparator, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(other, self.comparator, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def hasparent(
self, state: InstanceState[Any], optimistic: bool = False
def operate(
self, op: OperatorType, *other: Any, **kwargs: Any
) -> ColumnElement[Any]:
- return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def reverse_operate(
self, op: OperatorType, other: Any, **kwargs: Any
) -> ColumnElement[Any]:
col = self.__clause_element__()
- return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def __str__(self) -> str:
if not self.parent or not self.key:
def operate(
self, op: OperatorType, *other: Any, **kwargs: Any
) -> ColumnElement[Any]:
- return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def reverse_operate(
self, op: OperatorType, other: Any, **kwargs: Any
) -> ColumnElement[Any]:
col = self.__clause_element__()
- return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def found_in_pep593_annotated(self) -> Any:
# return a blank mapped_column(). This mapped_column()'s
*other: Any,
**kwargs: Any,
) -> ColumnElement[Any]:
- return op(self.comparator, *other, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(self.comparator, *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def reverse_operate(
self, op: operators.OperatorType, other: Any, **kwargs: Any
) -> ColumnElement[Any]:
- return op(other, self.comparator, **kwargs) # type: ignore[return-value] # noqa: E501
+ return op(other, self.comparator, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501
def _bind_param(
self,
from typing import Dict
from typing import Generic
from typing import Optional
+from typing import overload
from typing import Set
from typing import Tuple
from typing import Type
from ..util.typing import Protocol
if typing.TYPE_CHECKING:
+ from ._typing import ColumnExpressionArgument
from .cache_key import CacheConst
+ from .elements import ColumnElement
from .type_api import TypeEngine
_T = TypeVar("_T", bound=Any)
__name__: str
+ @overload
+ def __call__(
+ self,
+ left: ColumnExpressionArgument[Any],
+ right: Optional[Any] = None,
+ *other: Any,
+ **kwargs: Any,
+ ) -> ColumnElement[Any]:
+ ...
+
+ @overload
def __call__(
self,
left: Operators,
) -> Operators:
...
+ def __call__(
+ self,
+ left: Any,
+ right: Optional[Any] = None,
+ *other: Any,
+ **kwargs: Any,
+ ) -> Operators:
+ ...
+
add = cast(OperatorType, _uncast_add)
and_ = cast(OperatorType, _uncast_and_)
self.return_type._static_cache_key if self.return_type else None,
)
+ @overload
+ def __call__(
+ self,
+ left: ColumnExpressionArgument[Any],
+ right: Optional[Any] = None,
+ *other: Any,
+ **kwargs: Any,
+ ) -> ColumnElement[Any]:
+ ...
+
+ @overload
def __call__(
self,
left: Operators,
right: Optional[Any] = None,
*other: Any,
**kwargs: Any,
+ ) -> Operators:
+ ...
+
+ def __call__(
+ self,
+ left: Any,
+ right: Optional[Any] = None,
+ *other: Any,
+ **kwargs: Any,
) -> Operators:
if hasattr(left, "__sa_operate__"):
- return left.operate(self, right, *other, **kwargs)
+ return left.operate(self, right, *other, **kwargs) # type: ignore
elif self.python_impl:
return self.python_impl(left, right, *other, **kwargs) # type: ignore # noqa: E501
else:
from sqlalchemy import column
from sqlalchemy import ColumnElement
from sqlalchemy import Integer
+from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
+from sqlalchemy.sql import operators
class Base(DeclarativeBase):
op_c: "ColumnElement[str]" = col.op("&", return_type=String)("1")
op_d: "ColumnElement[int]" = col.op("&", return_type=BigInteger)("1")
op_e: "ColumnElement[bool]" = col.bool_op("&")("1")
+
+
+# op functions
+t1 = operators.eq(A.id, 1)
+select().where(t1)