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
4 changes: 2 additions & 2 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Iterable, Iterator, List, Optional, Protocol, Text, Type, Union
from typing import Any, Iterable, Iterator, List, Optional, Protocol, Type, Union

QUOTE_ALL: int
QUOTE_MINIMAL: int
Expand Down Expand Up @@ -34,7 +34,7 @@ class _Writer(Protocol):
def write(self, s: str) -> Any: ...

def writer(csvfile: _Writer, dialect: _DialectLike = ..., **fmtparams: Any) -> _writer: ...
def reader(csvfile: Iterable[Text], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ...
def reader(csvfile: Iterable[str], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ...
def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ...
def unregister_dialect(name: str) -> None: ...
def get_dialect(name: str) -> Dialect: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from types import FrameType, TracebackType
from typing import Any, Callable, Iterable, List, Mapping, Optional, Text, Type, TypeVar, Union
from typing import Any, Callable, Iterable, List, Mapping, Optional, Type, TypeVar, Union

# TODO recursive type
_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]
Expand Down Expand Up @@ -51,7 +51,7 @@ class Thread:
def run(self) -> None: ...
def join(self, timeout: Optional[float] = ...) -> None: ...
def getName(self) -> str: ...
def setName(self, name: Text) -> None: ...
def setName(self, name: str) -> None: ...
if sys.version_info >= (3, 8):
@property
def native_id(self) -> Optional[int]: ... # only available on some platforms
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_typeshed/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# file. They are provided for type checking purposes.

from sys import _OptExcInfo
from typing import Any, Callable, Dict, Iterable, List, Optional, Protocol, Text, Tuple
from typing import Any, Callable, Dict, Iterable, List, Optional, Protocol, Tuple

class StartResponse(Protocol):
def __call__(
self, status: str, headers: List[Tuple[str, str]], exc_info: Optional[_OptExcInfo] = ...
) -> Callable[[bytes], Any]: ...

WSGIEnvironment = Dict[Text, Any]
WSGIEnvironment = Dict[str, Any]
WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]]

# WSGI input streams per PEP 3333
Expand Down
4 changes: 2 additions & 2 deletions stdlib/aifc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from types import TracebackType
from typing import IO, Any, List, NamedTuple, Optional, Text, Tuple, Type, Union, overload
from typing import IO, Any, List, NamedTuple, Optional, Tuple, Type, Union, overload
from typing_extensions import Literal

class Error(Exception): ...
Expand All @@ -13,7 +13,7 @@ class _aifc_params(NamedTuple):
comptype: bytes
compname: bytes

_File = Union[Text, IO[bytes]]
_File = Union[str, IO[bytes]]
_Marker = Tuple[int, int, bytes]

class Aifc_read:
Expand Down
6 changes: 3 additions & 3 deletions stdlib/array.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys
from typing import Any, BinaryIO, Generic, Iterable, List, MutableSequence, Text, Tuple, TypeVar, Union, overload
from typing import Any, BinaryIO, Generic, Iterable, List, MutableSequence, Tuple, TypeVar, Union, overload
from typing_extensions import Literal

_IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
_FloatTypeCode = Literal["f", "d"]
_UnicodeTypeCode = Literal["u"]
_TypeCode = Union[_IntTypeCode, _FloatTypeCode, _UnicodeTypeCode]

_T = TypeVar("_T", int, float, Text)
_T = TypeVar("_T", int, float, str)

typecodes: str

