summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2023-01-31 22:08:07 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2023-01-31 22:08:07 +0000
commitf8e4ed046dac730096034476218896046cb81b56 (patch)
treea338ffd9b50a9f4644519499c6835676b60434f8 /lib/sqlalchemy/sql
parent8b41e839699c52e908ba3fff5b572ca82511a85f (diff)
parentceb0eb44ce2da4b7161b7a115525ed6bccf08cbc (diff)
downloadsqlalchemy-f8e4ed046dac730096034476218896046cb81b56.tar.gz
Merge "Fixed typing of limit, offset and fetch to allow ``None``." into main
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/_typing.py2
-rw-r--r--lib/sqlalchemy/sql/selectable.py11
-rw-r--r--lib/sqlalchemy/sql/util.py12
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/_typing.py b/lib/sqlalchemy/sql/_typing.py
index 5c1a501e4..e1190f7dd 100644
--- a/lib/sqlalchemy/sql/_typing.py
+++ b/lib/sqlalchemy/sql/_typing.py
@@ -260,6 +260,8 @@ _TypeEngineArgument = Union[Type["TypeEngine[_T]"], "TypeEngine[_T]"]
_EquivalentColumnMap = Dict["ColumnElement[Any]", Set["ColumnElement[Any]"]]
+_LimitOffsetType = Union[int, _ColumnExpressionArgument[int], None]
+
if TYPE_CHECKING:
def is_sql_compiler(c: Compiled) -> TypeGuard[SQLCompiler]:
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index f43e6b43f..47cf68357 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -109,6 +109,7 @@ if TYPE_CHECKING:
from ._typing import _ColumnExpressionOrStrLabelArgument
from ._typing import _FromClauseArgument
from ._typing import _JoinTargetArgument
+ from ._typing import _LimitOffsetType
from ._typing import _MAYBE_ENTITY
from ._typing import _NOT_ENTITY
from ._typing import _OnClauseArgument
@@ -3955,7 +3956,7 @@ class GenerativeSelect(SelectBase, Generative):
def _offset_or_limit_clause(
self,
- element: Union[int, _ColumnExpressionArgument[Any]],
+ element: _LimitOffsetType,
name: Optional[str] = None,
type_: Optional[_TypeEngineArgument[int]] = None,
) -> ColumnElement[Any]:
@@ -4041,8 +4042,7 @@ class GenerativeSelect(SelectBase, Generative):
@_generative
def limit(
- self: SelfGenerativeSelect,
- limit: Union[int, _ColumnExpressionArgument[int]],
+ self: SelfGenerativeSelect, limit: _LimitOffsetType
) -> SelfGenerativeSelect:
"""Return a new selectable with the given LIMIT criterion
applied.
@@ -4078,7 +4078,7 @@ class GenerativeSelect(SelectBase, Generative):
@_generative
def fetch(
self: SelfGenerativeSelect,
- count: Union[int, _ColumnExpressionArgument[int]],
+ count: _LimitOffsetType,
with_ties: bool = False,
percent: bool = False,
) -> SelfGenerativeSelect:
@@ -4133,8 +4133,7 @@ class GenerativeSelect(SelectBase, Generative):
@_generative
def offset(
- self: SelfGenerativeSelect,
- offset: Union[int, _ColumnExpressionArgument[int]],
+ self: SelfGenerativeSelect, offset: _LimitOffsetType
) -> SelfGenerativeSelect:
"""Return a new selectable with the given OFFSET criterion
applied.
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index a92ee9d1a..1dad9ce68 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -71,8 +71,8 @@ from ..util.typing import Literal
from ..util.typing import Protocol
if typing.TYPE_CHECKING:
- from ._typing import _ColumnExpressionArgument
from ._typing import _EquivalentColumnMap
+ from ._typing import _LimitOffsetType
from ._typing import _TypeEngineArgument
from .elements import BinaryExpression
from .elements import TextClause
@@ -1411,7 +1411,7 @@ class ColumnAdapter(ClauseAdapter):
def _offset_or_limit_clause(
- element: Union[int, _ColumnExpressionArgument[int]],
+ element: _LimitOffsetType,
name: Optional[str] = None,
type_: Optional[_TypeEngineArgument[int]] = None,
) -> ColumnElement[int]:
@@ -1427,8 +1427,8 @@ def _offset_or_limit_clause(
def _offset_or_limit_clause_asint_if_possible(
- clause: Optional[Union[int, _ColumnExpressionArgument[int]]]
-) -> Optional[Union[int, _ColumnExpressionArgument[int]]]:
+ clause: _LimitOffsetType,
+) -> _LimitOffsetType:
"""Return the offset or limit clause as a simple integer if possible,
else return the clause.
@@ -1443,8 +1443,8 @@ def _offset_or_limit_clause_asint_if_possible(
def _make_slice(
- limit_clause: Optional[Union[int, _ColumnExpressionArgument[int]]],
- offset_clause: Optional[Union[int, _ColumnExpressionArgument[int]]],
+ limit_clause: _LimitOffsetType,
+ offset_clause: _LimitOffsetType,
start: int,
stop: int,
) -> Tuple[Optional[ColumnElement[int]], Optional[ColumnElement[int]]]: