# HG changeset patch # User Yuya Nishihara # Date 1573889128 -32400 # Node ID da925257a39e5797e5b2e35ce1d68e923ea8ddf2 # Parent 009c115eba95b4cff1d998007991045afb771e2a typing: add pseudo localstr.__init__() to help pytype Apparently, pytype failed to parse localstr.__new__()? This fixes the following errors: line 126, in __hash__: No attribute '_utf8' on localstr [attribute-error] line 188, in tolocal: Function localstr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, string: str, ...) Actually passed: (self, string: bytes, ...) diff -r 009c115eba95 -r da925257a39e mercurial/encoding.py --- a/mercurial/encoding.py Sat Nov 16 15:24:49 2019 +0900 +++ b/mercurial/encoding.py Sat Nov 16 16:25:28 2019 +0900 @@ -20,11 +20,14 @@ from .pure import charencode as charencodepure +_TYPE_CHECKING = False + if not globals(): # hide this from non-pytype users from typing import ( Any, Callable, List, + TYPE_CHECKING as _TYPE_CHECKING, Text, Type, TypeVar, @@ -117,11 +120,17 @@ round-tripped to the local encoding and back''' def __new__(cls, u, l): - # type: (Type[_Tlocalstr], bytes, bytes) -> _Tlocalstr s = bytes.__new__(cls, l) s._utf8 = u return s + if _TYPE_CHECKING: + # pseudo implementation to help pytype see localstr() constructor + def __init__(self, u, l): + # type: (bytes, bytes) -> None + super(localstr, self).__init__(l) + self._utf8 = u + def __hash__(self): return hash(self._utf8) # avoid collisions in local string space