Expand All @@ -19,7 +19,7 @@ class array(MutableSequence[_T], Generic[_T]):
@overload
def __init__(self: array[float], typecode: _FloatTypeCode, __initializer: Union[bytes, Iterable[_T]] = ...) -> None: ...
@overload
def __init__(self: array[Text], typecode: _UnicodeTypeCode, __initializer: Union[bytes, Iterable[_T]] = ...) -> None: ...
def __init__(self: array[str], typecode: _UnicodeTypeCode, __initializer: Union[bytes, Iterable[_T]] = ...) -> None: ...
@overload
def __init__(self, typecode: str, __initializer: Union[bytes, Iterable[_T]] = ...) -> None: ...
def append(self, __v: _T) -> None: ...
Expand Down
90 changes: 41 additions & 49 deletions stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ from typing import (
List,
Optional,
Protocol,
Text,
TextIO,
Tuple,
Type,
Expand All @@ -22,25 +21,22 @@ from typing import (
from typing_extensions import Literal

# TODO: this only satisfies the most common interface, where
# bytes (py2 str) is the raw form and str (py2 unicode) is the cooked form.
# bytes is the raw form and str is the cooked form.
# In the long run, both should become template parameters maybe?
# There *are* bytes->bytes and str->str encodings in the standard library.
# They are much more common in Python 2 than in Python 3.

_Decoded = Text
_Encoded = bytes

class _Encoder(Protocol):
def __call__(self, input: _Decoded, errors: str = ...) -> Tuple[_Encoded, int]: ... # signature of Codec().encode
def __call__(self, input: str, errors: str = ...) -> Tuple[bytes, int]: ... # signature of Codec().encode

class _Decoder(Protocol):
def __call__(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ... # signature of Codec().decode
def __call__(self, input: bytes, errors: str = ...) -> Tuple[str, int]: ... # signature of Codec().decode

class _StreamReader(Protocol):
def __call__(self, stream: IO[_Encoded], errors: str = ...) -> StreamReader: ...
def __call__(self, stream: IO[bytes], errors: str = ...) -> StreamReader: ...

class _StreamWriter(Protocol):
def __call__(self, stream: IO[_Encoded], errors: str = ...) -> StreamWriter: ...
def __call__(self, stream: IO[bytes], errors: str = ...) -> StreamWriter: ...

class _IncrementalEncoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalEncoder: ...
Expand Down Expand Up @@ -74,18 +70,16 @@ def encode(obj: bytes, encoding: _BytesToBytesEncodingT, errors: str = ...) -> b
@overload
def encode(obj: str, encoding: Literal["rot13", "rot_13"] = ..., errors: str = ...) -> str: ... # type: ignore
@overload
def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ...
def encode(obj: str, encoding: str = ..., errors: str = ...) -> bytes: ...
@overload
def decode(obj: bytes, encoding: _BytesToBytesEncodingT, errors: str = ...) -> bytes: ... # type: ignore
@overload
def decode(obj: str, encoding: Literal["rot13", "rot_13"] = ..., errors: str = ...) -> Text: ...
def decode(obj: str, encoding: Literal["rot13", "rot_13"] = ..., errors: str = ...) -> str: ...
@overload
def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ...
def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ...
def lookup(__encoding: str) -> CodecInfo: ...
def utf_16_be_decode(
__data: _Encoded, __errors: Optional[str] = ..., __final: bool = ...
) -> Tuple[_Decoded, int]: ... # undocumented
def utf_16_be_encode(__str: _Decoded, __errors: Optional[str] = ...) -> Tuple[_Encoded, int]: ... # undocumented
def utf_16_be_decode(__data: bytes, __errors: Optional[str] = ..., __final: bool = ...) -> Tuple[str, int]: ... # undocumented
def utf_16_be_encode(__str: str, __errors: Optional[str] = ...) -> Tuple[bytes, int]: ... # undocumented

class CodecInfo(Tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
@property
Expand Down Expand Up @@ -124,11 +118,9 @@ def register(__search_function: Callable[[str], Optional[CodecInfo]]) -> None: .
def open(
filename: str, mode: str = ..., encoding: Optional[str] = ..., errors: str = ..., buffering: int = ...
) -> StreamReaderWriter: ...
def EncodedFile(
file: IO[_Encoded], data_encoding: str, file_encoding: Optional[str] = ..., errors: str = ...
) -> StreamRecoder: ...
def iterencode(iterator: Iterable[_Decoded], encoding: str, errors: str = ...) -> Generator[_Encoded, None, None]: ...
def iterdecode(iterator: Iterable[_Encoded], encoding: str, errors: str = ...) -> Generator[_Decoded, None, None]: ...
def EncodedFile(file: IO[bytes], data_encoding: str, file_encoding: Optional[str] = ..., errors: str = ...) -> StreamRecoder: ...
def iterencode(iterator: Iterable[str], encoding: str, errors: str = ...) -> Generator[bytes, None, None]: ...
def iterdecode(iterator: Iterable[bytes], encoding: str, errors: str = ...) -> Generator[str, None, None]: ...

BOM: bytes
BOM_BE: bytes
Expand All @@ -155,52 +147,52 @@ def backslashreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes],
class Codec:
# These are sort of @abstractmethod but sort of not.
# The StreamReader and StreamWriter subclasses only implement one.
def encode(self, input: _Decoded, errors: str = ...) -> Tuple[_Encoded, int]: ...
def decode(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ...
def encode(self, input: str, errors: str = ...) -> Tuple[bytes, int]: ...
def decode(self, input: bytes, errors: str = ...) -> Tuple[str, int]: ...

class IncrementalEncoder:
errors: str
def __init__(self, errors: str = ...) -> None: ...
@abstractmethod
def encode(self, input: _Decoded, final: bool = ...) -> _Encoded: ...
def encode(self, input: str, final: bool = ...) -> bytes: ...
def reset(self) -> None: ...
# documentation says int but str is needed for the subclass.
def getstate(self) -> Union[int, _Decoded]: ...
def setstate(self, state: Union[int, _Decoded]) -> None: ...
def getstate(self) -> Union[int, str]: ...
def setstate(self, state: Union[int, str]) -> None: ...

class IncrementalDecoder:
errors: str
def __init__(self, errors: str = ...) -> None: ...
@abstractmethod
def decode(self, input: _Encoded, final: bool = ...) -> _Decoded: ...
def decode(self, input: bytes, final: bool = ...) -> str: ...
def reset(self) -> None: ...
def getstate(self) -> Tuple[_Encoded, int]: ...
def setstate(self, state: Tuple[_Encoded, int]) -> None: ...
def getstate(self) -> Tuple[bytes, int]: ...
def setstate(self, state: Tuple[bytes, int]) -> None: ...

# These are not documented but used in encodings/*.py implementations.
class BufferedIncrementalEncoder(IncrementalEncoder):
buffer: str
def __init__(self, errors: str = ...) -> None: ...
@abstractmethod
def _buffer_encode(self, input: _Decoded, errors: str, final: bool) -> _Encoded: ...
def encode(self, input: _Decoded, final: bool = ...) -> _Encoded: ...
def _buffer_encode(self, input: str, errors: str, final: bool) -> bytes: ...
def encode(self, input: str, final: bool = ...) -> bytes: ...

class BufferedIncrementalDecoder(IncrementalDecoder):
buffer: bytes
def __init__(self, errors: str = ...) -> None: ...
@abstractmethod
def _buffer_decode(self, input: _Encoded, errors: str, final: bool) -> Tuple[_Decoded, int]: ...
def decode(self, input: _Encoded, final: bool = ...) -> _Decoded: ...
def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[str, int]: ...
def decode(self, input: bytes, final: bool = ...) -> str: ...

_SW = TypeVar("_SW", bound=StreamWriter)

# TODO: it is not possible to specify the requirement that all other
# attributes and methods are passed-through from the stream.
class StreamWriter(Codec):
errors: str
def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ...
def write(self, object: _Decoded) -> None: ...
def writelines(self, list: Iterable[_Decoded]) -> None: ...
def __init__(self, stream: IO[bytes], errors: str = ...) -> None: ...
def write(self, object: str) -> None: ...
def writelines(self, list: Iterable[str]) -> None: ...
def reset(self) -> None: ...
def __enter__(self: _SW) -> _SW: ...
def __exit__(
Expand All @@ -212,32 +204,32 @@ _SR = TypeVar("_SR", bound=StreamReader)

class StreamReader(Codec):
errors: str
def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ...
def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> _Decoded: ...
def readline(self, size: Optional[int] = ..., keepends: bool = ...) -> _Decoded: ...
def readlines(self, sizehint: Optional[int] = ..., keepends: bool = ...) -> List[_Decoded]: ...
def __init__(self, stream: IO[bytes], errors: str = ...) -> None: ...
def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> str: ...
def readline(self, size: Optional[int] = ..., keepends: bool = ...) -> str: ...
def readlines(self, sizehint: Optional[int] = ..., keepends: bool = ...) -> List[str]: ...
def reset(self) -> None: ...
def __enter__(self: _SR) -> _SR: ...
def __exit__(
self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
) -> None: ...
def __iter__(self) -> Iterator[_Decoded]: ...
def __iter__(self) -> Iterator[str]: ...
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...

_T = TypeVar("_T", bound=StreamReaderWriter)

# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
# and delegates attributes to the underlying binary stream with __getattr__.
class StreamReaderWriter(TextIO):
def __init__(self, stream: IO[_Encoded], Reader: _StreamReader, Writer: _StreamWriter, errors: str = ...) -> None: ...
def read(self, size: int = ...) -> _Decoded: ...
def readline(self, size: Optional[int] = ...) -> _Decoded: ...
def readlines(self, sizehint: Optional[int] = ...) -> List[_Decoded]: ...
def __next__(self) -> Text: ...
def __init__(self, stream: IO[bytes], Reader: _StreamReader, Writer: _StreamWriter, errors: str = ...) -> None: ...
def read(self, size: int = ...) -> str: ...
def readline(self, size: Optional[int] = ...) -> str: ...
def readlines(self, sizehint: Optional[int] = ...) -> List[str]: ...
def __next__(self) -> str: ...
def __iter__(self: _T) -> _T: ...
# This actually returns None, but that's incompatible with the supertype
def write(self, data: _Decoded) -> int: ...
def writelines(self, list: Iterable[_Decoded]) -> None: ...
def write(self, data: str) -> int: ...
def writelines(self, list: Iterable[str]) -> None: ...
def reset(self) -> None: ...
# Same as write()
def seek(self, offset: int, whence: int = ...) -> int: ...
Expand All @@ -263,7 +255,7 @@ _SRT = TypeVar("_SRT", bound=StreamRecoder)
class StreamRecoder(BinaryIO):
def __init__(
self,
stream: IO[_Encoded],
stream: IO[bytes],
encode: _Encoder,
decode: _Decoder,
Reader: _StreamReader,
Expand Down
6 changes: 3 additions & 3 deletions stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from _csv import (
unregister_dialect as unregister_dialect,
writer as writer,
)
from typing import Any, Generic, Iterable, Iterator, List, Mapping, Optional, Sequence, Text, Type, TypeVar, overload
from typing import Any, Generic, Iterable, Iterator, List, Mapping, Optional, Sequence, Type, TypeVar, overload

if sys.version_info >= (3, 8):
from typing import Dict as _DictReadMapping
Expand Down Expand Up @@ -55,7 +55,7 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]):
@overload
def __init__(
self,
f: Iterable[Text],
f: Iterable[str],
fieldnames: Sequence[_T],
restkey: Optional[str] = ...,
restval: Optional[str] = ...,
Expand All @@ -66,7 +66,7 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]):
@overload
def __init__(
self: DictReader[str],
f: Iterable[Text],
f: Iterable[str],
fieldnames: Optional[Sequence[str]] = ...,
restkey: Optional[str] = ...,
restval: Optional[str] = ...,
Expand Down
11 changes: 5 additions & 6 deletions stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ from typing import (
Mapping,
Optional,
Sequence,
Text,
Tuple,
Type,
TypeVar,
Expand Down Expand Up @@ -166,7 +165,7 @@ def create_string_buffer(init: _UnionT[int, bytes], size: Optional[int] = ...) -

c_buffer = create_string_buffer

def create_unicode_buffer(init: _UnionT[int, Text], size: Optional[int] = ...) -> Array[c_wchar]: ...
def create_unicode_buffer(init: _UnionT[int, str], size: Optional[int] = ...) -> Array[c_wchar]: ...

if sys.platform == "win32":
def DllCanUnloadNow() -> int: ...
Expand Down Expand Up @@ -248,10 +247,10 @@ class c_ulong(_SimpleCData[int]): ...
class c_ulonglong(_SimpleCData[int]): ...
class c_ushort(_SimpleCData[int]): ...
class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ...
class c_wchar(_SimpleCData[Text]): ...
class c_wchar(_SimpleCData[str]): ...

class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]):
def __init__(self, value: Optional[_UnionT[int, Text]] = ...) -> None: ...
class c_wchar_p(_PointerLike, _SimpleCData[Optional[str]]):
def __init__(self, value: Optional[_UnionT[int, str]] = ...) -> None: ...

class c_bool(_SimpleCData[bool]):
def __init__(self, value: bool = ...) -> None: ...
Expand Down Expand Up @@ -285,7 +284,7 @@ class Array(Generic[_CT], _CData):
_length_: ClassVar[int] = ...
_type_: ClassVar[Type[_CT]] = ...
raw: bytes = ... # Note: only available if _CT == c_char
value: Any = ... # Note: bytes if _CT == c_char, Text if _CT == c_wchar, unavailable otherwise
value: Any = ... # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
# here, because of a special feature of ctypes.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/decimal.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numbers
from types import TracebackType
from typing import Any, Container, Dict, List, NamedTuple, Optional, Sequence, Text, Tuple, Type, TypeVar, Union, overload
from typing import Any, Container, Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, TypeVar, Union, overload

_Decimal = Union[Decimal, int]
_DecimalNew = Union[Decimal, float, Text, Tuple[int, Sequence[int], int]]
_DecimalNew = Union[Decimal, float, str, Tuple[int, Sequence[int], int]]
_ComparableNum = Union[Decimal, float, numbers.Rational]
_DecimalT = TypeVar("_DecimalT", bound=Decimal)

Expand Down
Loading