refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
from __future__ import annotations
|
2023-01-06 18:02:17 +00:00
|
|
|
|
2022-11-08 15:09:16 +00:00
|
|
|
import typing as t
|
|
|
|
|
|
|
|
from typing_extensions import Protocol
|
|
|
|
|
|
|
|
HIGH = 5
|
|
|
|
DEFAULT = 10
|
|
|
|
LOW = 50
|
|
|
|
|
|
|
|
|
|
|
|
class PrioritizedCallback(Protocol):
|
|
|
|
priority: int
|
|
|
|
|
|
|
|
|
|
|
|
TPrioritized = t.TypeVar("TPrioritized", bound=PrioritizedCallback)
|
|
|
|
|
|
|
|
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
def insert_callback(callback: TPrioritized, callbacks: list[TPrioritized]) -> None:
|
2022-11-08 15:09:16 +00:00
|
|
|
# I wish we could use bisect.insort_right here but the `key=` parameter
|
|
|
|
# is unsupported in Python 3.9
|
|
|
|
position = 0
|
|
|
|
while (
|
|
|
|
position < len(callbacks) and callbacks[position].priority <= callback.priority
|
|
|
|
):
|
|
|
|
position += 1
|
|
|
|
callbacks.insert(position, callback)
|