Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pathutil.py @ 51304:f15cb5111a1e
pytype: move some type comment to proper annotation
We support direct type annotations now, while pytype is starting to complains
about them.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 19 Dec 2023 21:29:34 +0100 |
parents | 9d3721552b6c |
children | 8b2ea2246a5f |
line wrap: on
line diff
--- a/mercurial/pathutil.py Wed Dec 20 20:13:22 2023 +0100 +++ b/mercurial/pathutil.py Tue Dec 19 21:29:34 2023 +0100 @@ -32,8 +32,7 @@ ] -def _lowerclean(s): - # type: (bytes) -> bytes +def _lowerclean(s: bytes) -> bytes: return encoding.hfsignoreclean(s.lower()) @@ -72,8 +71,7 @@ else: self.normcase = lambda x: x - def __call__(self, path, mode=None): - # type: (bytes, Optional[Any]) -> None + def __call__(self, path: bytes, mode: Optional[Any] = None) -> None: """Check the relative path. path may contain a pattern (e.g. foodir/**.txt)""" @@ -170,8 +168,7 @@ raise error.Abort(msg % (path, pycompat.bytestr(prefix))) return True - def check(self, path): - # type: (bytes) -> bool + def check(self, path: bytes) -> bool: try: self(path) return True @@ -192,8 +189,12 @@ self._cached = False -def canonpath(root, cwd, myname, auditor=None): - # type: (bytes, bytes, bytes, Optional[pathauditor]) -> bytes +def canonpath( + root: bytes, + cwd: bytes, + myname: bytes, + auditor: Optional[pathauditor] = None, +) -> bytes: """return the canonical path of myname, given cwd and root >>> def check(root, cwd, myname): @@ -295,8 +296,7 @@ ) -def normasprefix(path): - # type: (bytes) -> bytes +def normasprefix(path: bytes) -> bytes: """normalize the specified path as path prefix Returned value can be used safely for "p.startswith(prefix)", @@ -319,8 +319,7 @@ return path -def finddirs(path): - # type: (bytes) -> Iterator[bytes] +def finddirs(path: bytes) -> Iterator[bytes]: pos = path.rfind(b'/') while pos != -1: yield path[:pos] @@ -355,8 +354,7 @@ for f in map: addpath(f) - def addpath(self, path): - # type: (bytes) -> None + def addpath(self, path: bytes) -> None: dirs = self._dirs for base in finddirs(path): if base.endswith(b'/'): @@ -368,8 +366,7 @@ return dirs[base] = 1 - def delpath(self, path): - # type: (bytes) -> None + def delpath(self, path: bytes) -> None: dirs = self._dirs for base in finddirs(path): if dirs[base] > 1: @@ -380,8 +377,7 @@ def __iter__(self): return iter(self._dirs) - def __contains__(self, d): - # type: (bytes) -> bool + def __contains__(self, d: bytes) -> bool: return d in self._dirs