Skip to content

[WIP] make unicode vs bytes more distinct in py2 #2621

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

Closed
wants to merge 5 commits into from
Closed
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
265 changes: 133 additions & 132 deletions stdlib/2/__builtin__.pyi

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions stdlib/2/_threading_local.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Source: https://hg.python.org/cpython/file/2.7/Lib/_threading_local.py
from typing import Any, List
from typing import Any, List, Text

__all__: List[str]
__all__: List[Text]

class _localbase(object): ...

class local(_localbase):
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
def __getattribute__(self, name: Text) -> Any: ...
def __setattr__(self, name: Text, value: Any) -> None: ...
def __delattr__(self, name: Text) -> None: ...
def __del__(self) -> None: ...

def _patch(self: local) -> None: ...
265 changes: 133 additions & 132 deletions stdlib/2/builtins.pyi

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion stdlib/2/encodings/utf_8.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import codecs
from six import text_type as unicode
from typing import Text, Tuple

class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input: Text, final: bool = ...) -> bytes: ...

class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[Text, int]: ...
def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[unicode, int]: ...

class StreamWriter(codecs.StreamWriter): ...
class StreamReader(codecs.StreamReader): ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2/json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def dumps(obj: Any,
**kwds: Any) -> str: ...

def dump(obj: Any,
fp: Union[IO[str], IO[Text]],
fp: Union[IO[str], IO[unicode]],
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2/string.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Based on http://docs.python.org/3.2/library/string.html

from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable, AnyStr
from typing import Mapping, Sequence, Any, Optional, Union, List, Text, Tuple, Iterable, AnyStr

ascii_letters = ... # type: str
ascii_lowercase = ... # type: str
Expand Down Expand Up @@ -70,5 +70,5 @@ class Formatter(object):
raise KeyError()
def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any],
kwargs: Mapping[str, Any]) -> None: ...
def format_field(self, value: Any, format_spec: str) -> Any: ...
def format_field(self, value: Any, format_spec: Text) -> Any: ...
def convert_field(self, value: Any, conversion: str) -> Any: ...
2 changes: 1 addition & 1 deletion stdlib/2/tempfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _TemporaryFileWrapper(IO[str]):
def __del__(self) -> None: ...
def __enter__(self) -> _TemporaryFileWrapper: ...
def __exit__(self, exc, value, tb) -> bool: ...
def __getattr__(self, name: unicode) -> Any: ...
def __getattr__(self, name: Text) -> Any: ...
def close(self) -> None: ...
def unlink(self, path: unicode) -> None: ...
# These methods don't exist directly on this object, but
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2/toaiff.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# Source: https://hg.python.org/cpython/file/2.7/Lib/toaiff.py
from pipes import Template
from typing import Dict, List
from typing import Dict, List, Text


__all__: List[str]
__all__: List[Text]
table: Dict[str, Template]
t: Template
uncompress: Template
Expand Down
28 changes: 14 additions & 14 deletions stdlib/2/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import (
Any, Callable, Dict, Iterable, Iterator, List, Optional,
Tuple, Type, TypeVar, Union, overload,
Text, Tuple, Type, TypeVar, Union, overload,
)

_T = TypeVar('_T')
Expand Down Expand Up @@ -33,9 +33,9 @@ class FunctionType:
func_closure = ... # type: Optional[Tuple[_Cell, ...]]
func_code = ... # type: CodeType
func_defaults = ... # type: Optional[Tuple[Any, ...]]
func_dict = ... # type: Dict[str, Any]
func_doc = ... # type: Optional[str]
func_globals = ... # type: Dict[str, Any]
func_dict = ... # type: Dict[Text, Any]
func_doc = ... # type: Optional[Text]
func_globals = ... # type: Dict[Text, Any]
func_name = ... # type: str
__closure__ = func_closure
__code__ = func_code
Expand Down Expand Up @@ -98,13 +98,13 @@ class BuiltinFunctionType:
BuiltinMethodType = BuiltinFunctionType

