author | Matt Harbison <matt_harbison@yahoo.com> |
Fri, 20 Sep 2024 00:04:09 -0400 | |
changeset 51887 | 1d95a87813ad |
parent 51886 | e59e1d8d29d2 |
child 51888 | f833ad92ee44 |
mercurial/util.py | file | annotate | diff | comparison | revisions |
--- a/mercurial/util.py Fri Sep 20 12:15:08 2024 -0400 +++ b/mercurial/util.py Fri Sep 20 00:04:09 2024 -0400 @@ -45,6 +45,8 @@ List, Optional, Tuple, + Type, + TypeVar, ) from .node import hex @@ -159,6 +161,10 @@ username = platform.username +if typing.TYPE_CHECKING: + _Tfilestat = TypeVar('_Tfilestat', bound='filestat') + + def setumask(val: int) -> None: '''updates the umask. used by chg server''' if pycompat.iswindows: @@ -2491,11 +2497,11 @@ 'exists()' examination on client side of this class. """ - def __init__(self, stat): + def __init__(self, stat: Optional[os.stat_result]) -> None: self.stat = stat @classmethod - def frompath(cls, path): + def frompath(cls: Type[_Tfilestat], path: bytes) -> _Tfilestat: try: stat = os.stat(path) except FileNotFoundError: @@ -2503,13 +2509,13 @@ return cls(stat) @classmethod - def fromfp(cls, fp): + def fromfp(cls: Type[_Tfilestat], fp: BinaryIO) -> _Tfilestat: stat = os.fstat(fp.fileno()) return cls(stat) __hash__ = object.__hash__ - def __eq__(self, old): + def __eq__(self, old) -> bool: try: # if ambiguity between stat of new and old file is # avoided, comparison of size, ctime and mtime is enough @@ -2526,7 +2532,7 @@ except AttributeError: return False - def isambig(self, old): + def isambig(self, old: _Tfilestat) -> bool: """Examine whether new (= self) stat is ambiguous against old one "S[N]" below means stat of a file at N-th change: @@ -2561,7 +2567,7 @@ except AttributeError: return False - def avoidambig(self, path, old): + def avoidambig(self, path: bytes, old: _Tfilestat) -> bool: """Change file stat of specified path to avoid ambiguity 'old' should be previous filestat of 'path'. @@ -2581,7 +2587,7 @@ return False return True - def __ne__(self, other): + def __ne__(self, other) -> bool: return not self == other