Mercurial > hg-stable
changeset 51858:460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
There were a handful of other changes to the pyi files generated when updating
pytype locally (and jumping from python 3.8.0 to python 3.10.11), but they were
not as clear (e.g. the embedded type in a list changing from `nothing` to `Any`
or similar). These looked obviously correct, and agreed with PyCharm's thoughts
on the signatures.
Oddly, even though pytype starting inferring `obsutil._getfilteredreason()` as
returning bytes, it (correctly) complained about the None path when it was typed
that way. Instead, raise a ProgrammingError if an unhandled fate is calculated.
(Currently, all possibilities are handled, so this isn't reachable unless
another fate is added in the future.)
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 20 Aug 2024 18:30:47 -0400 |
parents | f1ef512e14ab |
children | a1a94d488e14 |
files | hgext/convert/monotone.py hgext/remotefilelog/debugcommands.py mercurial/dagop.py mercurial/dispatch.py mercurial/lock.py mercurial/logcmdutil.py mercurial/obsutil.py mercurial/statprof.py mercurial/templatekw.py |
diffstat | 9 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/monotone.py Tue Aug 20 17:46:17 2024 -0400 +++ b/hgext/convert/monotone.py Tue Aug 20 18:30:47 2024 -0400 @@ -8,6 +8,9 @@ import os import re +from typing import ( + Tuple, +) from mercurial.i18n import _ from mercurial.pycompat import open @@ -121,7 +124,7 @@ return self.mtnstdioreadcommandoutput(command) - def mtnstdioreadpacket(self): + def mtnstdioreadpacket(self) -> Tuple[bytes, bytes, int, bytes]: read = None commandnbr = b'' while read != b':': @@ -167,7 +170,7 @@ return (commandnbr, stream, length, read) - def mtnstdioreadcommandoutput(self, command): + def mtnstdioreadcommandoutput(self, command) -> bytes: retval = [] while True: commandnbr, stream, length, output = self.mtnstdioreadpacket()
--- a/hgext/remotefilelog/debugcommands.py Tue Aug 20 17:46:17 2024 -0400 +++ b/hgext/remotefilelog/debugcommands.py Tue Aug 20 18:30:47 2024 -0400 @@ -34,7 +34,7 @@ ) -def debugremotefilelog(ui, path, **opts): +def debugremotefilelog(ui, path, **opts) -> None: decompress = opts.get('decompress') size, firstnode, mapping = parsefileblob(path, decompress)
--- a/mercurial/dagop.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/dagop.py Tue Aug 20 18:30:47 2024 -0400 @@ -8,6 +8,9 @@ import heapq import typing +from typing import ( + List, +) from .thirdparty import attr @@ -754,7 +757,7 @@ return child -def annotate(base, parents, skiprevs=None, diffopts=None): +def annotate(base, parents, skiprevs=None, diffopts=None) -> List[annotateline]: """Core algorithm for filectx.annotate() `parents(fctx)` is a function returning a list of parent filectxs.
--- a/mercurial/dispatch.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/dispatch.py Tue Aug 20 18:30:47 2024 -0400 @@ -85,7 +85,7 @@ # store the parsed and canonical command self.canonical_command = None - def _runexithandlers(self): + def _runexithandlers(self) -> None: exc = None handlers = self.ui._exithandlers try: @@ -239,7 +239,7 @@ return status -def _rundispatch(req): +def _rundispatch(req) -> int: with tracing.log('dispatch._rundispatch'): if req.ferr: ferr = req.ferr
--- a/mercurial/lock.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/lock.py Tue Aug 20 18:30:47 2024 -0400 @@ -110,7 +110,7 @@ raiseinterrupt(assertedsigs[0]) -def trylock(ui, vfs, lockname, timeout, warntimeout, *args, **kwargs): +def trylock(ui, vfs, lockname, timeout, warntimeout, *args, **kwargs) -> "lock": """return an acquired lock or raise an a LockHeld exception This function is responsible to issue warnings and or debug messages about @@ -256,7 +256,7 @@ # wrapper around procutil.getpid() to make testing easier return procutil.getpid() - def lock(self): + def lock(self) -> int: timeout = self.timeout while True: try: @@ -272,7 +272,7 @@ errno.ETIMEDOUT, inst.filename, self.desc, inst.locker ) - def _trylock(self): + def _trylock(self) -> None: if self.held: self.held += 1 return
--- a/mercurial/logcmdutil.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/logcmdutil.py Tue Aug 20 18:30:47 2024 -0400 @@ -575,6 +575,10 @@ functions that use changesest_templater. """ + _tresources: formatter.templateresources + lastheader: Optional[bytes] + t: templater.templater + # Arguments before "buffered" used to be positional. Consider not # adding/removing arguments before "buffered" to not break callers. def __init__( @@ -665,7 +669,7 @@ self.footer = self.t.render(self._parts[b'footer'], props) -def templatespec(tmpl, mapfile): +def templatespec(tmpl, mapfile) -> formatter.templatespec: assert not (tmpl and mapfile) if mapfile: return formatter.mapfile_templatespec(b'changeset', mapfile) @@ -673,7 +677,7 @@ return formatter.literal_templatespec(tmpl) -def _lookuptemplate(ui, tmpl, style): +def _lookuptemplate(ui, tmpl, style) -> formatter.templatespec: """Find the template matching the given template spec or style See formatter.lookuptemplate() for details.
--- a/mercurial/obsutil.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/obsutil.py Tue Aug 20 18:30:47 2024 -0400 @@ -947,7 +947,7 @@ } -def _getfilteredreason(repo, changeid, ctx): +def _getfilteredreason(repo, changeid, ctx) -> bytes: """return a human-friendly string on why a obsolete changeset is hidden""" successors = successorssets(repo, ctx.node()) fate = _getobsfate(successors) @@ -974,6 +974,8 @@ args = (changeid, firstsuccessors, remainingnumber) return filteredmsgtable[b'superseded_split_several'] % args + else: + raise error.ProgrammingError("unhandled fate: %r" % fate) def divergentsets(repo, ctx):
--- a/mercurial/statprof.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/statprof.py Tue Aug 20 18:30:47 2024 -0400 @@ -113,6 +113,10 @@ import threading import time +from typing import ( + List, +) + from .pycompat import open from . import ( encoding, @@ -155,6 +159,8 @@ class ProfileState: + samples: List["Sample"] + def __init__(self, frequency=None): self.reset(frequency) self.track = b'cpu'
--- a/mercurial/templatekw.py Tue Aug 20 17:46:17 2024 -0400 +++ b/mercurial/templatekw.py Tue Aug 20 18:30:47 2024 -0400 @@ -482,7 +482,7 @@ return showlatesttags(context, mapping, None) -def showlatesttags(context, mapping, pattern): +def showlatesttags(context, mapping, pattern) -> _hybrid: """helper method for the latesttag keyword and function""" latesttags = getlatesttags(context, mapping, pattern)