# HG changeset patch # User Matt Harbison # Date 2024-08-20 22:30:47 # Node ID 460e80488cf0bb4695c5f4bb760c086c49606261 # Parent f1ef512e14abf7aff799b7afd4ee4d3e8f80f226 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.) diff --git a/hgext/convert/monotone.py b/hgext/convert/monotone.py --- a/hgext/convert/monotone.py +++ b/hgext/convert/monotone.py @@ -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 @@ class monotone_source(common.converter_s 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 @@ class monotone_source(common.converter_s return (commandnbr, stream, length, read) - def mtnstdioreadcommandoutput(self, command): + def mtnstdioreadcommandoutput(self, command) -> bytes: retval = [] while True: commandnbr, stream, length, output = self.mtnstdioreadpacket() diff --git a/hgext/remotefilelog/debugcommands.py b/hgext/remotefilelog/debugcommands.py --- a/hgext/remotefilelog/debugcommands.py +++ b/hgext/remotefilelog/debugcommands.py @@ -34,7 +34,7 @@ from . import ( ) -def debugremotefilelog(ui, path, **opts): +def debugremotefilelog(ui, path, **opts) -> None: decompress = opts.get('decompress') size, firstnode, mapping = parsefileblob(path, decompress) diff --git a/mercurial/dagop.py b/mercurial/dagop.py --- a/mercurial/dagop.py +++ b/mercurial/dagop.py @@ -8,6 +8,9 @@ import heapq import typing +from typing import ( + List, +) from .thirdparty import attr @@ -754,7 +757,7 @@ def _annotatepair(parents, childfctx, ch 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. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -85,7 +85,7 @@ class request: # 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 @@ def dispatch(req): return status -def _rundispatch(req): +def _rundispatch(req) -> int: with tracing.log('dispatch._rundispatch'): if req.ferr: ferr = req.ferr diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -110,7 +110,7 @@ def _delayedinterrupt(): 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 @@ class lock: # 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 @@ class lock: errno.ETIMEDOUT, inst.filename, self.desc, inst.locker ) - def _trylock(self): + def _trylock(self) -> None: if self.held: self.held += 1 return diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -575,6 +575,10 @@ class changesettemplater(changesetprinte 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 @@ class changesettemplater(changesetprinte 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 @@ def templatespec(tmpl, mapfile): 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. diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py --- a/mercurial/obsutil.py +++ b/mercurial/obsutil.py @@ -947,7 +947,7 @@ filteredmsgtable = { } -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 @@ def _getfilteredreason(repo, changeid, c args = (changeid, firstsuccessors, remainingnumber) return filteredmsgtable[b'superseded_split_several'] % args + else: + raise error.ProgrammingError("unhandled fate: %r" % fate) def divergentsets(repo, ctx): diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -113,6 +113,10 @@ import sys import threading import time +from typing import ( + List, +) + from .pycompat import open from . import ( encoding, @@ -155,6 +159,8 @@ def clock(): class ProfileState: + samples: List["Sample"] + def __init__(self, frequency=None): self.reset(frequency) self.track = b'cpu' diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -482,7 +482,7 @@ def showlatesttag(context, mapping): 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)