From 43d3fa6774ccaa28fe19819cb3a7d1495c9e33aa Mon Sep 17 00:00:00 2001 From: Iris <58442094+sleepyStick@users.noreply.github.com> Date: Mon, 24 Jul 2023 16:07:12 -0700 Subject: [PATCH] PYTHON-3868 add types to typings.py (#1324) --- pymongo/typings.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pymongo/typings.py b/pymongo/typings.py index e9d0ce8ce..4630870b8 100644 --- a/pymongo/typings.py +++ b/pymongo/typings.py @@ -13,7 +13,16 @@ # limitations under the License. """Type aliases used by PyMongo""" -from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence, Tuple, Union +from typing import ( + TYPE_CHECKING, + Any, + Mapping, + Optional, + Sequence, + Tuple, + TypeVar, + Union, +) from bson.typings import _DocumentOut, _DocumentType, _DocumentTypeArg @@ -26,8 +35,10 @@ _Address = Tuple[str, Optional[int]] _CollationIn = Union[Mapping[str, Any], "Collation"] _Pipeline = Sequence[Mapping[str, Any]] +_T = TypeVar("_T") -def strip_optional(elem): + +def strip_optional(elem: Optional[_T]) -> _T: """This function is to allow us to cast all of the elements of an iterator from Optional[_T] to _T while inside a list comprehension. """