Mercurial > hg-stable
comparison mercurial/vfs.py @ 51931:992fcf6b2473
typing: add a handful more annotations to `mercurial/vfs.py`
These came out of refactoring into a protocol class, but they can stand on their
own.
The `audit` callback is kinda screwy because the internal lambda and the callable
for `pathutil.pathauditor` have different args and a different return type. It's
conditionalized where it is called, and can be cleaned up later if desired.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 23 Sep 2024 14:58:37 -0400 |
parents | 22e1924e9402 |
children |
comparison
equal
deleted
inserted
replaced
51930:22e1924e9402 | 51931:992fcf6b2473 |
---|---|
17 | 17 |
18 from typing import ( | 18 from typing import ( |
19 Any, | 19 Any, |
20 BinaryIO, | 20 BinaryIO, |
21 Callable, | 21 Callable, |
22 Dict, | |
22 Iterable, | 23 Iterable, |
23 Iterator, | 24 Iterator, |
24 List, | 25 List, |
25 MutableMapping, | 26 MutableMapping, |
26 Optional, | 27 Optional, |
27 Tuple, | 28 Tuple, |
28 Type, | 29 Type, |
29 TypeVar, | 30 TypeVar, |
31 Union, | |
30 ) | 32 ) |
31 | 33 |
32 from .i18n import _ | 34 from .i18n import _ |
33 from . import ( | 35 from . import ( |
34 encoding, | 36 encoding, |
453 'cacheaudited' should be enabled only if (a) vfs object is short-lived, or | 455 'cacheaudited' should be enabled only if (a) vfs object is short-lived, or |
454 (b) the base directory is managed by hg and considered sort-of append-only. | 456 (b) the base directory is managed by hg and considered sort-of append-only. |
455 See pathutil.pathauditor() for details. | 457 See pathutil.pathauditor() for details. |
456 """ | 458 """ |
457 | 459 |
460 audit: Union[pathutil.pathauditor, Callable[[bytes, Optional[bytes]], Any]] | |
461 base: bytes | |
458 createmode: Optional[int] | 462 createmode: Optional[int] |
463 options: Dict[bytes, Any] | |
464 _audit: bool | |
465 _trustnlink: Optional[bool] | |
459 | 466 |
460 def __init__( | 467 def __init__( |
461 self, | 468 self, |
462 base: bytes, | 469 base: bytes, |
463 audit: bool = True, | 470 audit: bool = True, |
686 | 693 |
687 def _auditpath(self, path: bytes, mode: bytes) -> None: | 694 def _auditpath(self, path: bytes, mode: bytes) -> None: |
688 return self.vfs._auditpath(path, mode) | 695 return self.vfs._auditpath(path, mode) |
689 | 696 |
690 @property | 697 @property |
691 def options(self): | 698 def options(self) -> Dict[bytes, Any]: |
692 return self.vfs.options | 699 return self.vfs.options |
693 | 700 |
694 @options.setter | 701 @options.setter |
695 def options(self, value): | 702 def options(self, value: Dict[bytes, Any]) -> None: |
696 self.vfs.options = value | 703 self.vfs.options = value |
697 | 704 |
698 @property | 705 @property |
699 def audit(self): | 706 def audit(self): |
700 return self.vfs.audit | 707 return self.vfs.audit |
701 | 708 |
702 | 709 |
703 class filtervfs(proxyvfs, abstractvfs): | 710 class filtervfs(proxyvfs, abstractvfs): |
704 '''Wrapper vfs for filtering filenames with a function.''' | 711 '''Wrapper vfs for filtering filenames with a function.''' |
705 | 712 |
706 def __init__(self, vfs: vfs, filter) -> None: | 713 def __init__(self, vfs: vfs, filter: Callable[[bytes], bytes]) -> None: |
707 proxyvfs.__init__(self, vfs) | 714 proxyvfs.__init__(self, vfs) |
708 self._filter = filter | 715 self._filter = filter |
709 | 716 |
710 # TODO: The return type should be BinaryIO | 717 # TODO: The return type should be BinaryIO |
711 def __call__(self, path: bytes, *args, **kwargs) -> Any: | 718 def __call__(self, path: bytes, *args, **kwargs) -> Any: |