class ModuleType:
__doc__ = ... # type: Optional[str]
__file__ = ... # type: Optional[str]
__name__ = ... # type: str
__package__ = ... # type: Optional[str]
__path__ = ... # type: Optional[Iterable[str]]
__dict__ = ... # type: Dict[str, Any]
def __init__(self, name: str, doc: Optional[str] = ...) -> None: ...
__doc__ = ... # type: Optional[Text]
__file__ = ... # type: Optional[Text]
__name__ = ... # type: Text
__package__ = ... # type: Optional[Text]
__path__ = ... # type: Optional[Iterable[Text]]
__dict__ = ... # type: Dict[Text, Any]
def __init__(self, name: Text, doc: Optional[Text] = ...) -> None: ...
FileType = file
XRangeType = xrange

Expand All @@ -116,15 +116,15 @@ class TracebackType:

class FrameType:
f_back = ... # type: FrameType
f_builtins = ... # type: Dict[str, Any]
f_builtins = ... # type: Dict[Text, Any]
f_code = ... # type: CodeType
f_exc_type = ... # type: None
f_exc_value = ... # type: None
f_exc_traceback = ... # type: None
f_globals = ... # type: Dict[str, Any]
f_globals = ... # type: Dict[Text, Any]
f_lasti = ... # type: int
f_lineno = ... # type: int
f_locals = ... # type: Dict[str, Any]
f_locals = ... # type: Dict[Text, Any]
f_restricted = ... # type: bool
f_trace = ... # type: Callable[[], None]

Expand Down
4 changes: 2 additions & 2 deletions stdlib/2/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def update(self, **kwargs: _VT) -> None: ...

Text = unicode
Text = Union[bytes, unicode]

TYPE_CHECKING = True

Expand Down Expand Up @@ -397,7 +397,7 @@ class Match(Generic[AnyStr]):
# Pattern is generic over AnyStr (determining the type of its .pattern
# attribute), but at the same time its methods take either bytes or
# Text and return the same type, regardless of the type of the pattern.
_AnyStr2 = TypeVar('_AnyStr2', bytes, Text)
_AnyStr2 = TypeVar('_AnyStr2', bytes, unicode, Text)

class Pattern(Generic[AnyStr]):
flags: int
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2/unittest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _T = TypeVar('_T')
_FT = TypeVar('_FT')

_ExceptionType = Union[Type[BaseException], Tuple[Type[BaseException], ...]]
_Regexp = Union[Text, Pattern[Text]]
_Regexp = Union[Text, Pattern[unicode], Pattern[str]]

class Testable(metaclass=ABCMeta):
@abstractmethod
Expand Down
5 changes: 3 additions & 2 deletions stdlib/2and3/codecs.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from six import text_type as unicode
import sys
from typing import Any, BinaryIO, Callable, Generator, IO, Iterable, Iterator, List, Optional, Protocol, Text, TextIO, Tuple, Type, TypeVar, Union

Expand All @@ -10,7 +11,7 @@ import types
# 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
_Decoded = unicode
_Encoded = bytes

class _Encoder(Protocol):
Expand Down Expand Up @@ -171,7 +172,7 @@ class StreamReaderWriter(TextIO):
if sys.version_info >= (3,):
def __next__(self) -> Text: ...
else:
def next(self) -> Text: ...
def next(self) -> unicode: ...
def __iter__(self: _T) -> _T: ...
# This actually returns None, but that's incompatible with the supertype
def write(self, data: _Decoded) -> int: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/2and3/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ class _StructUnionMeta(_CDataMeta):
_fields_: Sequence[_UnionT[Tuple[str, Type[_CData]], Tuple[str, Type[_CData], int]]] = ...
_pack_: int = ...
_anonymous_: Sequence[str] = ...
def __getattr__(self, name: str) -> _CField: ...
def __getattr__(self, name: Text) -> _CField: ...
class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
def __init__(self, *args: Any, **kw: Any) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __getattr__(self, name: Text) -> Any: ...
def __setattr__(self, name: Text, value: Any) -> None: ...

