Skip to content

Commit 8172207

Browse files
committed
Fix typing
1 parent 7006b8d commit 8172207

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pymongo/asynchronous/auth_oidc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import asyncio
19+
import threading
1920
import time
2021
from dataclasses import dataclass, field
2122
from typing import TYPE_CHECKING, Any, Mapping, MutableMapping, Optional, Union
@@ -82,7 +83,11 @@ class _OIDCAuthenticator:
8283
access_token: Optional[str] = field(default=None)
8384
idp_info: Optional[OIDCIdPInfo] = field(default=None)
8485
token_gen_id: int = field(default=0)
85-
lock: Lock = field(default_factory=_async_create_lock)
86+
if not _IS_SYNC:
87+
lock: Lock = field(default_factory=_async_create_lock) # type: ignore[assignment]
88+
else:
89+
lock: threading.Lock = field(default_factory=_async_create_lock) # type: ignore[assignment, no-redef]
90+
8691
last_call_time: float = field(default=0)
8792

8893
async def reauthenticate(self, conn: AsyncConnection) -> Optional[Mapping[str, Any]]:
@@ -187,7 +192,7 @@ async def _get_access_token(self) -> Optional[str]:
187192
return None
188193

189194
if not prev_token and cb is not None:
190-
async with self.lock:
195+
async with self.lock: # type: ignore[attr-defined]
191196
# See if the token was changed while we were waiting for the
192197
# lock.
193198
new_token = self.access_token
@@ -213,7 +218,7 @@ async def _get_access_token(self) -> Optional[str]:
213218
username=self.properties.username,
214219
)
215220
if not _IS_SYNC:
216-
resp = await asyncio.get_running_loop().run_in_executor(None, cb.fetch, context)
221+
resp = await asyncio.get_running_loop().run_in_executor(None, cb.fetch, context) # type: ignore[assignment]
217222
else:
218223
resp = cb.fetch(context)
219224
if not isinstance(resp, OIDCCallbackResult):

pymongo/synchronous/auth_oidc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import asyncio
19+
import threading
1920
import time
2021
from dataclasses import dataclass, field
2122
from typing import TYPE_CHECKING, Any, Mapping, MutableMapping, Optional, Union
@@ -82,7 +83,11 @@ class _OIDCAuthenticator:
8283
access_token: Optional[str] = field(default=None)
8384
idp_info: Optional[OIDCIdPInfo] = field(default=None)
8485
token_gen_id: int = field(default=0)
85-
lock: Lock = field(default_factory=_create_lock)
86+
if not _IS_SYNC:
87+
lock: Lock = field(default_factory=_create_lock) # type: ignore[assignment]
88+
else:
89+
lock: threading.Lock = field(default_factory=_create_lock) # type: ignore[assignment, no-redef]
90+
8691
last_call_time: float = field(default=0)
8792

8893
def reauthenticate(self, conn: Connection) -> Optional[Mapping[str, Any]]:
@@ -187,7 +192,7 @@ def _get_access_token(self) -> Optional[str]:
187192
return None
188193

189194
if not prev_token and cb is not None:
190-
with self.lock:
195+
with self.lock: # type: ignore[attr-defined]
191196
# See if the token was changed while we were waiting for the
192197
# lock.
193198
new_token = self.access_token
@@ -213,7 +218,7 @@ def _get_access_token(self) -> Optional[str]:
213218
username=self.properties.username,
214219
)
215220
if not _IS_SYNC:
216-
resp = asyncio.get_running_loop().run_in_executor(None, cb.fetch, context)
221+
resp = asyncio.get_running_loop().run_in_executor(None, cb.fetch, context) # type: ignore[assignment]
217222
else:
218223
resp = cb.fetch(context)
219224
if not isinstance(resp, OIDCCallbackResult):

0 commit comments

Comments
 (0)