move OpenTextMode and friends to _typeshed (#4213)

This commit is contained in:
Jelle Zijlstra
2020-06-10 06:36:21 -07:00
committed by GitHub
parent 85281b636e
commit ea577cec1f
7 changed files with 50 additions and 92 deletions

View File

@@ -12,20 +12,16 @@ from typing import (
from abc import ABCMeta
from ast import mod, AST
from io import (
_OpenBinaryMode, _OpenTextMode, _OpenBinaryModeUpdating, _OpenBinaryModeWriting, _OpenBinaryModeReading,
TextIOWrapper, FileIO, BufferedRandom, BufferedReader, BufferedWriter
)
from types import TracebackType, CodeType
from _typeshed import AnyPath, OpenBinaryMode, OpenTextMode, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenBinaryModeReading
from typing_extensions import Literal
import sys
if sys.version_info >= (3,):
from typing import SupportsBytes, SupportsRound
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -1384,18 +1380,14 @@ def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
def oct(__number: Union[int, _SupportsIndex]) -> str: ...
if sys.version_info >= (3,):
if sys.version_info >= (3, 6):
# Changed in version 3.6: Support added to accept objects implementing os.PathLike.
_OpenFile = Union[str, bytes, int, _PathLike[Any]]
else:
_OpenFile = Union[str, bytes, int]
_OpenFile = Union[AnyPath, int]
_Opener = Callable[[str, int], int]
# Text mode: always returns a TextIOWrapper
@overload
def open(
file: _OpenFile,
mode: _OpenTextMode = ...,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
@@ -1408,7 +1400,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryMode,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = ...,
errors: None = ...,
@@ -1421,7 +1413,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeUpdating,
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1432,7 +1424,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeWriting,
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1443,7 +1435,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeReading,
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1456,7 +1448,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryMode,
mode: OpenBinaryMode,
buffering: int,
encoding: None = ...,
errors: None = ...,

View File

@@ -4,8 +4,7 @@
# Only a subset of functionality is included.
from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any, Union, Optional
from typing_extensions import Literal
from typing import IO, Any, Union
import _io
from _io import BlockingIOError as BlockingIOError
@@ -22,27 +21,6 @@ from _io import TextIOWrapper as TextIOWrapper
from _io import UnsupportedOperation as UnsupportedOperation
from _io import open as open
_OpenTextMode = Literal[
'r', 'r+', '+r', 'rt', 'tr', 'rt+', 'r+t', '+rt', 'tr+', 't+r', '+tr',
'w', 'w+', '+w', 'wt', 'tw', 'wt+', 'w+t', '+wt', 'tw+', 't+w', '+tw',
'a', 'a+', '+a', 'at', 'ta', 'at+', 'a+t', '+at', 'ta+', 't+a', '+ta',
'U', 'rU', 'Ur', 'rtU', 'rUt', 'Urt', 'trU', 'tUr', 'Utr',
]
_OpenBinaryModeUpdating = Literal[
'rb+', 'r+b', '+rb', 'br+', 'b+r', '+br',
'wb+', 'w+b', '+wb', 'bw+', 'b+w', '+bw',
'ab+', 'a+b', '+ab', 'ba+', 'b+a', '+ba',
]
_OpenBinaryModeWriting = Literal[
'wb', 'bw',
'ab', 'ba',
]
_OpenBinaryModeReading = Literal[
'rb', 'br',
'rbU', 'rUb', 'Urb', 'brU', 'bUr', 'Ubr',
]
_OpenBinaryMode = Union[_OpenBinaryModeUpdating, _OpenBinaryModeReading, _OpenBinaryModeWriting]
def _OpenWrapper(file: Union[str, unicode, int],
mode: unicode = ..., buffering: int = ..., encoding: unicode = ...,
errors: unicode = ..., newline: unicode = ...,

View File

@@ -14,6 +14,7 @@
import sys
from typing import Text, Union
from typing_extensions import Literal
# StrPath and AnyPath can be used in places where a
# path can be used instead of a string, starting with Python 3.6.
@@ -26,3 +27,27 @@ else:
StrPath = Text
BytesPath = bytes
AnyPath = Union[Text, bytes]
OpenTextMode = Literal[
'r', 'r+', '+r', 'rt', 'tr', 'rt+', 'r+t', '+rt', 'tr+', 't+r', '+tr',
'w', 'w+', '+w', 'wt', 'tw', 'wt+', 'w+t', '+wt', 'tw+', 't+w', '+tw',
'a', 'a+', '+a', 'at', 'ta', 'at+', 'a+t', '+at', 'ta+', 't+a', '+ta',
'x', 'x+', '+x', 'xt', 'tx', 'xt+', 'x+t', '+xt', 'tx+', 't+x', '+tx',
'U', 'rU', 'Ur', 'rtU', 'rUt', 'Urt', 'trU', 'tUr', 'Utr',
]
OpenBinaryModeUpdating = Literal[
'rb+', 'r+b', '+rb', 'br+', 'b+r', '+br',
'wb+', 'w+b', '+wb', 'bw+', 'b+w', '+bw',
'ab+', 'a+b', '+ab', 'ba+', 'b+a', '+ba',
'xb+', 'x+b', '+xb', 'bx+', 'b+x', '+bx',
]
OpenBinaryModeWriting = Literal[
'wb', 'bw',
'ab', 'ba',
'xb', 'bx',
]
OpenBinaryModeReading = Literal[
'rb', 'br',
'rbU', 'rUb', 'Urb', 'brU', 'bUr', 'Ubr',
]
OpenBinaryMode = Union[OpenBinaryModeUpdating, OpenBinaryModeReading, OpenBinaryModeWriting]

View File

@@ -12,20 +12,16 @@ from typing import (
from abc import ABCMeta
from ast import mod, AST
from io import (
_OpenBinaryMode, _OpenTextMode, _OpenBinaryModeUpdating, _OpenBinaryModeWriting, _OpenBinaryModeReading,
TextIOWrapper, FileIO, BufferedRandom, BufferedReader, BufferedWriter
)
from types import TracebackType, CodeType
from _typeshed import AnyPath, OpenBinaryMode, OpenTextMode, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenBinaryModeReading
from typing_extensions import Literal
import sys
if sys.version_info >= (3,):
from typing import SupportsBytes, SupportsRound
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -1384,18 +1380,14 @@ def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
def oct(__number: Union[int, _SupportsIndex]) -> str: ...
if sys.version_info >= (3,):
if sys.version_info >= (3, 6):
# Changed in version 3.6: Support added to accept objects implementing os.PathLike.
_OpenFile = Union[str, bytes, int, _PathLike[Any]]
else:
_OpenFile = Union[str, bytes, int]
_OpenFile = Union[AnyPath, int]
_Opener = Callable[[str, int], int]
# Text mode: always returns a TextIOWrapper
@overload
def open(
file: _OpenFile,
mode: _OpenTextMode = ...,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
@@ -1408,7 +1400,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryMode,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = ...,
errors: None = ...,
@@ -1421,7 +1413,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeUpdating,
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1432,7 +1424,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeWriting,
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1443,7 +1435,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryModeReading,
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
@@ -1456,7 +1448,7 @@ if sys.version_info >= (3,):
@overload
def open(
file: _OpenFile,
mode: _OpenBinaryMode,
mode: OpenBinaryMode,
buffering: int,
encoding: None = ...,
errors: None = ...,

View File

@@ -7,11 +7,6 @@ import sys
from mmap import mmap
from types import TracebackType
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
_bytearray_like = Union[bytearray, mmap]
DEFAULT_BUFFER_SIZE: int
@@ -22,30 +17,6 @@ SEEK_END: int
_T = TypeVar('_T', bound=IOBase)
_OpenTextMode = Literal[
'r', 'r+', '+r', 'rt', 'tr', 'rt+', 'r+t', '+rt', 'tr+', 't+r', '+tr',
'w', 'w+', '+w', 'wt', 'tw', 'wt+', 'w+t', '+wt', 'tw+', 't+w', '+tw',
'a', 'a+', '+a', 'at', 'ta', 'at+', 'a+t', '+at', 'ta+', 't+a', '+ta',
'x', 'x+', '+x', 'xt', 'tx', 'xt+', 'x+t', '+xt', 'tx+', 't+x', '+tx',
'U', 'rU', 'Ur', 'rtU', 'rUt', 'Urt', 'trU', 'tUr', 'Utr',
]
_OpenBinaryModeUpdating = Literal[
'rb+', 'r+b', '+rb', 'br+', 'b+r', '+br',
'wb+', 'w+b', '+wb', 'bw+', 'b+w', '+bw',
'ab+', 'a+b', '+ab', 'ba+', 'b+a', '+ba',
'xb+', 'x+b', '+xb', 'bx+', 'b+x', '+bx',
]
_OpenBinaryModeWriting = Literal[
'wb', 'bw',
'ab', 'ba',
'xb', 'bx',
]
_OpenBinaryModeReading = Literal[
'rb', 'br',
'rbU', 'rUb', 'Urb', 'brU', 'bUr', 'Ubr',
]
_OpenBinaryMode = Union[_OpenBinaryModeUpdating, _OpenBinaryModeReading, _OpenBinaryModeWriting]
open = builtins.open
if sys.version_info >= (3, 8):

View File

@@ -1,4 +1,4 @@
from io import _OpenBinaryMode, _OpenTextMode
from _typeshed import OpenBinaryMode, OpenTextMode
from typing import (Any, BinaryIO, Generator, IO, List, Optional, Sequence,
TextIO, Tuple, Type, TypeVar, Union, overload)
from types import TracebackType
@@ -100,10 +100,10 @@ class Path(PurePath):
def mkdir(self, mode: int = ..., parents: bool = ...,
exist_ok: bool = ...) -> None: ...
@overload
def open(self, mode: _OpenTextMode = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,
def open(self, mode: OpenTextMode = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,
newline: Optional[str] = ...) -> TextIO: ...
@overload
def open(self, mode: _OpenBinaryMode, buffering: int = ..., encoding: None = ..., errors: None = ...,
def open(self, mode: OpenBinaryMode, buffering: int = ..., encoding: None = ..., errors: None = ...,
newline: None = ...) -> BinaryIO: ...
@overload
def open(self, mode: str, buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,

View File

@@ -1,4 +1,4 @@
from io import _OpenBinaryMode, _OpenTextMode
from _typeshed import OpenBinaryMode, OpenTextMode
from typing import (Any, BinaryIO, Generator, IO, List, Optional, Sequence,
TextIO, Tuple, Type, TypeVar, Union, overload)
from types import TracebackType
@@ -100,10 +100,10 @@ class Path(PurePath):
def mkdir(self, mode: int = ..., parents: bool = ...,
exist_ok: bool = ...) -> None: ...
@overload
def open(self, mode: _OpenTextMode = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,
def open(self, mode: OpenTextMode = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,
newline: Optional[str] = ...) -> TextIO: ...
@overload
def open(self, mode: _OpenBinaryMode, buffering: int = ..., encoding: None = ..., errors: None = ...,
def open(self, mode: OpenBinaryMode, buffering: int = ..., encoding: None = ..., errors: None = ...,
newline: None = ...) -> BinaryIO: ...
@overload
def open(self, mode: str, buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ...,