class Union(_StructUnionBase): ...
class Structure(_StructUnionBase): ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2and3/decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import numbers
import sys
from types import TracebackType
from typing import (
Any, Container, Dict, List, NamedTuple, Optional, Sequence, Text, Tuple, Type, TypeVar, Union,
Any, AnyStr, Container, Dict, List, NamedTuple, Optional, Sequence, Text, Tuple, Type, TypeVar, Union,
)

_Decimal = Union[Decimal, int]
Expand Down Expand Up @@ -193,7 +193,7 @@ class Decimal(object):
def __reduce__(self) -> Tuple[Type[Decimal], Tuple[str]]: ...
def __copy__(self) -> Decimal: ...
def __deepcopy__(self, memo: Any) -> Decimal: ...
def __format__(self, specifier: str, context: Optional[Context] = ...) -> str: ...
def __format__(self, specifier: AnyStr, context: Optional[Context] = ...) -> AnyStr: ...

class _ContextManager(object):
new_context: Context
Expand Down
7 changes: 4 additions & 3 deletions stdlib/2and3/imaplib.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Stubs for imaplib (Python 2)

import imaplib
from six import text_type as unicode
import subprocess
import sys
import time
Expand All @@ -15,7 +16,7 @@ class IMAP4:
error: Type[Exception] = ...
abort: Type[Exception] = ...
readonly: Type[Exception] = ...
mustquote: Pattern[Text] = ...
mustquote: Union[Pattern[str],Pattern[unicode]] = ...
debug: int = ...
state: str = ...
literal: Optional[Text] = ...
Expand All @@ -25,7 +26,7 @@ class IMAP4:
is_readonly: bool = ...
tagnum: int = ...
tagpre: str = ...
tagre: Pattern[Text] = ...
tagre: Union[Pattern[str],Pattern[unicode]] = ...
welcome: bytes = ...
capabilities: Tuple[str] = ...
PROTOCOL_VERSION: str = ...
Expand All @@ -34,7 +35,7 @@ class IMAP4:
host: str = ...
port: int = ...
sock: _socket = ...
file: Union[IO[Text], IO[bytes]] = ...
file: Union[IO[unicode], IO[bytes]] = ...
def open(self, host: str = ..., port: int = ...) -> None: ...
def read(self, size: int) -> bytes: ...
def readline(self) -> bytes: ...
Expand Down
5 changes: 3 additions & 2 deletions stdlib/2and3/lib2to3/pgen2/driver.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Stubs for lib2to3.pgen2.driver (Python 3.6)

import os
from six import text_type as unicode
import sys
from typing import Any, Callable, IO, Iterable, List, Optional, Text, Tuple, Union

Expand All @@ -16,8 +17,8 @@ class Driver:
convert: _Convert
def __init__(self, grammar: Grammar, convert: Optional[_Convert] = ..., logger: Optional[Logger] = ...) -> None: ...
def parse_tokens(self, tokens: Iterable[Any], debug: bool = ...) -> _NL: ...
def parse_stream_raw(self, stream: IO[Text], debug: bool = ...) -> _NL: ...
def parse_stream(self, stream: IO[Text], debug: bool = ...) -> _NL: ...
def parse_stream_raw(self, stream: Union[IO[str],IO[unicode]], debug: bool = ...) -> _NL: ...
def parse_stream(self, stream: Union[IO[str],IO[unicode]], debug: bool = ...) -> _NL: ...
def parse_file(self, filename: _Path, encoding: Optional[Text] = ..., debug: bool = ...) -> _NL: ...
def parse_string(self, text: Text, debug: bool = ...) -> _NL: ...

