annotate mercurial/interfaces/types.py @ 52902:3e8a3db5f5e8

typing: introduce a few basic alias for common types These types are passed everywhere. We introduce basic alias to Any, to make it simpler to start annotating code prior to introducing proper protocol for them.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 07 Feb 2025 23:00:31 +0100
parents a7dcb7c1ff5a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52741
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 # mercurial/interfaces/types.py - type alias for interfaces
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 #
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 # This software may be used and distributed according to the terms of the
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 # GNU General Public License version 2 or any later version.
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 #
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 # This is the main entry point for Mercurial code writing type annotations.
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 #
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 # The general principle can be summarized when dealing with <FooBar> object:
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 # - to type your code: use FooBarT from `mercurial.interface.types`
52748
fecda9f44e57 interfaces: minor documentation tweaks to the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52741
diff changeset
10 # - to subclass <FooBar>: use IFooBar from `mercurial.interface.foo_bar`
52741
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 from __future__ import annotations
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13
52752
4eede65d68cf lint: add comments for disabling unused import warnings where appropriate
Matt Harbison <matt_harbison@yahoo.com>
parents: 52750
diff changeset
14 from ._basetypes import ( # noqa: F401 (ignore imported but not used)
52753
ae2848198462 typing: add annotation to the public API of the transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52752
diff changeset
15 CallbackCategoryT,
52750
2a5450ecde20 interfaces: direct import the basetypes into the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52748
diff changeset
16 FsPathT,
2a5450ecde20 interfaces: direct import the basetypes into the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52748
diff changeset
17 HgPathT,
52902
3e8a3db5f5e8 typing: introduce a few basic alias for common types
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52754
diff changeset
18 RepoT,
3e8a3db5f5e8 typing: introduce a few basic alias for common types
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52754
diff changeset
19 UiT,
52750
2a5450ecde20 interfaces: direct import the basetypes into the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52748
diff changeset
20 UserMsgT,
52753
ae2848198462 typing: add annotation to the public API of the transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52752
diff changeset
21 VfsKeyT,
52902
3e8a3db5f5e8 typing: introduce a few basic alias for common types
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52754
diff changeset
22 VfsT,
52750
2a5450ecde20 interfaces: direct import the basetypes into the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52748
diff changeset
23 )
2a5450ecde20 interfaces: direct import the basetypes into the `types` module
Matt Harbison <matt_harbison@yahoo.com>
parents: 52748
diff changeset
24
52741
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25 from . import (
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
26 matcher,
52754
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52753
diff changeset
27 transaction,
52741
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
28 )
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
29
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
30 MatcherT = matcher.IMatcher
52754
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52753
diff changeset
31 TransactionT = transaction.ITransaction