annotate mercurial/typelib.py @ 51790:43460c311c0c

typing: add trivial type hints to `mercurial.scmutil` There's still a lot to go, but there's a lot here already, so I tried to keep it to obvious/trivial things. I didn't bother with contexts, matchers, and revisions that can be `bytes | int | None`.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 24 Jul 2024 22:40:22 -0400
parents f3b34386d3e0
children 1c5810ce737e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49888
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
1 # typelib.py - type hint aliases and support
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
2 #
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
3 # Copyright 2022 Matt Harbison <matt_harbison@yahoo.com>
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
4 #
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
7
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
8 import typing
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
9
51790
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
10 from typing import (
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
11 Callable,
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
12 )
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
13
49888
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
14 # Note: this is slightly different from pycompat.TYPE_CHECKING, as using
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
15 # pycompat causes the BinaryIO_Proxy type to be resolved to ``object`` when
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
16 # used as the base class during a pytype run.
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
17 TYPE_CHECKING = typing.TYPE_CHECKING
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
18
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
19
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
20 # The BinaryIO class provides empty methods, which at runtime means that
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
21 # ``__getattr__`` on the proxy classes won't get called for the methods that
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
22 # should delegate to the internal object. So to avoid runtime changes because
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
23 # of the required typing inheritance, just use BinaryIO when typechecking, and
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
24 # ``object`` otherwise.
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
25 if TYPE_CHECKING:
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
26 from typing import (
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
27 BinaryIO,
51775
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
28 Union,
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
29 )
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
30
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
31 from . import (
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
32 node,
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
33 posix,
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
34 windows,
49888
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
35 )
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
36
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
37 BinaryIO_Proxy = BinaryIO
51775
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
38 CacheStat = Union[posix.cachestat, windows.cachestat]
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
39 NodeConstants = node.sha1nodeconstants
49888
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
40 else:
51775
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
41 from typing import Any
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
42
49888
8147abc05794 pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
43 BinaryIO_Proxy = object
51775
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
44 CacheStat = Any
f3b34386d3e0 typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49888
diff changeset
45 NodeConstants = Any
51790
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
46
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
47 # scmutil.getuipathfn() related callback.
43460c311c0c typing: add trivial type hints to `mercurial.scmutil`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51775
diff changeset
48 UiPathFn = Callable[[bytes], bytes]