@@ -3,6 +3,7 @@ import sys
33import types
44from abc import ABCMeta , abstractmethod
55from typing import IO , Any , Iterator , Mapping , Optional , Sequence , Tuple , Union
6+ from typing_extensions import Literal
67
78# Loader is exported from this module, but for circular import reasons
89# exists in its own stub file (with ModuleSpec and ModuleType).
@@ -70,3 +71,27 @@ if sys.version_info >= (3, 7):
7071 def is_resource (self , name : str ) -> bool : ...
7172 @abstractmethod
7273 def contents (self ) -> Iterator [str ]: ...
74+
75+ if sys .version_info >= (3 , 9 ):
76+ from typing import Protocol , runtime_checkable
77+ @runtime_checkable
78+ class Traversable (Protocol ):
79+ @abstractmethod
80+ def iterdir (self ) -> Iterator [Traversable ]: ...
81+ @abstractmethod
82+ def read_bytes (self ) -> bytes : ...
83+ @abstractmethod
84+ def read_text (self , encoding : Optional [str ] = ...) -> str : ...
85+ @abstractmethod
86+ def is_dir (self ) -> bool : ...
87+ @abstractmethod
88+ def is_file (self ) -> bool : ...
89+ @abstractmethod
90+ def joinpath (self , child : Traversable ) -> Traversable : ...
91+ @abstractmethod
92+ def __truediv__ (self , child : Traversable ) -> Traversable : ...
93+ @abstractmethod
94+ def open (self , mode : Literal ["r" , "rb" ] = ..., * args : Any , ** kwargs : Any ) -> IO : ...
95+ @property
96+ @abstractmethod
97+ def name (self ) -> str : ...
0 commit comments