Mercurial > hg
view .hgignore @ 51671:6fc31e7bd5db
typing: add some type hints for bundle2 capabilities
Somewhere between hg 3dbc7b1ecaba and hg 8e3f6b5bf720, pytype determined the
signature of `bundle20.capabilities` changed from `Dict[bytes, Tuple[bytes]]` to
`Dict[bytes, Union[List[bytes], Tuple[bytes]]]`.
First, I did try to simply be explicit about the previously inferred type, but
it does seem to mix and match list/tuple now (e.g. in `writenewbundle()`). I
tried changing the new list usage to tuple, but a couple of things complained,
(and I think lists of one item are a little more clear to read anyway). So then
I typed the dict value as `Sequence[bytes]`, which worked fine. But there's
also a module level `capabilities` field, and when that's typed, pytype
complains about `Sequence[bytes]` lacking `__add__`[1]. So I gave up, and just
assigned it the type it wanted, with an alias. If somebody feels motivated to
make the type consistent, it's simple enough to change the alias.
The mutable default value to the constructor was removed to appease PyCharm's
type checking on the field. (I didn't bother running the code through pytype
prior to changing it, because we've previously made an effort to remove this
pattern anyway.)
I'm not sure why `getrepocaps()` has a default value for `role` that apparently
raises an exception. It's just flagged for now so this series can land without
risking additional problems.
[1] https://foss.heptapod.net/mercurial/mercurial-devel/-/jobs/2466903
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 10 Jul 2024 17:09:34 -0400 |
parents | 59820ae507b1 |
children | 2a875530a023 |
line wrap: on
line source
syntax: glob *.elc *.tmp *.orig *.rej *~ *.mergebackup *.o *.so *.dll *.exe *.pyd *.pyc *.pyo *$py.class *.swp *.prof *.zip \#*\# .\#* result/ tests/artifacts/cache/big-file-churn.hg tests/.coverage* tests/.testtimes* # the file is written in the CWD when run-tests is run. .testtimes tests/.hypothesis tests/hypothesis-generated tests/annotated tests/exceptions tests/python3 tests/*.err tests/htmlcov build contrib/chg/chg contrib/hgsh/hgsh contrib/vagrant/.vagrant contrib/merge-lists/target/ dist packages doc/common.txt doc/*.[0-9] doc/*.[0-9].txt doc/*.[0-9].gendoc.txt doc/*.[0-9].{x,ht}ml MANIFEST MANIFEST.in patches mercurial/__modulepolicy__.py mercurial/__version__.py mercurial/hgpythonlib.h mercurial.egg-info .DS_Store tags cscope.* .vscode/* .idea/* .asv/* .pytype/* .mypy_cache i18n/hg.pot locale/*/LC_MESSAGES/hg.mo hgext/__index__.py rust/target/ rust/*/target/ # Generated wheels wheelhouse/ syntax: rootglob # See Profiling in rust/README.rst .cargo/config syntax: regexp ^\.pc/ ^\.(pydev)?project # hackable windows distribution additions ^hg-python ^hg.py$