Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions stdlib/@python2/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra,
def __setitem__(self, __k: _KT_contra, __v: _VT) -> None: ...
def __delitem__(self, __v: _KT_contra) -> None: ...

# StrPath and AnyPath can be used in places where a
# path can be used instead of a string, starting with Python 3.6.
# These aliases can be used in places where a PathLike object can be used
# instead of a string in Python 3.
StrPath = Text
BytesPath = bytes
AnyPath = Union[Text, bytes]
BytesPath = str
StrOrBytesPath = Text
AnyPath = StrOrBytesPath # obsolete, will be removed soon

OpenTextModeUpdating = Literal[
"r+",
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/bz2.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import io
from _typeshed import AnyPath, ReadableBuffer, WriteableBuffer
from typing import IO, Any, Iterable, List, Optional, TypeVar, Union
from _typeshed import ReadableBuffer, WriteableBuffer
from typing import IO, Any, Iterable, List, Optional, Text, TypeVar, Union

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use unicode instead of Text in Python 2?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we agreed at some point that semantically Text means str or unicode and unicode means just unicode.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information about this is all a bit hidden, but unicode and str are not compatible on all type checkers (e.g. pytype). Therefore the following can fail to type check:

def foo(x: unicode): ...
foo("")

But PEP 484 also says:

For parameters typed as Text, arguments of type str as well as unicode should be acceptable.

So the following checks on all type checkers:

def foo(x: Text): ...
foo("")

from typing_extensions import SupportsIndex

_PathOrFile = Union[AnyPath, IO[bytes]]
_PathOrFile = Union[Text, IO[bytes]]
_T = TypeVar("_T")

def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
Expand Down
5 changes: 2 additions & 3 deletions stdlib/@python2/cProfile.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from _typeshed import AnyPath
from types import CodeType
from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, Union
from typing import Any, Callable, Dict, Optional, Text, Tuple, TypeVar, Union

def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...
def runctx(
Expand All @@ -19,7 +18,7 @@ class Profile:
def enable(self) -> None: ...
def disable(self) -> None: ...
def print_stats(self, sort: Union[str, int] = ...) -> None: ...
def dump_stats(self, file: AnyPath) -> None: ...
def dump_stats(self, file: Text) -> None: ...
def create_stats(self) -> None: ...
def snapshot_stats(self) -> None: ...
def run(self: _SelfT, cmd: str) -> _SelfT: ...
Expand Down
7 changes: 3 additions & 4 deletions stdlib/@python2/cgitb.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from _typeshed import AnyPath
from types import FrameType, TracebackType
from typing import IO, Any, Callable, Dict, List, Optional, Tuple, Type
from typing import IO, Any, Callable, Dict, List, Optional, Text, Tuple, Type

_ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]

Expand All @@ -19,7 +18,7 @@ class Hook: # undocumented
def __init__(
self,
display: int = ...,
logdir: Optional[AnyPath] = ...,
logdir: Optional[Text] = ...,
context: int = ...,
file: Optional[IO[str]] = ...,
format: str = ...,
Expand All @@ -30,4 +29,4 @@ class Hook: # undocumented
def handle(self, info: Optional[_ExcInfo] = ...) -> None: ...

def handler(info: Optional[_ExcInfo] = ...) -> None: ...
def enable(display: int = ..., logdir: Optional[AnyPath] = ..., context: int = ..., format: str = ...) -> None: ...
def enable(display: int = ..., logdir: Optional[Text] = ..., context: int = ..., format: str = ...) -> None: ...
9 changes: 4 additions & 5 deletions stdlib/@python2/compileall.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from _typeshed import AnyPath
from typing import Any, Optional, Pattern
from typing import Any, Optional, Pattern, Text

# rx can be any object with a 'search' method; once we have Protocols we can change the type
def compile_dir(
dir: AnyPath,
dir: Text,
maxlevels: int = ...,
ddir: Optional[AnyPath] = ...,
ddir: Optional[Text] = ...,
force: bool = ...,
rx: Optional[Pattern[Any]] = ...,
quiet: int = ...,
) -> int: ...
def compile_file(
fullname: AnyPath, ddir: Optional[AnyPath] = ..., force: bool = ..., rx: Optional[Pattern[Any]] = ..., quiet: int = ...
fullname: Text, ddir: Optional[Text] = ..., force: bool = ..., rx: Optional[Pattern[Any]] = ..., quiet: int = ...
) -> int: ...
def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ...) -> int: ...
15 changes: 7 additions & 8 deletions stdlib/@python2/fileinput.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from _typeshed import AnyPath
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Union
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Text, Union

def input(
files: Union[AnyPath, Iterable[AnyPath], None] = ...,
files: Union[Text, Iterable[Text], None] = ...,
inplace: bool = ...,
backup: str = ...,
bufsize: int = ...,
mode: str = ...,
openhook: Callable[[AnyPath, str], IO[AnyStr]] = ...,
openhook: Callable[[Text, str], IO[AnyStr]] = ...,
) -> FileInput[AnyStr]: ...
def close() -> None: ...
def nextfile() -> None: ...
Expand All @@ -21,12 +20,12 @@ def isstdin() -> bool: ...
class FileInput(Iterable[AnyStr], Generic[AnyStr]):
def __init__(
self,
files: Union[None, AnyPath, Iterable[AnyPath]] = ...,
files: Union[None, Text, Iterable[Text]] = ...,
inplace: bool = ...,
backup: str = ...,
bufsize: int = ...,
mode: str = ...,
openhook: Callable[[AnyPath, str], IO[AnyStr]] = ...,
openhook: Callable[[Text, str], IO[AnyStr]] = ...,
) -> None: ...
def __del__(self) -> None: ...
def close(self) -> None: ...
Expand All @@ -42,5 +41,5 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]):
def isfirstline(self) -> bool: ...
def isstdin(self) -> bool: ...

