Skip to content

Commit 9390f46

Browse files
committed
Refresh RangeMap from jaraco.collections 5.0.1.
1 parent 47db639 commit 9390f46

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

distutils/_collections.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from __future__ import annotations
2+
13
import collections
24
import functools
35
import itertools
46
import operator
57

8+
from collections.abc import Mapping
9+
from typing import Any
10+
611

712
# from jaraco.collections 3.5.1
813
class DictStack(list, collections.abc.Mapping):
@@ -58,7 +63,7 @@ def __len__(self):
5863
return len(list(iter(self)))
5964

6065

61-
# from jaraco.collections 3.7
66+
# from jaraco.collections 5.0.1
6267
class RangeMap(dict):
6368
"""
6469
A dictionary-like object that uses the keys as bounds for a range.
@@ -70,7 +75,7 @@ class RangeMap(dict):
7075
One may supply keyword parameters to be passed to the sort function used
7176
to sort keys (i.e. key, reverse) as sort_params.
7277
73-
Let's create a map that maps 1-3 -> 'a', 4-6 -> 'b'
78+
Create a map that maps 1-3 -> 'a', 4-6 -> 'b'
7479
7580
>>> r = RangeMap({3: 'a', 6: 'b'}) # boy, that was easy
7681
>>> r[1], r[2], r[3], r[4], r[5], r[6]
@@ -82,7 +87,7 @@ class RangeMap(dict):
8287
>>> r[4.5]
8388
'b'
8489
85-
But you'll notice that the way rangemap is defined, it must be open-ended
90+
Notice that the way rangemap is defined, it must be open-ended
8691
on one side.
8792
8893
>>> r[0]
@@ -140,7 +145,12 @@ class RangeMap(dict):
140145
141146
"""
142147

143-
def __init__(self, source, sort_params={}, key_match_comparator=operator.le):
148+
def __init__(
149+
self,
150+
source,
151+
sort_params: Mapping[str, Any] = {},
152+
key_match_comparator=operator.le,
153+
):
144154
dict.__init__(self, source)
145155
self.sort_params = sort_params
146156
self.match = key_match_comparator

0 commit comments

Comments
 (0)