-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
More precise return types for open(), Path.open(), bz2.open(), etc. #3371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
71506a8
6bec337
23749a6
952dc90
0335f3f
38e04fe
1619c9b
1eb282e
e6a4321
3a631c0
f924ef2
7455811
529d3b8
a4f11f1
70916ef
7bc89fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,58 @@ | ||
import io | ||
import sys | ||
from typing import Any, IO, Optional, Union | ||
from os.path import _PathType | ||
from typing import IO, Any, Optional, TextIO, Union, overload | ||
|
||
if sys.version_info >= (3, 6): | ||
from os import PathLike | ||
_PathOrFile = Union[str, bytes, IO[Any], PathLike[Any]] | ||
elif sys.version_info >= (3, 3): | ||
_PathOrFile = Union[str, bytes, IO[Any]] | ||
if sys.version_info >= (3, 8): | ||
from typing import Literal | ||
else: | ||
_PathOrFile = str | ||
from typing_extensions import Literal | ||
|
||
_PathOrFile = Union[_PathType, IO[bytes]] | ||
|
||
def compress(data: bytes, compresslevel: int = ...) -> bytes: ... | ||
def decompress(data: bytes) -> bytes: ... | ||
|
||
if sys.version_info >= (3, 3): | ||
def open(filename: _PathOrFile, | ||
mode: str = ..., | ||
compresslevel: int = ..., | ||
encoding: Optional[str] = ..., | ||
errors: Optional[str] = ..., | ||
newline: Optional[str] = ...) -> IO[Any]: ... | ||
if sys.version_info >= (3, 4): | ||
# Changed in version 3.4: The 'x' (exclusive creation) mode was added. | ||
_OpenBinaryMode = Literal["r", "rb", "w", "wb", "x", "xb", "a", "ab"] | ||
_OpenTextMode = Literal["rt", "wt", "xt", "at"] | ||
else: | ||
_OpenBinaryMode = Literal["r", "rb", "w", "wb", "a", "ab"] | ||
_OpenTextMode = Literal["rt", "wt", "at"] | ||
@overload | ||
def open( | ||
filename: _PathOrFile, | ||
mode: _OpenBinaryMode = ..., | ||
compresslevel: int = ..., | ||
encoding: None = ..., | ||
errors: None = ..., | ||
newline: None = ..., | ||
) -> BZ2File: ... | ||
@overload | ||
def open( | ||
filename: _PathType, | ||
mode: _OpenTextMode, | ||
compresslevel: int = ..., | ||
encoding: Optional[str] = ..., | ||
errors: Optional[str] = ..., | ||
newline: Optional[str] = ..., | ||
) -> TextIO: ... | ||
@overload | ||
def open( | ||
filename: _PathOrFile, | ||
mode: str, | ||
compresslevel: int = ..., | ||
encoding: Optional[str] = ..., | ||
errors: Optional[str] = ..., | ||
newline: Optional[str] = ..., | ||
) -> Union[BZ2File, TextIO]: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
class BZ2File(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#5027 | ||
def __init__(self, | ||
filename: _PathOrFile, | ||
mode: str = ..., | ||
buffering: Optional[Any] = ..., | ||
compresslevel: int = ...) -> None: ... | ||
def __init__( | ||
self, filename: _PathOrFile, mode: str = ..., buffering: Optional[Any] = ..., compresslevel: int = ... | ||
) -> None: ... | ||
|
||
class BZ2Compressor(object): | ||
def __init__(self, compresslevel: int = ...) -> None: ... | ||
|
Uh oh!
There was an error while loading. Please reload this page.