def hook_compressed(filename: AnyPath, mode: str) -> IO[Any]: ...
def hook_encoded(encoding: str) -> Callable[[AnyPath, str], IO[Any]]: ...
def hook_compressed(filename: Text, mode: str) -> IO[Any]: ...
def hook_encoded(encoding: str) -> Callable[[Text, str], IO[Any]]: ...
22 changes: 11 additions & 11 deletions stdlib/@python2/genericpath.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from _typeshed import AnyPath, BytesPath, StrPath, SupportsLessThanT
from typing import List, Sequence, Tuple, Union, overload
from _typeshed import SupportsLessThanT
from typing import List, Sequence, Text, Tuple, Union, overload
from typing_extensions import Literal

# All overloads can return empty string. Ideally, Literal[""] would be a valid
# Iterable[T], so that Union[List[T], Literal[""]] could be used as a return
# type. But because this only works when T is str, we need Sequence[T] instead.
@overload
def commonprefix(m: Sequence[StrPath]) -> str: ... # type: ignore
def commonprefix(m: Sequence[Text]) -> str: ... # type: ignore
@overload
def commonprefix(m: Sequence[BytesPath]) -> Union[bytes, Literal[""]]: ... # type: ignore
def commonprefix(m: Sequence[str]) -> Union[str, Literal[""]]: ... # type: ignore
@overload
def commonprefix(m: Sequence[List[SupportsLessThanT]]) -> Sequence[SupportsLessThanT]: ...
@overload
def commonprefix(m: Sequence[Tuple[SupportsLessThanT, ...]]) -> Sequence[SupportsLessThanT]: ...
def exists(path: AnyPath) -> bool: ...
def getsize(filename: AnyPath) -> int: ...
def isfile(path: AnyPath) -> bool: ...
def isdir(s: AnyPath) -> bool: ...
def exists(path: Text) -> bool: ...
def getsize(filename: Text) -> int: ...
def isfile(path: Text) -> bool: ...
def isdir(s: Text) -> bool: ...

# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(filename: AnyPath) -> float: ...
def getmtime(filename: AnyPath) -> float: ...
def getctime(filename: AnyPath) -> float: ...
def getatime(filename: Text) -> float: ...
def getmtime(filename: Text) -> float: ...
def getctime(filename: Text) -> float: ...
11 changes: 5 additions & 6 deletions stdlib/@python2/macpath.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import AnyPath
from genericpath import (
commonprefix as commonprefix,
exists as exists,
Expand Down Expand Up @@ -37,7 +36,7 @@ def dirname(s: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(s: AnyStr) -> AnyStr: ...
def realpath(path: AnyStr) -> AnyStr: ...
def islink(s: AnyPath) -> bool: ...
def islink(s: Text) -> bool: ...

# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
Expand All @@ -46,11 +45,11 @@ def islink(s: AnyPath) -> bool: ...
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: Text) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: Text) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: Text, *p: Text) -> Text: ...
@overload
def join(__p1: Text, *p: AnyPath) -> Text: ...
def join(__p1: Text, *p: Text) -> Text: ...
def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
19 changes: 9 additions & 10 deletions stdlib/@python2/mailbox.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import email.message
from _typeshed import AnyPath
from types import TracebackType
from typing import (
IO,
Expand Down Expand Up @@ -40,7 +39,7 @@ class Mailbox(Generic[_MessageT]):

_path: Union[bytes, str] # undocumented
_factory: Optional[Callable[[IO[Any]], _MessageT]] # undocumented
def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], _MessageT]] = ..., create: bool = ...) -> None: ...
def __init__(self, path: Text, factory: Optional[Callable[[IO[Any]], _MessageT]] = ..., create: bool = ...) -> None: ...
def add(self, message: _MessageData) -> str: ...
def remove(self, key: str) -> None: ...
def __delitem__(self, key: str) -> None: ...
Expand Down Expand Up @@ -81,7 +80,7 @@ class Maildir(Mailbox[MaildirMessage]):

