@@ -7,8 +7,10 @@ from typing import Any
77from typing import BinaryIO
88from typing import Callable
99from typing import Iterator
10+ from typing import Literal
1011from typing import Protocol
1112from typing import Sequence
13+ from typing import TextIO
1214from typing import TypeVar
1315from typing import runtime_checkable
1416
@@ -26,7 +28,7 @@ class JoinablePath(ABC):
2628 @abstractmethod
2729 def with_segments (self , * pathsegments : str | Self ) -> Self : ...
2830 @abstractmethod
29- def __str__ (self ) -> str : ...
31+ def __vfspath__ (self ) -> str : ...
3032 @property
3133 def anchor (self ) -> str : ...
3234 @property
@@ -61,7 +63,7 @@ class ReadablePath(JoinablePath):
6163 @abstractmethod
6264 def info (self ) -> PathInfo : ...
6365 @abstractmethod
64- def __open_rb__ (self , buffering : int = ... ) -> BinaryIO : ...
66+ def __open_reader__ (self ) -> BinaryIO : ...
6567 def read_bytes (self ) -> bytes : ...
6668 def read_text (
6769 self ,
@@ -93,7 +95,7 @@ class WritablePath(JoinablePath):
9395 @abstractmethod
9496 def mkdir (self ) -> None : ...
9597 @abstractmethod
96- def __open_wb__ (self , buffering : int = ... ) -> BinaryIO : ...
98+ def __open_writer__ (self , mode : Literal [ "a" , "w" , "x" ] ) -> BinaryIO : ...
9799 def write_bytes (self , data : bytes ) -> int : ...
98100 def write_text (
99101 self ,
@@ -119,3 +121,26 @@ class PathInfo(Protocol):
119121 def is_dir (self , * , follow_symlinks : bool = True ) -> bool : ...
120122 def is_file (self , * , follow_symlinks : bool = True ) -> bool : ...
121123 def is_symlink (self ) -> bool : ...
124+
125+ class SupportsOpenReader (Protocol ):
126+ def __open_reader__ (self ) -> BinaryIO : ...
127+
128+ class SupportsOpenWriter (Protocol ):
129+ def __open_writer__ (self , mode : Literal ["a" , "w" , "x" ]) -> BinaryIO : ...
130+
131+ class SupportsOpenUpdater (Protocol ):
132+ def __open_updater__ (self , mode : Literal ["r+" , "w+" , "+r" , "+w" ]) -> BinaryIO : ...
133+
134+ def vfsopen (
135+ obj : SupportsOpenReader | SupportsOpenWriter | SupportsOpenUpdater ,
136+ mode = "r" ,
137+ buffering : int = - 1 ,
138+ encoding : str | None = None ,
139+ errors : str | None = None ,
140+ newline : str | None = None ,
141+ ) -> BinaryIO | TextIO : ...
142+
143+ class SupportsVFSPath (Protocol ):
144+ def __vfspath__ (self ) -> str : ...
145+
146+ def vfspath (obj : SupportsVFSPath ) -> str : ...
0 commit comments