##// END OF EJS Templates
typing: add type annotations to the `mercurial.util.filestat` class...
Matt Harbison -
r52780:1d95a878 default
parent child Browse files
Show More
@@ -45,6 +45,8 from typing import (
45 45 List,
46 46 Optional,
47 47 Tuple,
48 Type,
49 TypeVar,
48 50 )
49 51
50 52 from .node import hex
@@ -159,6 +161,10 unlink = platform.unlink
159 161 username = platform.username
160 162
161 163
164 if typing.TYPE_CHECKING:
165 _Tfilestat = TypeVar('_Tfilestat', bound='filestat')
166
167
162 168 def setumask(val: int) -> None:
163 169 '''updates the umask. used by chg server'''
164 170 if pycompat.iswindows:
@@ -2491,11 +2497,11 class filestat:
2491 2497 'exists()' examination on client side of this class.
2492 2498 """
2493 2499
2494 def __init__(self, stat):
2500 def __init__(self, stat: Optional[os.stat_result]) -> None:
2495 2501 self.stat = stat
2496 2502
2497 2503 @classmethod
2498 def frompath(cls, path):
2504 def frompath(cls: Type[_Tfilestat], path: bytes) -> _Tfilestat:
2499 2505 try:
2500 2506 stat = os.stat(path)
2501 2507 except FileNotFoundError:
@@ -2503,13 +2509,13 class filestat:
2503 2509 return cls(stat)
2504 2510
2505 2511 @classmethod
2506 def fromfp(cls, fp):
2512 def fromfp(cls: Type[_Tfilestat], fp: BinaryIO) -> _Tfilestat:
2507 2513 stat = os.fstat(fp.fileno())
2508 2514 return cls(stat)
2509 2515
2510 2516 __hash__ = object.__hash__
2511 2517
2512 def __eq__(self, old):
2518 def __eq__(self, old) -> bool:
2513 2519 try:
2514 2520 # if ambiguity between stat of new and old file is
2515 2521 # avoided, comparison of size, ctime and mtime is enough
@@ -2526,7 +2532,7 class filestat:
2526 2532 except AttributeError:
2527 2533 return False
2528 2534
2529 def isambig(self, old):
2535 def isambig(self, old: _Tfilestat) -> bool:
2530 2536 """Examine whether new (= self) stat is ambiguous against old one
2531 2537
2532 2538 "S[N]" below means stat of a file at N-th change:
@@ -2561,7 +2567,7 class filestat:
2561 2567 except AttributeError:
2562 2568 return False
2563 2569
2564 def avoidambig(self, path, old):
2570 def avoidambig(self, path: bytes, old: _Tfilestat) -> bool:
2565 2571 """Change file stat of specified path to avoid ambiguity
2566 2572
2567 2573 'old' should be previous filestat of 'path'.
@@ -2581,7 +2587,7 class filestat:
2581 2587 return False
2582 2588 return True
2583 2589
2584 def __ne__(self, other):
2590 def __ne__(self, other) -> bool:
2585 2591 return not self == other
2586 2592
2587 2593
General Comments 0
You need to be logged in to leave comments. Login now