# HG changeset patch # User Pierre-Yves David # Date 2023-12-20 10:23:09 # Node ID 8b2ea2246a5f790da4ccbdfb56f3e3b5bde53625 # Parent f15cb5111a1e4f7eb2e4c42e22ce0aad306884e2 pytype: convert type comment for inline variable too Same logic as for the previous changeset, but for "type comment" annotating variables, not function/method. As for the previous changeset, we had to adjust for of the types to actually match what was happening. diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py --- a/mercurial/chgserver.py +++ b/mercurial/chgserver.py @@ -48,6 +48,10 @@ import stat import struct import time +from typing import ( + Optional, +) + from .i18n import _ from .node import hex @@ -628,14 +632,16 @@ class chgunixservicehandler: pollinterval = 1 # [sec] + _hashstate: Optional[hashstate] + _baseaddress: Optional[bytes] + _realaddress: Optional[bytes] + def __init__(self, ui): self.ui = ui - # TODO: use PEP 526 syntax (`_hashstate: hashstate` at the class level) - # when 3.5 support is dropped. - self._hashstate = None # type: hashstate - self._baseaddress = None # type: bytes - self._realaddress = None # type: bytes + self._hashstate = None + self._baseaddress = None + self._realaddress = None self._idletimeout = ui.configint(b'chgserver', b'idletimeout') self._lastactive = time.time() diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -57,7 +57,7 @@ class Hint: """ def __init__(self, *args, **kw): - self.hint = kw.pop('hint', None) # type: Optional[bytes] + self.hint: Optional[bytes] = kw.pop('hint', None) super(Hint, self).__init__(*args, **kw) diff --git a/mercurial/i18n.py b/mercurial/i18n.py --- a/mercurial/i18n.py +++ b/mercurial/i18n.py @@ -89,7 +89,7 @@ def gettext(message: bytes) -> bytes: if message not in cache: if type(message) is str: # goofy unicode docstrings in test - paragraphs = message.split(u'\n\n') # type: List[str] + paragraphs: List[str] = message.split(u'\n\n') else: # should be ascii, but we have unicode docstrings in test, which # are converted to utf-8 bytes on Python 3. diff --git a/mercurial/pathutil.py b/mercurial/pathutil.py --- a/mercurial/pathutil.py +++ b/mercurial/pathutil.py @@ -392,4 +392,4 @@ if rustdirs is not None: # rather not let our internals know that we're thinking in posix terms # - instead we'll let them be oblivious. join = posixpath.join -dirname = posixpath.dirname # type: Callable[[bytes], bytes] +dirname: Callable[[bytes], bytes] = posixpath.dirname diff --git a/mercurial/phases.py b/mercurial/phases.py --- a/mercurial/phases.py +++ b/mercurial/phases.py @@ -163,7 +163,9 @@ if typing.TYPE_CHECKING: _fphasesentry = struct.Struct(b'>i20s') # record phase index -public, draft, secret = range(3) # type: int +public: int = 0 +draft: int = 1 +secret: int = 2 archived = 32 # non-continuous for compatibility internal = 96 # non-continuous for compatibility allphases = (public, draft, secret, archived, internal) diff --git a/mercurial/upgrade_utils/actions.py b/mercurial/upgrade_utils/actions.py --- a/mercurial/upgrade_utils/actions.py +++ b/mercurial/upgrade_utils/actions.py @@ -108,7 +108,7 @@ class improvement: compatible_with_share = False -allformatvariant = [] # type: List[Type['formatvariant']] +allformatvariant: List[Type['formatvariant']] = [] def registerformatvariant(cls):