Skip to content

Commit 2cd31c6

Browse files
tvaron3Copilot
andcommitted
fix: resolve pylint, mypy, cspell errors in PKRange change
- Import PKRange in _routing_map_provider_common.py (fixes all emulator tests) - Fix namedtuple name mismatch (_PKRangeBase, not PKRange) for mypy - Use raise-from pattern in PKRange.__getitem__ (pylint W0707) - Move _locks_lock and _collection_locks init into __init__ (pylint W0201) - Add 'pkrange' to cspell dictionary Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3ec8f5e commit 2cd31c6

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@
17191719
"filename": "sdk/cosmos/azure-cosmos/**",
17201720
"words": [
17211721
"colls",
1722+
"pkrange",
17221723
"pkranges",
17231724
"Upserts",
17241725
"sprocs",

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/_routing_map_provider_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .collection_routing_map import CollectionRoutingMap, _build_routing_map_from_ranges
3535
from . import routing_range
3636
from .routing_range import (
37+
PKRange,
3738
PartitionKeyRange,
3839
_is_sorted_and_non_overlapping,
3940
_subtract_range,

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/aio/routing_map_provider.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def __init__(self, client: Any):
7979
self._collection_routing_map_by_item = _shared_routing_map_cache[self._endpoint]
8080
# A lock to control access to the locks dictionary itself
8181
self._locks_lock = asyncio.Lock()
82+
# A dictionary to hold a lock for each collection ID
83+
self._collection_locks: Dict[str, asyncio.Lock] = {}
8284

8385
def clear_cache(self):
8486
"""Clear the shared routing map cache for this endpoint."""
@@ -87,8 +89,7 @@ def clear_cache(self):
8789
_shared_routing_map_cache[self._endpoint] = {}
8890
self._collection_routing_map_by_item = _shared_routing_map_cache.get(self._endpoint, {})
8991

90-
# A dictionary to hold a lock for each collection ID
91-
self._collection_locks: Dict[str, asyncio.Lock] = {}
92+
self._collection_locks = {}
9293

9394
async def _get_lock_for_collection(self, collection_id: str) -> asyncio.Lock:
9495
"""Safely gets or creates a lock for a given collection ID.

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/routing_map_provider.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,20 @@ def __init__(self, client: Any):
7676
_shared_routing_map_cache[self._endpoint] = {}
7777
self._collection_routing_map_by_item = _shared_routing_map_cache[self._endpoint]
7878

79+
# A lock to control access to the locks dictionary itself
80+
self._locks_lock = threading.Lock()
81+
# A dictionary to hold a lock for each collection ID
82+
self._collection_locks: Dict[str, threading.Lock] = {}
83+
7984
def clear_cache(self):
8085
"""Clear the shared routing map cache for this endpoint."""
8186
with _shared_cache_lock:
8287
if self._endpoint in _shared_routing_map_cache:
8388
_shared_routing_map_cache[self._endpoint] = {}
8489
self._collection_routing_map_by_item = _shared_routing_map_cache.get(self._endpoint, {})
8590

86-
# A lock to control access to the locks dictionary itself
8791
self._locks_lock = threading.Lock()
88-
# A dictionary to hold a lock for each collection ID
89-
self._collection_locks: Dict[str, threading.Lock] = {}
92+
self._collection_locks = {}
9093

9194
def _get_lock_for_collection(self, collection_id: str) -> threading.Lock:
9295

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/routing_range.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from collections import namedtuple
3131

32-
_PKRangeBase = namedtuple('PKRange', ['id', 'minInclusive', 'maxExclusive', 'parents'])
32+
_PKRangeBase = namedtuple('_PKRangeBase', ['id', 'minInclusive', 'maxExclusive', 'parents'])
3333

3434

3535
class PKRange(_PKRangeBase):
@@ -39,8 +39,8 @@ class PKRange(_PKRangeBase):
3939
def __getitem__(self, key):
4040
try:
4141
return getattr(self, key)
42-
except AttributeError:
43-
raise KeyError(key)
42+
except AttributeError as exc:
43+
raise KeyError(key) from exc
4444

4545
def get(self, key, default=None):
4646
return getattr(self, key, default)

0 commit comments

Comments
 (0)