You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2022/11/09 19:51:59 UTC

[allura] 02/02: type hint for chunked_find

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/410_gone
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 9774cd4f053cf0baba85b56e6ce2c02addb95a18
Author: Dave Brondsema <db...@slashdotmedia.com>
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).