Mercurial > hg
annotate mercurial/typelib.py @ 51723:9367571fea21
cext: correct the argument handling of `b85encode()`
The type stub indicated that this argument is `Optional`, which implies None is
allowed. I don't see in the documentation where that's the case for `i`[1], and
trying it in `hg debugshell` resulted in the method failing with a TypeError. I
guess it was typed as an `int` argument because the `p` format unit wasn't added
until Python 3.3[2].
In any event, 2 clients in core (`pvec` and `obsolete`) call this with no
argument supplied, and `mdiff` calls it with True. So I guess we've avoided the
None arg case, and when no arg is supplied, it defaults to the 0 initialization
of the `pad` variable in C. Since the `p` format unit accepts both `int` and
None, as well as `bool`, I'm not bothering to bump the module version- this code
is more permissive than it was, in addition to being more correct.
Interestingly, when I first imported the `cext` and `pure` methods in the same
manner as the previous commit, it dropped the `Optional` part of the argument
type when generating `util.pyi`. No idea why.
[1] https://docs.python.org/3/c-api/arg.html#numbers
[2] https://docs.python.org/3/c-api/arg.html#other-objects
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 20 Jul 2024 01:55:09 -0400 |
parents | f3b34386d3e0 |
children | 43460c311c0c |
rev | line source |
---|---|
49793
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 |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
10 # 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
|
11 # 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
|
12 # 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
|
13 TYPE_CHECKING = typing.TYPE_CHECKING |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
14 |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
15 |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
16 # 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
|
17 # ``__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
|
18 # 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
|
19 # 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
|
20 # ``object`` otherwise. |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
21 if TYPE_CHECKING: |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
22 from typing import ( |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
23 BinaryIO, |
51716
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
24 Union, |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
25 ) |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
26 |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
27 from . import ( |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
28 node, |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
29 posix, |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
30 windows, |
49793
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
31 ) |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
32 |
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
33 BinaryIO_Proxy = BinaryIO |
51716
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
34 CacheStat = Union[posix.cachestat, windows.cachestat] |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
35 NodeConstants = node.sha1nodeconstants |
49793
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
36 else: |
51716
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
37 from typing import Any |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
38 |
49793
8147abc05794
pytype: stop excluding mercurial/ui.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
39 BinaryIO_Proxy = object |
51716
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
40 CacheStat = Any |
f3b34386d3e0
typing: add type hints to `mercurial.dirstatemap`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49793
diff
changeset
|
41 NodeConstants = Any |