Expand Down
7 changes: 4 additions & 3 deletions stdlib/2and3/lib2to3/pgen2/pgen.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Stubs for lib2to3.pgen2.pgen (Python 3.6)

from six import text_type as unicode
from typing import (
Any, Dict, IO, Iterable, Iterator, List, NoReturn, Optional, Text, Tuple
Any, Dict, IO, Iterable, Iterator, List, NoReturn, Optional, Text, Tuple, Union
)

from lib2to3.pgen2 import _Path, grammar
Expand All @@ -11,10 +12,10 @@ class PgenGrammar(grammar.Grammar): ...

class ParserGenerator:
filename: _Path
stream: IO[Text]
stream: Union[IO[str],IO[unicode]]
generator: Iterator[_TokenInfo]
first: Dict[Text, Dict[Text, int]]
def __init__(self, filename: _Path, stream: Optional[IO[Text]] = ...) -> None: ...
def __init__(self, filename: _Path, stream: Optional[Union[IO[str],IO[unicode]]] = ...) -> None: ...
def make_grammar(self) -> PgenGrammar: ...
def make_first(self, c: PgenGrammar, name: Text) -> Dict[int, int]: ...
def make_label(self, c: PgenGrammar, label: Text) -> int: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2and3/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Logger(Filterer):
def setLevel(self, lvl: Union[int, str]) -> None: ...
def isEnabledFor(self, lvl: int) -> bool: ...
def getEffectiveLevel(self) -> int: ...
def getChild(self, suffix: str) -> Logger: ...
def getChild(self, suffix: Text) -> Logger: ...
if sys.version_info >= (3,):
def debug(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ...,
stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ...,
Expand Down
8 changes: 4 additions & 4 deletions stdlib/2and3/plistlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import (
Any, IO, Mapping, MutableMapping, Optional, Union,
Type, TypeVar,
Text, Type, TypeVar,
)
from typing import Dict as DictT
import sys
Expand Down Expand Up @@ -48,9 +48,9 @@ if sys.version_info < (3,):

if sys.version_info < (3, 7):
class Dict(dict):
def __getattr__(self, attr: str) -> Any: ...
def __setattr__(self, attr: str, value: Any) -> None: ...
def __delattr__(self, attr: str) -> None: ...
def __getattr__(self, attr: Text) -> Any: ...
def __setattr__(self, attr: Text, value: Any) -> None: ...
def __delattr__(self, attr: Text) -> None: ...

class Data:
data = ... # type: bytes
Expand Down
5 changes: 3 additions & 2 deletions stdlib/2and3/poplib.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Stubs for poplib (Python 2 and 3)

import socket
from six import text_type as unicode
import ssl
import sys
from typing import (
Any, BinaryIO, Dict, List, NoReturn, Optional, overload, Pattern, Text,
Tuple,
Tuple, Union,
)

_LongResp = Tuple[bytes, List[bytes], int]
Expand Down Expand Up @@ -44,7 +45,7 @@ class POP3:
def close(self) -> None: ...
def rpop(self, user: Text) -> bytes: ...

timestamp: Pattern[Text]
timestamp: Union[Pattern[str],Pattern[unicode]]

if sys.version_info < (3, 0):
def apop(self, user: Text, secret: Text) -> bytes: ...
Expand Down
8 changes: 4 additions & 4 deletions stdlib/2and3/threading.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stubs for threading

from typing import (
Any, Callable, Iterable, List, Mapping, Optional, Tuple, Type, Union,
Any, Callable, Iterable, List, Mapping, Optional, Tuple, Text, Type, Union,
TypeVar,
)
from types import FrameType, TracebackType
Expand Down Expand Up @@ -41,9 +41,9 @@ class ThreadError(Exception): ...


class local(object):
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
def __getattribute__(self, name: Text) -> Any: ...
def __setattr__(self, name: Text, value: Any) -> None: ...
def __delattr__(self, name: Text) -> None: ...


class Thread:
Expand Down
Loading