class _HybridExprCallableType(Protocol[_T_co]):
def __call__(
s, cls: Any
- ) -> Union[_HasClauseElement, SQLColumnExpression[_T_co]]:
+ ) -> Union[_HasClauseElement[_T_co], SQLColumnExpression[_T_co]]:
...
classes for usage with hybrids."""
def __init__(
- self, expression: Union[_HasClauseElement, SQLColumnExpression[_T]]
+ self, expression: Union[_HasClauseElement[_T], SQLColumnExpression[_T]]
):
self.expression = expression
def __init__(
self,
cls: Type[Any],
- expression: Union[_HasClauseElement, SQLColumnExpression[_T]],
+ expression: Union[_HasClauseElement[_T], SQLColumnExpression[_T]],
hybrid: hybrid_property[_T],
):
self.cls = cls
from typing import Any
from typing import Callable
from typing import Dict
+from typing import Generic
from typing import Iterable
from typing import Mapping
from typing import NoReturn
from .elements import SQLCoreOperations
from .elements import TextClause
from .lambdas import LambdaElement
- from .roles import ColumnsClauseRole
from .roles import FromClauseRole
from .schema import Column
from .selectable import Alias
from ..util.typing import TypeGuard
_T = TypeVar("_T", bound=Any)
+_T_co = TypeVar("_T_co", bound=Any, covariant=True)
_CE = TypeVar("_CE", bound="ColumnElement[Any]")
_CLE = TypeVar("_CLE", bound="ClauseElement")
-class _HasClauseElement(Protocol):
+class _HasClauseElement(Protocol, Generic[_T_co]):
"""indicates a class that has a __clause_element__() method"""
- def __clause_element__(self) -> ColumnsClauseRole:
+ def __clause_element__(self) -> roles.ExpressionElementRole[_T_co]:
...
roles.ColumnsClauseRole,
Literal["*", 1],
Type[Any],
- Inspectable[_HasClauseElement],
- _HasClauseElement,
+ Inspectable[_HasClauseElement[Any]],
+ _HasClauseElement[Any],
)
str,
"TextClause",
"ColumnElement[_T]",
- _HasClauseElement,
+ _HasClauseElement[_T],
roles.ExpressionElementRole[_T],
]
"SQLCoreOperations[_T]",
Literal["*", 1],
Type[_T],
- Inspectable[_HasClauseElement],
- _HasClauseElement,
+ Inspectable[_HasClauseElement[_T]],
+ _HasClauseElement[_T],
]
"""open-ended SELECT columns clause argument.
_ColumnExpressionArgument = Union[
"ColumnElement[_T]",
- _HasClauseElement,
+ _HasClauseElement[_T],
"SQLCoreOperations[_T]",
roles.ExpressionElementRole[_T],
Callable[[], "ColumnElement[_T]"],
_FromClauseArgument = Union[
roles.FromClauseRole,
Type[Any],
- Inspectable[_HasClauseElement],
- _HasClauseElement,
+ Inspectable[_HasClauseElement[Any]],
+ _HasClauseElement[Any],
]
"""A FROM clause, like we would send to select().select_from().
_DMLColumnArgument = Union[
str,
- _HasClauseElement,
+ _HasClauseElement[Any],
roles.DMLColumnRole,
"SQLCoreOperations[Any]",
]
"Alias",
"CTE",
Type[Any],
- Inspectable[_HasClauseElement],
- _HasClauseElement,
+ Inspectable[_HasClauseElement[Any]],
+ _HasClauseElement[Any],
]
_PropagateAttrsType = util.immutabledict[str, Any]
return hasattr(s, "quote")
-def is_has_clause_element(s: object) -> TypeGuard[_HasClauseElement]:
+def is_has_clause_element(s: object) -> TypeGuard[_HasClauseElement[Any]]:
return hasattr(s, "__clause_element__")