from typing import Generic
from typing import Optional
from typing import Set
+from typing import Tuple
from typing import Type
from typing import TYPE_CHECKING
from typing import TypeVar
from ..util.typing import Protocol
if typing.TYPE_CHECKING:
+ from .cache_key import CacheConst
from .type_api import TypeEngine
_T = TypeVar("_T", bound=Any)
self.python_impl = python_impl
def __eq__(self, other: Any) -> bool:
- return isinstance(other, custom_op) and other.opstring == self.opstring
+ return (
+ isinstance(other, custom_op)
+ and other._hash_key() == self._hash_key()
+ )
def __hash__(self) -> int:
- return id(self)
+ return hash(self._hash_key())
+
+ def _hash_key(self) -> Union[CacheConst, Tuple[Any, ...]]:
+ return (
+ self.__class__,
+ self.opstring,
+ self.precedence,
+ self.is_comparison,
+ self.natural_self_precedent,
+ self.eager_grouping,
+ self.return_type._static_cache_key if self.return_type else None,
+ )
def __call__(
self,
def visit_operator(
self, attrname, left_parent, left, right_parent, right, **kw
):
- return left is right
+ return left == right
def visit_type(
self, attrname, left_parent, left, right_parent, right, **kw
from sqlalchemy import extract
from sqlalchemy import Float
from sqlalchemy import Integer
+from sqlalchemy import literal
from sqlalchemy import literal_column
from sqlalchemy import MetaData
from sqlalchemy import or_
bindparam("bar", type_=String)
),
),
+ lambda: (
+ literal(1).op("+")(literal(1)),
+ literal(1).op("-")(literal(1)),
+ column("q").op("-")(literal(1)),
+ UnaryExpression(table_a.c.b, modifier=operators.neg),
+ UnaryExpression(table_a.c.b, modifier=operators.desc_op),
+ UnaryExpression(table_a.c.b, modifier=operators.custom_op("!")),
+ UnaryExpression(table_a.c.b, modifier=operators.custom_op("~")),
+ ),
lambda: (
column("q") == column("x"),
column("q") == column("y"),
(column("z") == column("x")).self_group(),
(column("q") == column("x")).self_group(),
column("z") + column("x"),
+ column("z").op("foo")(column("x")),
+ column("z").op("foo")(literal(1)),
+ column("z").op("bar")(column("x")),
column("z") - column("x"),
column("x") - column("z"),
column("z") > column("x"),