From 7b605884dd0e7569910dbd350793037d99aed612 Mon Sep 17 00:00:00 2001 From: slymit Date: Wed, 12 Jun 2024 18:48:19 +0300 Subject: [PATCH] Fix TypeError: 'type' object is not subscriptable if using python versions 3.7 or 3.8 --- sa_filters/pagination.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sa_filters/pagination.py b/sa_filters/pagination.py index 1441de5..70433ad 100644 --- a/sa_filters/pagination.py +++ b/sa_filters/pagination.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import math from collections import namedtuple +import sys from typing import Optional, Union from sqlalchemy.sql import Select @@ -9,6 +10,12 @@ from .exceptions import InvalidPage +if sys.version_info < (3, 9): # pragma: nocover + from typing import Tuple as TupleType +else: # pragma: nocover + TupleType = tuple + + Pagination = namedtuple( 'Pagination', ['page_number', 'page_size', 'num_pages', 'total_results'] ) @@ -19,7 +26,7 @@ def apply_pagination( page_number: Optional[int] = None, page_size: Optional[int] = None, total_results: int = 0 -) -> tuple[Union[Select, Query], Pagination]: +) -> TupleType[Union[Select, Query], Pagination]: """Apply pagination to a SQLAlchemy query or Select object. :param stmt: