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

@@ -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 = ...,