Skip to content

Commit 6370d2f

Browse files
committed
apply com2ann
1 parent fb16674 commit 6370d2f

File tree

3 files changed

+47
-52
lines changed

3 files changed

+47
-52
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
# List of patterns, relative to source directory, that match files and
5858
# directories to ignore when looking for source files.
59-
exclude_patterns = [] # type: List[str]
59+
exclude_patterns: List[str] = []
6060

6161
# Example configuration for intersphinx: refer to the Python standard library.
6262
intersphinx_mapping = {'http://docs.python.org/': None}

src/priority/priority.py

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,22 @@ class Stream:
8989
:param weight: (optional) The stream weight. Defaults to 16.
9090
"""
9191

92-
def __init__(self, stream_id, weight=16): # type: (int, int) -> None
92+
def __init__(self, stream_id: int, weight: int = 16) -> None:
9393
self.stream_id = stream_id
9494
self.weight = weight
95-
self.children = [] # type: List[Stream]
96-
self.parent = None # type: Optional[Stream]
97-
self.child_queue = [] # type: List[Tuple[int, Stream]]
95+
self.children: List[Stream] = []
96+
self.parent: Optional[Stream] = None
97+
self.child_queue: List[Tuple[int, Stream]] = []
9898
self.active = True
9999
self.last_weight = 0
100100
self._deficit = 0
101101

102102
@property
103-
def weight(self): # type: () -> int
103+
def weight(self) -> int:
104104
return self._weight
105105

106106
@weight.setter
107-
def weight(self, value): # type: (int) -> None
107+
def weight(self, value: int) -> None:
108108
# RFC 7540 § 5.3.2: "All dependent streams are allocated an integer
109109
# weight between 1 and 256 (inclusive)."
110110
if not isinstance(value, int):
@@ -115,7 +115,7 @@ def weight(self, value): # type: (int) -> None
115115
)
116116
self._weight = value
117117

118-
def add_child(self, child): # type: (Stream) -> None
118+
def add_child(self, child: Stream) -> None:
119119
"""
120120
Add a stream that depends on this one.
121121
@@ -125,7 +125,7 @@ def add_child(self, child): # type: (Stream) -> None
125125
self.children.append(child)
126126
heapq.heappush(self.child_queue, (self.last_weight, child))
127127

