1
+ from __future__ import annotations
2
+
1
3
import collections
2
4
import functools
3
5
import itertools
4
6
import operator
5
7
8
+ from collections .abc import Mapping
9
+ from typing import Any
10
+
6
11
7
12
# from jaraco.collections 3.5.1
8
13
class DictStack (list , collections .abc .Mapping ):
@@ -58,7 +63,7 @@ def __len__(self):
58
63
return len (list (iter (self )))
59
64
60
65
61
- # from jaraco.collections 3.7
66
+ # from jaraco.collections 5.0.1
62
67
class RangeMap (dict ):
63
68
"""
64
69
A dictionary-like object that uses the keys as bounds for a range.
@@ -70,7 +75,7 @@ class RangeMap(dict):
70
75
One may supply keyword parameters to be passed to the sort function used
71
76
to sort keys (i.e. key, reverse) as sort_params.
72
77
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'
74
79
75
80
>>> r = RangeMap({3: 'a', 6: 'b'}) # boy, that was easy
76
81
>>> r[1], r[2], r[3], r[4], r[5], r[6]
@@ -82,7 +87,7 @@ class RangeMap(dict):
82
87
>>> r[4.5]
83
88
'b'
84
89
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
86
91
on one side.
87
92
88
93
>>> r[0]
@@ -140,7 +145,12 @@ class RangeMap(dict):
140
145
141
146
"""
142
147
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
+ ):
144
154
dict .__init__ (self , source )
145
155
self .sort_params = sort_params
146
156
self .match = key_match_comparator
0 commit comments