Mercurial > public > mercurial-scm > hg
annotate mercurial/interfaces/misc.py @ 52893: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 |
rev | line source |
---|---|
52893
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # misc.py - Various Interface that did not deserve a dedicated module (yet) |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 # Copyright 2025 Octobus, contact@octobus.net |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 from __future__ import annotations |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 import abc |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 from typing import ( |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 Callable, |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 List, |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 Protocol, |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 ) |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 class IHooks(Protocol): |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 """A collection of hook functions that can be used to extend a |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 function's behavior. Hooks are called in lexicographic order, |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 based on the names of their sources.""" |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 @abc.abstractmethod |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 def add(self, source: bytes, hook: Callable): |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 ... |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 @abc.abstractmethod |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 def __call__(self, *args) -> List: |
483b0bb23085
typing: use a protocol to annotate `hooks` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 ... |