Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/interfaces/misc.py @ 52905:483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
That is one external import for the repository interface module. Two more to go.
This introduces a new "misc" module in the `interfaces` "package" to host small
things that does warrant their own module yet.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 08 Feb 2025 18:12:29 +0100 |
parents | |
children | bde94bd8e8a2 |
comparison
equal
deleted
inserted
replaced
52904:acaf6bad6b89 | 52905:483b0bb23085 |
---|---|
1 # misc.py - Various Interface that did not deserve a dedicated module (yet) | |
2 # | |
3 # Copyright 2025 Octobus, contact@octobus.net | |
4 from __future__ import annotations | |
5 | |
6 import abc | |
7 | |
8 from typing import ( | |
9 Callable, | |
10 List, | |
11 Protocol, | |
12 ) | |
13 | |
14 | |
15 class IHooks(Protocol): | |
16 """A collection of hook functions that can be used to extend a | |
17 function's behavior. Hooks are called in lexicographic order, | |
18 based on the names of their sources.""" | |
19 | |
20 @abc.abstractmethod | |
21 def add(self, source: bytes, hook: Callable): | |
22 ... | |
23 | |
24 @abc.abstractmethod | |
25 def __call__(self, *args) -> List: | |
26 ... |