This is an automated email from the ASF dual-hosted git repository. gcruz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
commit c3daf98f3405f59c9bbe9bc2f3b03a8c8b092088 Author: Dave Brondsema <[email protected]> AuthorDate: Wed Nov 9 14:51:48 2022 -0500 type hint for chunked_find --- Allura/allura/lib/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py index 41b2c979f..6dca2dc8b 100644 --- a/Allura/allura/lib/utils.py +++ b/Allura/allura/lib/utils.py @@ -14,9 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +from __future__ import annotations import base64 -import operator +from collections.abc import Iterable from contextlib import contextmanager import time import string @@ -28,6 +29,7 @@ import datetime import random import mimetypes import re +from typing import Type, TypeVar import magic from itertools import groupby import operator as op @@ -37,7 +39,6 @@ from six.moves.urllib.parse import urlparse import six.moves.urllib.request import six.moves.urllib.parse import six.moves.urllib.error -import types import socket import tg @@ -61,6 +62,10 @@ from ming.odm.odmsession import ODMCursor from ming.odm import session import six + +T = TypeVar('T') + + MARKDOWN_EXTENSIONS = ['.markdown', '.mdown', '.mkdn', '.mkd', '.md'] @@ -154,7 +159,8 @@ class CustomWatchedFileHandler(logging.handlers.WatchedFileHandler): return super().format(record) -def chunked_find(cls, query=None, pagesize=1024, sort_key='_id', sort_dir=1): +def chunked_find(cls: Type[T], query: dict | None = None, pagesize: int = 1024, sort_key: str | None = '_id', + sort_dir: int = 1) -> Iterable[Iterable[T]]: ''' Execute a mongo query against the specified class, yield some results at a time (avoids mongo cursor timeouts if the total result set is very large).