128-
def add_child_exclusive(self, child): # type: (Stream) -> None
128+
def add_child_exclusive(self, child: Stream) -> None:
129129
"""
130130
Add a stream that exclusively depends on this one.
131131
@@ -142,10 +142,9 @@ def add_child_exclusive(self, child): # type: (Stream) -> None
142142

143143
def remove_child(
144144
self,
145-
child, # type: Stream
146-
strip_children=True, # type: bool
147-
):
148-
# type: (...) -> None
145+
child: Stream,
146+
strip_children: bool = True,
147+
) -> None:
149148
"""
150149
Removes a child stream from this stream. This is a potentially somewhat
151150
expensive operation.
@@ -161,7 +160,7 @@ def remove_child(
161160
# it in the old one
162161
self.children.remove(child)
163162

164-
new_queue = [] # type: List[Tuple[int, Stream]]
163+
new_queue: List[Tuple[int, Stream]] = []
165164

166165
while self.child_queue:
167166
level, stream = heapq.heappop(self.child_queue)
@@ -176,7 +175,7 @@ def remove_child(
176175
for new_child in child.children:
177176
self.add_child(new_child)
178177

179-
def schedule(self): # type: () -> int
178+
def schedule(self) -> int:
180179
"""
181180
Returns the stream ID of the next child to schedule. Potentially
182181
recurses down the tree of priorities.
@@ -216,45 +215,45 @@ def schedule(self): # type: () -> int
216215
return next_stream
217216

218217
# Custom repr
219-
def __repr__(self): # type: () -> str
218+
def __repr__(self) -> str:
220219
return "Stream<id=%d, weight=%d>" % (self.stream_id, self.weight)
221220

222221
# Custom comparison
223-
def __eq__(self, other): # type: (object) -> bool
222+
def __eq__(self, other: object) -> bool:
224223
if not isinstance(other, Stream): # pragma: no cover
225224
return False
226225

227226
return self.stream_id == other.stream_id
228227

229-
def __ne__(self, other): # type: (object) -> bool
228+
def __ne__(self, other: object) -> bool:
230229
return not self.__eq__(other)
231230

232-
def __lt__(self, other): # type: (Stream) -> bool
231+
def __lt__(self, other: Stream) -> bool:
233232
if not isinstance(other, Stream): # pragma: no cover
234233
return NotImplemented
235234

236235
return self.stream_id < other.stream_id
237236

238-
def __le__(self, other): # type: (Stream) -> bool
237+
def __le__(self, other: Stream) -> bool:
239238
if not isinstance(other, Stream): # pragma: no cover
240239
return NotImplemented
241240

242241
return self.stream_id <= other.stream_id
243242

244-
def __gt__(self, other): # type: (Stream) -> bool
243+
def __gt__(self, other: Stream) -> bool:
245244
if not isinstance(other, Stream): # pragma: no cover
246245
return NotImplemented
247246

248247
return self.stream_id > other.stream_id
249248

250-
def __ge__(self, other): # type: (Stream) -> bool
249+
def __ge__(self, other: Stream) -> bool:
251250
if not isinstance(other, Stream): # pragma: no cover
252251
return NotImplemented
253252

254253
return self.stream_id >= other.stream_id
255254

256255

257-
def _stream_cycle(new_parent, current): # type: (Stream, Stream) -> bool
256+
def _stream_cycle(new_parent: Stream, current: Stream) -> bool:
258257
"""
259258
Reports whether the new parent depends on the current stream.
260259
"""
@@ -301,7 +300,7 @@ class PriorityTree:
301300
:type maximum_streams: ``int``
302301
"""
303302

304-
def __init__(self, maximum_streams=1000): # type: (int) -> None
303+
def __init__(self, maximum_streams: int = 1000) -> None:
305304
# This flat array keeps hold of all the streams that are logically
306305
# dependent on stream 0.
307306
self._root_stream = Stream(stream_id=0, weight=1)
@@ -314,7 +313,7 @@ def __init__(self, maximum_streams=1000): # type: (int) -> None
314313
raise ValueError("maximum_streams must be a positive integer.")
315314
self._maximum_streams = maximum_streams
316315

317-
def _get_or_insert_parent(self, parent_stream_id): # type: (int) -> Stream
316+
def _get_or_insert_parent(self, parent_stream_id: int) -> Stream:
318317
"""
319318
When inserting or reprioritizing a stream it is possible to make it
320319
dependent on a stream that is no longer in the tree. In this situation,
@@ -330,10 +329,9 @@ def _get_or_insert_parent(self, parent_stream_id): # type: (int) -> Stream
330329

331330
def _exclusive_insert(
332331
self,
333-
parent_stream, # type: Stream
334-
inserted_stream, # type: Stream
335-
):
336-
# type: (...) -> None
332+
parent_stream: Stream,
333+
inserted_stream: Stream,
334+
) -> None:
337335
"""
338336
Insert ``inserted_stream`` beneath ``parent_stream``, obeying the
339337
semantics of exclusive insertion.
@@ -342,12 +340,11 @@ def _exclusive_insert(
342340

343341
def insert_stream(
344342
self,
345-
stream_id, # type: int
346-
depends_on=None, # type: Optional[int]
347-
weight=16, # type: int
348-
exclusive=False, # type: bool
349-
):
350-
# type: (...) -> None
343+
stream_id: int,
344+
depends_on: Optional[int] = None,
345+
weight: int = 16,
346+
exclusive: bool = False,
347+
) -> None:
351348
"""
352349
Insert a stream into the tree.
353350
@@ -389,12 +386,11 @@ def insert_stream(
389386

390387
def reprioritize(
391388
self,
392-
stream_id, # type: int
393-
depends_on=None, # type: Optional[int]
394-
weight=16, # type: int
395-
exclusive=False, # type: bool
396-
):
397-
# type: (...) -> None
389+
stream_id: int,
390+
depends_on: Optional[int] = None,
391+
weight: int = 16,
392+
exclusive: bool = False,
393+
) -> None:
398394
"""
399395
Update the priority status of a stream already in the tree.
400396
@@ -453,7 +449,7 @@ def reprioritize(
453449
else:
454450
new_parent.add_child(current_stream)
455451

456-
def remove_stream(self, stream_id): # type: (int) -> None
452+
def remove_stream(self, stream_id: int) -> None:
457453
"""
458454
Removes a stream from the priority tree.
459455
@@ -470,7 +466,7 @@ def remove_stream(self, stream_id): # type: (int) -> None
470466
parent = child.parent
471467
parent.remove_child(child) # type: ignore[union-attr]
472468

473-
def block(self, stream_id): # type: (int) -> None
469+
def block(self, stream_id: int) -> None:
474470
"""
475471
Marks a given stream as blocked, with no data to send.
476472
@@ -484,7 +480,7 @@ def block(self, stream_id): # type: (int) -> None
484480
except KeyError:
485481
raise MissingStreamError("Stream %d not in tree" % stream_id)
486482

487-
def unblock(self, stream_id): # type: (int) -> None
483+
def unblock(self, stream_id: int) -> None:
488484
"""
489485
Marks a given stream as unblocked, with more data to send.
490486
@@ -499,14 +495,14 @@ def unblock(self, stream_id): # type: (int) -> None
499495
raise MissingStreamError("Stream %d not in tree" % stream_id)
500496

501497
# The iterator protocol
502-
def __iter__(self): # type: () -> PriorityTree # pragma: no cover
498+
def __iter__(self) -> PriorityTree: # pragma: no cover
503499
return self
504500

505-
def __next__(self): # type: () -> int # pragma: no cover
501+
def __next__(self) -> int: # pragma: no cover
506502
try:
507503
return self._root_stream.schedule()
508504
except IndexError:
509505
raise DeadlockError("No unblocked streams to schedule.")
510506

511-
def next(self): # type: () -> int # pragma: no cover
507+
def next(self) -> int: # pragma: no cover
512508
return self.__next__()

test/test_priority.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ def readme_tree():
5959

6060

6161
def active_readme_streams_from_filter(
62-
filtered, # type: Iterable[int]
63-
blocked=True, # type: bool
64-
):
65-
# type: (...) -> List[int]
62+
filtered: Iterable[int],
63+
blocked: bool = True,
64+
) -> List[int]:
6665
"""
6766
Given a collection of filtered streams, determine which ones are active.
6867
This applies only to the readme tree at this time, though in future it
@@ -84,7 +83,7 @@ def active_readme_streams_from_filter(
8483
}
8584
filtered = set(filtered)
8685

87-
def get_expected(tree): # type: (Dict[Any, Any]) -> List[int]
86+
def get_expected(tree: Dict[Any, Any]) -> List[int]:
8887
expected = []
8988

9089
for stream_id in tree:

0 commit comments

Comments
 (0)