Skip to content

Commit 8f47637

Browse files
ymyzkmatthiaskramm
authored andcommitted
Update stub for tarfile (#1389)
1 parent 55f1883 commit 8f47637

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

stdlib/2and3/tarfile.pyi

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ from typing import (
44
Callable, IO, Iterable, Iterator, List, Mapping, Optional, Type,
55
Union,
66
)
7+
import os
78
import sys
89
from types import TracebackType
910

1011

12+
if sys.version_info >= (3, 6):
13+
_Path = Union[bytes, str, os.PathLike]
14+
elif sys.version_info >= (3,):
15+
_Path = Union[bytes, str]
16+
else:
17+
_Path = Union[str, unicode]
18+
1119
ENCODING = ... # type: str
1220

1321
USTAR_FORMAT = ... # type: int
@@ -30,7 +38,7 @@ if sys.version_info < (3,):
3038
TAR_PLAIN = ... # type: int
3139
TAR_GZIPPED = ... # type: int
3240

33-
def open(name: Optional[str] = ..., mode: str = ...,
41+
def open(name: Optional[_Path] = ..., mode: str = ...,
3442
fileobj: Optional[IO[bytes]] = ..., bufsize: int = ...,
3543
*, format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ...,
3644
dereference: Optional[bool] = ...,
@@ -43,7 +51,7 @@ def open(name: Optional[str] = ..., mode: str = ...,
4351

4452

4553
class TarFile(Iterable[TarInfo]):
46-
name = ... # type: Optional[str]
54+
name = ... # type: Optional[_Path]
4755
mode = ... # type: str
4856
fileobj = ... # type: Optional[IO[bytes]]
4957
format = ... # type: Optional[int]
@@ -57,7 +65,7 @@ class TarFile(Iterable[TarInfo]):
5765
errorlevel = ... # type: Optional[int]
5866
if sys.version_info < (3,):
5967
posix = ... # type: bool
60-
def __init__(self, name: Optional[str] = ..., mode: str = ...,
68+
def __init__(self, name: Optional[_Path] = ..., mode: str = ...,
6169
fileobj: Optional[IO[bytes]] = ...,
6270
format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ...,
6371
dereference: Optional[bool] = ...,
@@ -74,7 +82,7 @@ class TarFile(Iterable[TarInfo]):
7482
exc_tb: Optional[TracebackType]) -> bool: ...
7583
def __iter__(self) -> Iterator[TarInfo]: ...
7684
@classmethod
77-
def open(cls, name: Optional[str] = ..., mode: str = ...,
85+
def open(cls, name: Optional[_Path] = ..., mode: str = ...,
7886
fileobj: Optional[IO[bytes]] = ..., bufsize: int = ...,
7987
*, format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ...,
8088
dereference: Optional[bool] = ...,
@@ -93,22 +101,22 @@ class TarFile(Iterable[TarInfo]):
93101
def list(self, verbose: bool = ...) -> None: ...
94102
def next(self) -> Optional[TarInfo]: ...
95103
if sys.version_info >= (3, 5):
96-
def extractall(self, path: str = ...,
104+
def extractall(self, path: _Path = ...,
97105
members: Optional[List[TarInfo]] = ...,
98106
*, numeric_owner: bool = ...) -> None: ...
99107
else:
100-
def extractall(self, path: str = ...,
108+
def extractall(self, path: _Path = ...,
101109
members: Optional[List[TarInfo]] = ...) -> None: ...
102110
if sys.version_info >= (3, 5):
103-
def extract(self, member: Union[str, TarInfo], path: str = ...,
111+
def extract(self, member: Union[str, TarInfo], path: _Path = ...,
104112
set_attrs: bool = ...,
105113
*, numeric_owner: bool = ...) -> None: ...
106114
elif sys.version_info >= (3,):
107-
def extract(self, member: Union[str, TarInfo], path: str = ...,
115+
def extract(self, member: Union[str, TarInfo], path: _Path = ...,
108116
set_attrs: bool = ...) -> None: ...
109117
else:
110118
def extract(self, member: Union[str, TarInfo],
111-
path: str = ...) -> None: ...
119+
path: _Path = ...) -> None: ...
112120
def extractfile(self,
113121
member: Union[str, TarInfo]) -> Optional[IO[bytes]]: ...
114122
if sys.version_info >= (3,):

0 commit comments

Comments
 (0)