Mercurial > public > mercurial-scm > hg
diff mercurial/phases.py @ 52900:0fd4b2af347b
typing: add a few hints to `mercurial.phases` to appease PyCharm
I'm a little surprised that pytype doesn't complain- `phasenumber` is
`dict[bytes, int]`, so that's what `phasenumber2` is, due to initializing with a
copy of `phasenumber`. But then the next line doesn't adhere to that, and
starts adding keys as bytes. Be explicit and allow both.
The second issue is PyCharm thinks `_readroots()` returns
`tuple[dict[int, set] | dict[int, set[int]], bool] | None` (note the first set
doesn't have a parameterized type like the second and the bool is somehow
missing). That can also be helped by being explicit. This doesn't completely
fix the issue (it still thinks it can return None somehow, but neither I nor
pytype see how, so it's got to be a bug), but at least the dict types now match
and are elided in the warning so that it is more readable.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 13 Feb 2025 11:40:56 -0500 |
parents | 4cb75772818d |
children |
line wrap: on
line diff
--- a/mercurial/phases.py Tue Feb 11 23:30:00 2025 -0500 +++ b/mercurial/phases.py Thu Feb 13 11:40:56 2025 -0500 @@ -173,10 +173,12 @@ phasenames[archived] = b'archived' phasenames[internal] = b'internal' # map phase name to phase number -phasenumber = {name: phase for phase, name in phasenames.items()} +phasenumber: dict[bytes, int] = { + name: phase for phase, name in phasenames.items() +} # like phasenumber, but also include maps for the numeric and binary # phase number to the phase number -phasenumber2 = phasenumber.copy() +phasenumber2: dict[bytes | int, int] = phasenumber.copy() phasenumber2.update({phase: phase for phase in phasenames}) phasenumber2.update({b'%i' % phase: phase for phase in phasenames}) # record phase property @@ -216,7 +218,7 @@ """ repo = repo.unfiltered() dirty = False - roots = {i: set() for i in allphases} + roots: Phaseroots = {i: set() for i in allphases} to_rev = repo.changelog.index.get_rev unknown_msg = b'removing unknown node %s from %i-phase boundary\n' try: