mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-06-22 06:54:44 +00:00
The hooks API had several issues which are summarized in this comment: https://github.com/openedx/wg-developer-experience/issues/125#issuecomment-1313553526 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for https://github.com/openedx/wg-developer-experience/issues/125
28 lines
638 B
Python
28 lines
638 B
Python
from __future__ import annotations
|
|
|
|
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)
|
|
|
|
|
|
def insert_callback(callback: TPrioritized, callbacks: list[TPrioritized]) -> None:
|
|
# 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)
|