Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/upath/types/__init__.py: 93%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

72 statements  

1from __future__ import annotations 

2 

3import enum 

4import sys 

5from collections.abc import Callable 

6from os import PathLike 

7from typing import TYPE_CHECKING 

8from typing import Any 

9from typing import Optional 

10from typing import Protocol 

11from typing import Union 

12from typing import runtime_checkable 

13 

14from upath.types._abc import JoinablePath 

15from upath.types._abc import PathInfo 

16from upath.types._abc import PathParser 

17from upath.types._abc import ReadablePath 

18from upath.types._abc import WritablePath 

19 

20if TYPE_CHECKING: 

21 

22 if sys.version_info >= (3, 12): 

23 from typing import TypeAlias 

24 else: 

25 from typing_extensions import TypeAlias 

26 

27__all__ = [ 

28 "JoinablePath", 

29 "ReadablePath", 

30 "WritablePath", 

31 "JoinablePathLike", 

32 "ReadablePathLike", 

33 "WritablePathLike", 

34 "SupportsPathLike", 

35 "PathInfo", 

36 "StatResultType", 

37 "PathParser", 

38 "UPathParser", 

39 "UNSET_DEFAULT", 

40 "OnNameCollisionFunc", 

41] 

42 

43 

44class VFSPathLike(Protocol): 

45 def __vfspath__(self) -> str: ... 

46 

47 

48SupportsPathLike: TypeAlias = Union[VFSPathLike, PathLike[str]] 

49JoinablePathLike: TypeAlias = Union[JoinablePath, SupportsPathLike, str] 

50ReadablePathLike: TypeAlias = Union[ReadablePath, SupportsPathLike, str] 

51WritablePathLike: TypeAlias = Union[WritablePath, SupportsPathLike, str] 

52 

53 

54class _DefaultValue(enum.Enum): 

55 UNSET = enum.auto() 

56 

57 

58UNSET_DEFAULT: Any = _DefaultValue.UNSET 

59 

60# We can't assume this, because pathlib_abc==0.5.1 is ahead of stdlib 3.14 

61# if sys.version_info >= (3, 14): 

62# JoinablePath.register(pathlib.PurePath) 

63# ReadablePath.register(pathlib.Path) 

64# WritablePath.register(pathlib.Path) 

65 

66 

67@runtime_checkable 

68class StatResultType(Protocol): 

69 """duck-type for os.stat_result""" 

70 

71 @property 

72 def st_mode(self) -> int: ... 

73 @property 

74 def st_ino(self) -> int: ... 

75 @property 

76 def st_dev(self) -> int: ... 

77 @property 

78 def st_nlink(self) -> int: ... 

79 @property 

80 def st_uid(self) -> int: ... 

81 @property 

82 def st_gid(self) -> int: ... 

83 @property 

84 def st_size(self) -> int: ... 

85 @property 

86 def st_atime(self) -> float: ... 

87 @property 

88 def st_mtime(self) -> float: ... 

89 @property 

90 def st_ctime(self) -> float: ... 

91 @property 

92 def st_atime_ns(self) -> int: ... 

93 @property 

94 def st_mtime_ns(self) -> int: ... 

95 @property 

96 def st_ctime_ns(self) -> int: ... 

97 

98 # st_birthtime is available on Windows (3.12+), FreeBSD, and macOS 

99 # On Linux it's currently unavailable 

100 # see: https://discuss.python.org/t/st-birthtime-not-available/104350/2 

101 if (sys.platform == "win32" and sys.version_info >= (3, 12)) or ( 

102 sys.platform == "darwin" or sys.platform.startswith("freebsd") 

103 ): 

104 

105 @property 

106 def st_birthtime(self) -> float: ... 

107 

108 

109@runtime_checkable 

110class UPathParser(PathParser, Protocol): 

111 """duck-type for upath.core.UPathParser""" 

112 

113 def split(self, path: JoinablePathLike) -> tuple[str, str]: ... 

114 def splitext(self, path: JoinablePathLike) -> tuple[str, str]: ... 

115 def normcase(self, path: JoinablePathLike) -> str: ... 

116 

117 def strip_protocol(self, path: JoinablePathLike) -> str: ... 

118 

119 def join( 

120 self, 

121 path: JoinablePathLike, 

122 *paths: JoinablePathLike, 

123 ) -> str: ... 

124 

125 def isabs(self, path: JoinablePathLike) -> bool: ... 

126 

127 def splitdrive(self, path: JoinablePathLike) -> tuple[str, str]: ... 

128 

129 def splitroot(self, path: JoinablePathLike) -> tuple[str, str, str]: ... 

130 

131 

132OnNameCollisionFunc: TypeAlias = Callable[ 

133 [ReadablePath, WritablePath], tuple[Optional[WritablePath], Optional[WritablePath]] 

134]