colon: str
def __init__(
self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], MaildirMessage]] = ..., create: bool = ...
self, dirname: Text, factory: Optional[Callable[[IO[Any]], MaildirMessage]] = ..., create: bool = ...
) -> None: ...
def get_file(self, key: str) -> _ProxyFile[bytes]: ...
def list_folders(self) -> List[str]: ...
Expand All @@ -99,24 +98,24 @@ class _mboxMMDF(_singlefileMailbox[_MessageT]):
def get_string(self, key: str, from_: bool = ...) -> str: ...

class mbox(_mboxMMDF[mboxMessage]):
def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ...) -> None: ...
def __init__(self, path: Text, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ...) -> None: ...

class MMDF(_mboxMMDF[MMDFMessage]):
def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ...) -> None: ...
def __init__(self, path: Text, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ...) -> None: ...

class MH(Mailbox[MHMessage]):
def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ...
def __init__(self, path: Text, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ...
def get_file(self, key: str) -> _ProxyFile[bytes]: ...
def list_folders(self) -> List[str]: ...
def get_folder(self, folder: AnyPath) -> MH: ...
def add_folder(self, folder: AnyPath) -> MH: ...
def remove_folder(self, folder: AnyPath) -> None: ...
def get_folder(self, folder: Text) -> MH: ...
def add_folder(self, folder: Text) -> MH: ...
def remove_folder(self, folder: Text) -> None: ...
def get_sequences(self) -> Dict[str, List[int]]: ...
def set_sequences(self, sequences: Mapping[str, Sequence[int]]) -> None: ...
def pack(self) -> None: ...

class Babyl(_singlefileMailbox[BabylMessage]):
def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ...) -> None: ...
def __init__(self, path: Text, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ...) -> None: ...
def get_file(self, key: str) -> IO[bytes]: ...
def get_labels(self) -> List[str]: ...

Expand Down
7 changes: 3 additions & 4 deletions stdlib/@python2/netrc.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from _typeshed import AnyPath
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Text, Tuple

class NetrcParseError(Exception):
filename: Optional[str]
lineno: Optional[int]
msg: str
def __init__(self, msg: str, filename: Optional[AnyPath] = ..., lineno: Optional[int] = ...) -> None: ...
def __init__(self, msg: str, filename: Optional[Text] = ..., lineno: Optional[int] = ...) -> None: ...

# (login, account, password) tuple
_NetrcTuple = Tuple[str, Optional[str], Optional[str]]

class netrc:
hosts: Dict[str, _NetrcTuple]
macros: Dict[str, List[str]]
def __init__(self, file: Optional[AnyPath] = ...) -> None: ...
def __init__(self, file: Optional[Text] = ...) -> None: ...
def authenticators(self, host: str) -> Optional[_NetrcTuple]: ...
37 changes: 18 additions & 19 deletions stdlib/@python2/ntpath.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
from _typeshed import AnyPath, BytesPath, StrPath
from genericpath import exists as exists
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, overload

Expand Down Expand Up @@ -39,20 +38,20 @@ else:
# NOTE: Empty lists results in '' (str) regardless of contained type.
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
# So, fall back to Any
def commonprefix(m: Sequence[AnyPath]) -> Any: ...
def lexists(path: AnyPath) -> bool: ...
def commonprefix(m: Sequence[Text]) -> Any: ...
def lexists(path: Text) -> bool: ...

# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(filename: AnyPath) -> float: ...
def getmtime(filename: AnyPath) -> float: ...
def getctime(filename: AnyPath) -> float: ...
def getsize(filename: AnyPath) -> int: ...
def isabs(s: AnyPath) -> bool: ...
def isfile(path: AnyPath) -> bool: ...
def isdir(s: AnyPath) -> bool: ...
def islink(path: AnyPath) -> bool: ...
def ismount(path: AnyPath) -> bool: ...
def getatime(filename: Text) -> float: ...
def getmtime(filename: Text) -> float: ...
def getctime(filename: Text) -> float: ...
def getsize(filename: Text) -> int: ...
def isabs(s: Text) -> bool: ...
def isfile(path: Text) -> bool: ...
def isdir(s: Text) -> bool: ...
def islink(path: Text) -> bool: ...
def ismount(path: Text) -> bool: ...

# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
# (Since Python 2 allows that, too)
Expand All @@ -61,18 +60,18 @@ def ismount(path: AnyPath) -> bool: ...
@overload
def join(__p1: bytes, *p: bytes) -> bytes: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: Text) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: Text) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
def join(__p1: bytes, __p2: Text, *p: Text) -> Text: ...
@overload
def join(__p1: Text, *p: AnyPath) -> Text: ...
def join(__p1: Text, *p: Text) -> Text: ...
@overload
def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ...
def relpath(path: str, start: Optional[str] = ...) -> str: ...
@overload
def relpath(path: StrPath, start: Optional[StrPath] = ...) -> Text: ...
def samefile(f1: AnyPath, f2: AnyPath) -> bool: ...
def relpath(path: Text, start: Optional[Text] = ...) -> Text: ...
def samefile(f1: Text, f2: Text) -> bool: ...
def sameopenfile(fp1: int, fp2: int) -> bool: ...
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
Expand Down
Loading