Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/interfaces/types.py @ 52755:5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
This is a proposal to formalise the way we do typing and do more of it.
The initial motivation to make progress is to help break the 100+ module
cycle that is slowing pytype a lot.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 30 Jan 2025 18:22:01 +0100 |
parents | |
children | fecda9f44e57 |
rev | line source |
---|---|
52755
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` |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 # - to implement foobar: use IFoorbar from `mercurial.interface.foo_bar` |
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 |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 from . import ( |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 _basetypes, |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 matcher, |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 ) |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 MatcherT = matcher.IMatcher |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 UserMsgT = _basetypes.UserMsgT |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 HgPathT = _basetypes.HgPathT |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 FsPathT = _basetypes.FsPathT |