@@ -5,12 +5,13 @@ from typing import (
55 TypeVar , Iterator , Iterable , NoReturn , overload , Container ,
66 Sequence , MutableSequence , Mapping , MutableMapping , Tuple , List , Any , Dict , Callable , Generic ,
77 Set , AbstractSet , FrozenSet , MutableSet , Sized , Reversible , SupportsInt , SupportsFloat , SupportsAbs ,
8- SupportsComplex , IO , BinaryIO , Union ,
8+ SupportsComplex , IO , BinaryIO , TextIO , Union ,
99 ItemsView , KeysView , ValuesView , ByteString , Optional , AnyStr , Type , Text ,
1010 Protocol ,
1111)
1212from abc import abstractmethod , ABCMeta
1313from ast import mod , AST
14+ from io import _OpenBinaryMode , _OpenTextMode
1415from types import TracebackType , CodeType
1516import sys
1617
@@ -1357,14 +1358,47 @@ def next(__i: Iterator[_T]) -> _T: ...
13571358def next (__i : Iterator [_T ], default : _VT ) -> Union [_T , _VT ]: ...
13581359def oct (__number : Union [int , _SupportsIndex ]) -> str : ...
13591360
1360- if sys .version_info >= (3 , 6 ):
1361- def open (file : Union [str , bytes , int , _PathLike [Any ]], mode : str = ..., buffering : int = ..., encoding : Optional [str ] = ...,
1362- errors : Optional [str ] = ..., newline : Optional [str ] = ..., closefd : bool = ...,
1363- opener : Optional [Callable [[str , int ], int ]] = ...) -> IO [Any ]: ...
1364- elif sys .version_info >= (3 ,):
1365- def open (file : Union [str , bytes , int ], mode : str = ..., buffering : int = ..., encoding : Optional [str ] = ...,
1366- errors : Optional [str ] = ..., newline : Optional [str ] = ..., closefd : bool = ...,
1367- opener : Optional [Callable [[str , int ], int ]] = ...) -> IO [Any ]: ...
1361+ if sys .version_info >= (3 ,):
1362+ if sys .version_info >= (3 , 6 ):
1363+ # Changed in version 3.6: Support added to accept objects implementing os.PathLike.
1364+ _OpenFile = Union [str , bytes , int , _PathLike [Any ]]
1365+ else :
1366+ _OpenFile = Union [str , bytes , int ]
1367+
1368+ @overload
1369+ def open (
1370+ file : _OpenFile ,
1371+ mode : _OpenTextMode = ...,
1372+ buffering : int = ...,
1373+ encoding : Optional [str ] = ...,
1374+ errors : Optional [str ] = ...,
1375+ newline : Optional [str ] = ...,
1376+ closefd : bool = ...,
1377+ opener : Optional [Callable [[str , int ], int ]] = ...,
1378+ ) -> TextIO : ...
1379+ @overload
1380+ def open (
1381+ file : _OpenFile ,
1382+ mode : _OpenBinaryMode ,
1383+ buffering : int = ...,
1384+ encoding : None = ...,
1385+ errors : None = ...,
1386+ newline : None = ...,
1387+ closefd : bool = ...,
1388+ opener : Optional [Callable [[str , int ], int ]] = ...,
1389+ ) -> BinaryIO : ...
1390+ @overload
1391+ def open (
1392+ file : _OpenFile ,
1393+ mode : str ,
1394+ buffering : int = ...,
1395+ encoding : Optional [str ] = ...,
1396+ errors : Optional [str ] = ...,
1397+ newline : Optional [str ] = ...,
1398+ closefd : bool = ...,
1399+ opener : Optional [Callable [[str , int ], int ]] = ...,
1400+ ) -> IO [Any ]: ...
1401+
13681402else :
13691403 def open (name : Union [unicode , int ], mode : unicode = ..., buffering : int = ...) -> BinaryIO : ...
13701404
0 commit comments