diff --git a/.travis.yml b/.travis.yml index 4bef66638..1dd1e896e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ matrix: - python: "3.6" env: TEST_CMD="./tests/mypy_selftest.py" - python: "3.5" - env: TEST_CMD="./tests/mypy_test.py" + env: TEST_CMD="./tests/mypy_test.py --no-implicit-optional" - python: "2.7" env: TEST_CMD="./tests/pytype_test.py --num-parallel=4" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fd3678f5c..5bf687557 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -135,7 +135,8 @@ rule is that they should be as concise as possible. Specifically: names, or methods and fields within a single class; * use a single blank line between top-level class definitions, or none if the classes are very small; -* do not use docstrings. +* do not use docstrings; +* for arguments with a type and a default, use spaces around the `=`. Imports in stubs are considered private (not part of the exported API) unless: @@ -144,6 +145,14 @@ unless: * they use the form ``from library import *`` which means all names from that library are exported. +For arguments with type and a default value of `None`, PEP 484 +prescribes that the type automatically becomes `Optional`. However we +prefer explicit over implicit in this case, and require the explicit +`Optional[]` around the type. The mypy tests enforce this (through +the use of --no-implicit-optional) and the error looks like +`Incompatible types in assignment (expression has type None, variable +has type "Blah") `. + Stub files support forward references natively. In other words, the order of class declarations and type aliases does not matter in a stub file. You can also use the name of the class within its own diff --git a/stdlib/3.4/asyncio/locks.pyi b/stdlib/3.4/asyncio/locks.pyi index 685402511..16cb02b30 100644 --- a/stdlib/3.4/asyncio/locks.pyi +++ b/stdlib/3.4/asyncio/locks.pyi @@ -37,7 +37,7 @@ class Event: def wait(self) -> Generator[Any, None, bool]: ... class Condition(_ContextManagerMixin): - def __init__(self, lock: Lock = None, *, loop: Optional[AbstractEventLoop] = ...) -> None: ... + def __init__(self, lock: Optional[Lock] = None, *, loop: Optional[AbstractEventLoop] = ...) -> None: ... def locked(self) -> bool: ... @coroutine def acquire(self) -> Generator[Any, None, bool]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 27d9c5eed..19586b75d 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -250,8 +250,8 @@ class str(Sequence[str]): def center(self, width: int, fillchar: str = ' ') -> str: ... def count(self, x: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def encode(self, encoding: str = 'utf-8', errors: str = 'strict') -> bytes: ... - def endswith(self, suffix: Union[str, Tuple[str, ...]], start: int = None, - end: int = None) -> bool: ... + def endswith(self, suffix: Union[str, Tuple[str, ...]], start: Optional[int] = None, + end: Optional[int] = None) -> bool: ... def expandtabs(self, tabsize: int = 8) -> str: ... def find(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: Any, **kwargs: Any) -> str: ... @@ -271,20 +271,20 @@ class str(Sequence[str]): def join(self, iterable: Iterable[str]) -> str: ... def ljust(self, width: int, fillchar: str = ' ') -> str: ... def lower(self) -> str: ... - def lstrip(self, chars: str = None) -> str: ... + def lstrip(self, chars: Optional[str] = None) -> str: ... def partition(self, sep: str) -> Tuple[str, str, str]: ... def replace(self, old: str, new: str, count: int = -1) -> str: ... def rfind(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def rindex(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def rjust(self, width: int, fillchar: str = ' ') -> str: ... def rpartition(self, sep: str) -> Tuple[str, str, str]: ... - def rsplit(self, sep: str = None, maxsplit: int = -1) -> List[str]: ... - def rstrip(self, chars: str = None) -> str: ... - def split(self, sep: str = None, maxsplit: int = -1) -> List[str]: ... + def rsplit(self, sep: Optional[str] = None, maxsplit: int = -1) -> List[str]: ... + def rstrip(self, chars: Optional[str] = None) -> str: ... + def split(self, sep: Optional[str] = None, maxsplit: int = -1) -> List[str]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... - def startswith(self, prefix: Union[str, Tuple[str, ...]], start: int = None, - end: int = None) -> bool: ... - def strip(self, chars: str = None) -> str: ... + def startswith(self, prefix: Union[str, Tuple[str, ...]], start: Optional[int] = None, + end: Optional[int] = None) -> bool: ... + def strip(self, chars: Optional[str] = None) -> str: ... def swapcase(self) -> str: ... def title(self) -> str: ... def translate(self, table: Dict[int, Any]) -> str: ... @@ -333,22 +333,22 @@ class bytes(ByteString): def capitalize(self) -> bytes: ... def center(self, width: int, fillchar: bytes = ...) -> bytes: ... if sys.version_info >= (3, 3): - def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def count(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ... def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = 8) -> bytes: ... if sys.version_info >= (3, 3): - def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def find(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... if sys.version_info >= (3, 5): def hex(self) -> str: ... if sys.version_info >= (3, 3): - def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def index(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... def isdigit(self) -> bool: ... @@ -359,25 +359,25 @@ class bytes(ByteString): def join(self, iterable: Iterable[bytes]) -> bytes: ... def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... def lower(self) -> bytes: ... - def lstrip(self, chars: bytes = None) -> bytes: ... + def lstrip(self, chars: Optional[bytes] = None) -> bytes: ... def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... def replace(self, old: bytes, new: bytes, count: int = -1) -> bytes: ... if sys.version_info >= (3, 3): - def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rfind(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... if sys.version_info >= (3, 3): - def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rindex(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... - def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytes]: ... - def rstrip(self, chars: bytes = None) -> bytes: ... - def split(self, sep: bytes = None, maxsplit: int = -1) -> List[bytes]: ... + def rsplit(self, sep: Optional[bytes] = None, maxsplit: int = -1) -> List[bytes]: ... + def rstrip(self, chars: Optional[bytes] = None) -> bytes: ... + def split(self, sep: Optional[bytes] = None, maxsplit: int = -1) -> List[bytes]: ... def splitlines(self, keepends: bool = ...) -> List[bytes]: ... def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... - def strip(self, chars: bytes = None) -> bytes: ... + def strip(self, chars: Optional[bytes] = None) -> bytes: ... def swapcase(self) -> bytes: ... def title(self) -> bytes: ... def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... @@ -424,22 +424,22 @@ class bytearray(MutableSequence[int], ByteString): def capitalize(self) -> bytearray: ... def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... if sys.version_info >= (3, 3): - def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def count(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def count(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ... def endswith(self, suffix: bytes) -> bool: ... def expandtabs(self, tabsize: int = 8) -> bytearray: ... if sys.version_info >= (3, 3): - def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def find(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def find(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... if sys.version_info >= (3, 5): def hex(self) -> str: ... if sys.version_info >= (3, 3): - def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def index(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def index(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def insert(self, index: int, object: int) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -451,25 +451,25 @@ class bytearray(MutableSequence[int], ByteString): def join(self, iterable: Iterable[bytes]) -> bytearray: ... def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... def lower(self) -> bytearray: ... - def lstrip(self, chars: bytes = None) -> bytearray: ... + def lstrip(self, chars: Optional[bytes] = None) -> bytearray: ... def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... def replace(self, old: bytes, new: bytes, count: int = -1) -> bytearray: ... if sys.version_info >= (3, 3): - def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rfind(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... if sys.version_info >= (3, 3): - def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = None, end: Optional[int] = None) -> int: ... else: - def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ... + def rindex(self, sub: bytes, start: Optional[int] = None, end: Optional[int] = None) -> int: ... def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... - def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytearray]: ... - def rstrip(self, chars: bytes = None) -> bytearray: ... - def split(self, sep: bytes = None, maxsplit: int = -1) -> List[bytearray]: ... + def rsplit(self, sep: Optional[bytes] = None, maxsplit: int = -1) -> List[bytearray]: ... + def rstrip(self, chars: Optional[bytes] = None) -> bytearray: ... + def split(self, sep: Optional[bytes] = None, maxsplit: int = -1) -> List[bytearray]: ... def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... def startswith(self, prefix: bytes) -> bool: ... - def strip(self, chars: bytes = None) -> bytearray: ... + def strip(self, chars: Optional[bytes] = None) -> bytearray: ... def swapcase(self) -> bytearray: ... def title(self) -> bytearray: ... def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... @@ -556,7 +556,7 @@ class slice: @overload def __init__(self, stop: Optional[int]) -> None: ... @overload - def __init__(self, start: Optional[int], stop: Optional[int], step: int = None) -> None: ... + def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = None) -> None: ... def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -604,7 +604,7 @@ class list(MutableSequence[_T], Generic[_T]): def insert(self, index: int, object: _T) -> None: ... def remove(self, object: _T) -> None: ... def reverse(self) -> None: ... - def sort(self, *, key: Callable[[_T], Any] = None, reverse: bool = ...) -> None: ... + def sort(self, *, key: Optional[Callable[[_T], Any]] = None, reverse: bool = ...) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... @@ -646,7 +646,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... def popitem(self) -> Tuple[_KT, _VT]: ... - def setdefault(self, k: _KT, default: _VT = None) -> _VT: ... + def setdefault(self, k: _KT, default: Optional[_VT] = None) -> _VT: ... @overload def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload @@ -740,7 +740,7 @@ class range(Sequence[int]): @overload def __init__(self, start: int, stop: int, step: int = 1) -> None: ... def count(self, value: int) -> int: ... - def index(self, value: int, start: int = 0, stop: int = None) -> int: ... + def index(self, value: int, start: int = 0, stop: Optional[int] = None) -> int: ... def __len__(self) -> int: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[int]: ... @@ -752,13 +752,14 @@ class range(Sequence[int]): def __reversed__(self) -> Iterator[int]: ... class property: - def __init__(self, fget: Callable[[Any], Any] = None, - fset: Callable[[Any, Any], None] = None, - fdel: Callable[[Any], None] = None, doc: str = None) -> None: ... + def __init__(self, fget: Optional[Callable[[Any], Any]] = None, + fset: Optional[Callable[[Any, Any], None]] = None, + fdel: Optional[Callable[[Any], None]] = None, + doc: Optional[str] = None) -> None: ... def getter(self, fget: Callable[[Any], Any]) -> property: ... def setter(self, fset: Callable[[Any, Any], None]) -> property: ... def deleter(self, fdel: Callable[[Any], None]) -> property: ... - def __get__(self, obj: Any, type: type=None) -> Any: ... + def __get__(self, obj: Any, type: Optional[type] = None) -> Any: ... def __set__(self, obj: Any, value: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... def fget(self) -> Any: ... @@ -782,10 +783,10 @@ def delattr(o: Any, name: str) -> None: ... def dir(o: object = ...) -> List[str]: ... _N = TypeVar('_N', int, float) def divmod(a: _N, b: _N) -> Tuple[_N, _N]: ... -def eval(source: str, globals: Dict[str, Any] = None, - locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source -def exec(object: str, globals: Dict[str, Any] = None, - locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source +def eval(source: str, globals: Optional[Dict[str, Any]] = None, + locals: Optional[Mapping[str, Any]] = None) -> Any: ... # TODO code object as source +def exec(object: str, globals: Optional[Dict[str, Any]] = None, + locals: Optional[Mapping[str, Any]] = None) -> Any: ... # TODO code object as source def exit(code: Any = ...) -> NoReturn: ... @overload def filter(function: Optional[Callable[[_T], Any]], @@ -800,7 +801,7 @@ def hash(o: object) -> int: ... def help(*args: Any, **kwds: Any) -> None: ... def hex(i: int) -> str: ... # TODO __index__ def id(o: object) -> int: ... -def input(prompt: Any = None) -> str: ... +def input(prompt: Optional[Any] = None) -> str: ... @overload def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... @overload @@ -836,15 +837,15 @@ if sys.version_info >= (3, 6): class _PathLike(Generic[AnyStr]): def __fspath__(self) -> AnyStr: ... - def open(file: Union[str, bytes, int, _PathLike], mode: str = 'r', buffering: int = -1, encoding: str = None, - errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ... + def open(file: Union[str, bytes, int, _PathLike], mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, + errors: Optional[str] = None, newline: Optional[str] = None, closefd: bool = ...) -> IO[Any]: ... else: - def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: str = None, - errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ... + def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: Optional[str] = None, + errors: Optional[str] = None, newline: Optional[str] = None, closefd: bool = ...) -> IO[Any]: ... def ord(c: Union[str, bytes, bytearray]) -> int: ... # TODO: in Python 3.2, print() does not support flush -def print(*values: Any, sep: str = ' ', end: str = '\n', file: IO[str] = None, flush: bool = False) -> None: ... +def print(*values: Any, sep: str = ' ', end: str = '\n', file: Optional[IO[str]] = None, flush: bool = False) -> None: ... @overload def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y @overload @@ -853,7 +854,7 @@ def pow(x: int, y: int, z: int) -> Any: ... def pow(x: float, y: float) -> float: ... @overload def pow(x: float, y: float, z: float) -> float: ... -def quit(code: int = None) -> None: ... +def quit(code: Optional[int] = None) -> None: ... @overload def reversed(object: Reversible[_T]) -> Iterator[_T]: ... @overload @@ -868,7 +869,8 @@ def round(number: SupportsRound[_T]) -> _T: ... @overload def round(number: SupportsRound[_T], ndigits: int) -> _T: ... def setattr(object: Any, name: str, value: Any) -> None: ... -def sorted(iterable: Iterable[_T], *, key: Callable[[_T], Any] = None, +def sorted(iterable: Iterable[_T], *, + key: Optional[Callable[[_T], Any]] = None, reverse: bool = False) -> List[_T]: ... def sum(iterable: Iterable[_T], start: _T = ...) -> _T: ... def vars(object: Any = ...) -> Dict[str, Any]: ... diff --git a/stdlib/3/configparser.pyi b/stdlib/3/configparser.pyi index a990d8f31..ff90651ff 100644 --- a/stdlib/3/configparser.pyi +++ b/stdlib/3/configparser.pyi @@ -80,9 +80,9 @@ class RawConfigParser(_parser): def has_option(self, section: str, option: str) -> bool: ... def read(self, filenames: Union[str, Sequence[str]], - encoding: str = None) -> List[str]: ... + encoding: Optional[str] = None) -> List[str]: ... - def read_file(self, f: Iterable[str], source: str = None) -> None: ... + def read_file(self, f: Iterable[str], source: Optional[str] = None) -> None: ... def read_string(self, string: str, source: str = ...) -> None: ... @@ -117,16 +117,16 @@ class RawConfigParser(_parser): class ConfigParser(RawConfigParser): def __init__(self, - defaults: _section = None, + defaults: Optional[_section] = None, dict_type: Mapping[str, str] = ..., allow_no_value: bool = ..., delimiters: Sequence[str] = ..., comment_prefixes: Sequence[str] = ..., - inline_comment_prefixes: Sequence[str] = None, + inline_comment_prefixes: Optional[Sequence[str]] = None, strict: bool = ..., empty_lines_in_values: bool = ..., default_section: str = ..., - interpolation: Interpolation = None, + interpolation: Optional[Interpolation] = None, converters: _converters = ...) -> None: ... class SafeConfigParser(ConfigParser): ... diff --git a/stdlib/3/getpass.pyi b/stdlib/3/getpass.pyi index 73c0cb918..f55023c95 100644 --- a/stdlib/3/getpass.pyi +++ b/stdlib/3/getpass.pyi @@ -1,9 +1,9 @@ # Stubs for getpass -from typing import TextIO +from typing import Optional, TextIO -def getpass(prompt: str = ..., stream: TextIO = None) -> str: ... +def getpass(prompt: str = ..., stream: Optional[TextIO] = None) -> str: ... def getuser() -> str: ... diff --git a/stdlib/3/importlib/__init__.pyi b/stdlib/3/importlib/__init__.pyi index f44c2a799..08b3a8188 100644 --- a/stdlib/3/importlib/__init__.pyi +++ b/stdlib/3/importlib/__init__.pyi @@ -4,14 +4,15 @@ import sys import types from typing import Any, Mapping, Optional, Sequence -def __import__(name: str, globals: Mapping[str, Any] = None, - locals: Mapping[str, Any] = None, fromlist: Sequence[str] = ..., +def __import__(name: str, globals: Optional[Mapping[str, Any]] = None, + locals: Optional[Mapping[str, Any]] = None, + fromlist: Sequence[str] = ..., level: int = ...) -> types.ModuleType: ... -def import_module(name: str, package: str = None) -> types.ModuleType: ... +def import_module(name: str, package: Optional[str] = None) -> types.ModuleType: ... if sys.version_info >= (3, 3): - def find_loader(name: str, path: str = None) -> Optional[Loader]: ... + def find_loader(name: str, path: Optional[str] = None) -> Optional[Loader]: ... def invalidate_caches() -> None: ... diff --git a/stdlib/3/importlib/abc.pyi b/stdlib/3/importlib/abc.pyi index f7c746ac7..f7cd81d21 100644 --- a/stdlib/3/importlib/abc.pyi +++ b/stdlib/3/importlib/abc.pyi @@ -19,7 +19,7 @@ class Finder(metaclass=ABCMeta): # easier to simply ignore that this method exists. # @abstractmethod # def find_module(self, fullname: str, - # path: Sequence[_Path] = None) -> Optional[Loader]: ... + # path: Optional[Sequence[_Path]] = None) -> Optional[Loader]: ... class ResourceLoader(Loader): @abstractmethod @@ -64,7 +64,7 @@ if sys.version_info >= (3, 3): # Not defined on the actual class, but expected to exist. def find_spec( self, fullname: str, path: Optional[Sequence[_Path]], - target: types.ModuleType = None + target: Optional[types.ModuleType] = None ) -> Optional[ModuleSpec]: ... @@ -78,7 +78,7 @@ if sys.version_info >= (3, 3): # Not defined on the actual class, but expected to exist. def find_spec( self, fullname: str, - target: types.ModuleType = None + target: Optional[types.ModuleType] = None ) -> Optional[ModuleSpec]: ... class FileLoader(ResourceLoader, ExecutionLoader): diff --git a/stdlib/3/importlib/machinery.pyi b/stdlib/3/importlib/machinery.pyi index 32be0627e..f9e1907bd 100644 --- a/stdlib/3/importlib/machinery.pyi +++ b/stdlib/3/importlib/machinery.pyi @@ -22,7 +22,7 @@ if sys.version_info >= (3, 3): @classmethod def find_spec(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], - target: types.ModuleType = None) -> Optional[ModuleSpec]: + target: Optional[types.ModuleType] = None) -> Optional[ModuleSpec]: ... # InspectLoader @classmethod @@ -79,7 +79,7 @@ if sys.version_info >= (3, 3): @classmethod def find_spec(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], - target: types.ModuleType = None) -> Optional[ModuleSpec]: + target: Optional[types.ModuleType] = None) -> Optional[ModuleSpec]: ... # InspectLoader @classmethod @@ -136,7 +136,7 @@ if sys.version_info >= (3, 3): @classmethod def find_spec(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], - target: types.ModuleType = None) -> Optional[ModuleSpec]: + target: Optional[types.ModuleType] = None) -> Optional[ModuleSpec]: ... else: class WindowsRegisteryFinder: diff --git a/stdlib/3/importlib/util.pyi b/stdlib/3/importlib/util.pyi index 6f0232b00..0a56b9ca7 100644 --- a/stdlib/3/importlib/util.pyi +++ b/stdlib/3/importlib/util.pyi @@ -20,22 +20,22 @@ if sys.version_info >= (3, 3): if sys.version_info >= (3, 4): MAGIC_NUMBER = ... # type: bytes - def cache_from_source(path: str, debug_override: bool = None, *, - optimization: Any = None) -> str: ... + def cache_from_source(path: str, debug_override: Optional[bool] = None, *, + optimization: Optional[Any] = None) -> str: ... def source_from_cache(path: str) -> str: ... def decode_source(source_bytes: bytes) -> str: ... def find_spec( - name: str, package: str = None + name: str, package: Optional[str] = None ) -> importlib.machinery.ModuleSpec: ... def spec_from_loader( name: str, loader: Optional[importlib.abc.Loader], *, - origin: str = None, loader_state: Any = None, - is_package: bool = None + origin: Optional[str] = None, loader_state: Optional[Any] = None, + is_package: Optional[bool] = None ) -> importlib.machinery.ModuleSpec: ... def spec_from_file_location( name: str, location: str, *, - loader: importlib.abc.Loader = None, - submodule_search_locations: List[str]=None + loader: Optional[importlib.abc.Loader] = None, + submodule_search_locations: Optional[List[str]] = None ) -> importlib.machinery.ModuleSpec: ... if sys.version_info >= (3, 5): diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index a22955bb1..4b1deb742 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -106,8 +106,8 @@ class BytesIO(BinaryIO): def __iter__(self) -> Iterator[bytes]: ... def __next__(self) -> bytes: ... def __enter__(self) -> 'BytesIO': ... - def __exit__(self, t: type = None, value: BaseException = None, - traceback: Any = None) -> bool: ... + def __exit__(self, t: Optional[type] = None, value: Optional[BaseException] = None, + traceback: Optional[Any] = None) -> bool: ... def close(self) -> None: ... def fileno(self) -> int: ... def flush(self) -> None: ... @@ -210,8 +210,8 @@ class TextIOWrapper(TextIO): write_through: bool = ... ) -> None: ... # copied from IOBase - def __exit__(self, t: type = None, value: BaseException = None, - traceback: Any = None) -> bool: ... + def __exit__(self, t: Optional[type] = None, value: Optional[BaseException] = None, + traceback: Optional[Any] = None) -> bool: ... def close(self) -> None: ... def fileno(self) -> int: ... def flush(self) -> None: ... diff --git a/stdlib/3/json/decoder.pyi b/stdlib/3/json/decoder.pyi index 919039eac..1c3e9a05b 100644 --- a/stdlib/3/json/decoder.pyi +++ b/stdlib/3/json/decoder.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, Dict, List, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple if sys.version_info >= (3, 5): class JSONDecodeError(ValueError): @@ -18,11 +18,11 @@ class JSONDecoder: strict = ... # type: bool object_pairs_hook = None # type: Callable[[List[Tuple[str, Any]]], Any] - def __init__(self, object_hook: Callable[[Dict[str, Any]], Any]=None, - parse_float: Callable[[str], Any]=None, - parse_int: Callable[[str], Any]=None, - parse_constant: Callable[[str], Any]=None, - strict: bool=True, - object_pairs_hook: Callable[[List[Tuple[str, Any]]], Any]=None) -> None: ... + def __init__(self, object_hook: Optional[Callable[[Dict[str, Any]], Any]] = None, + parse_float: Optional[Callable[[str], Any]] = None, + parse_int: Optional[Callable[[str], Any]] = None, + parse_constant: Optional[Callable[[str], Any]] = None, + strict: bool = True, + object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], Any]] = None) -> None: ... def decode(self, s: str) -> Any: ... - def raw_decode(self, s: str, idx: int=...) -> Tuple[Any, int]: ... + def raw_decode(self, s: str, idx: int = ...) -> Tuple[Any, int]: ... diff --git a/stdlib/3/json/encoder.pyi b/stdlib/3/json/encoder.pyi index f75304dba..c423c182a 100644 --- a/stdlib/3/json/encoder.pyi +++ b/stdlib/3/json/encoder.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Iterator, Tuple +from typing import Any, Callable, Iterator, Optional, Tuple class JSONEncoder: item_separator = ... # type: str @@ -11,10 +11,10 @@ class JSONEncoder: sort_keys = ... # type: bool indent = None # type: int - def __init__(self, skipkeys: bool=..., ensure_ascii: bool=..., - check_circular: bool=..., allow_nan: bool=..., sort_keys: bool=..., - indent: int=None, separators: Tuple[str, str]=None, default: Callable=None) -> None: ... + def __init__(self, skipkeys: bool = ..., ensure_ascii: bool = ..., + check_circular: bool = ..., allow_nan: bool = ..., sort_keys: bool = ..., + indent: Optional[int] = None, separators: Optional[Tuple[str, str]] = None, default: Optional[Callable] = None) -> None: ... def default(self, o: Any) -> Any: ... def encode(self, o: Any) -> str: ... - def iterencode(self, o: Any, _one_shot: bool=False) -> Iterator[str]: ... + def iterencode(self, o: Any, _one_shot: bool = False) -> Iterator[str]: ... diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index 40aed12f4..da9333533 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -25,7 +25,7 @@ class Pool(): initializer: Optional[Callable[..., None]] = ..., initargs: Iterable[Any] = ..., maxtasksperchild: Optional[int] = ..., - context: Any = None) -> None: ... + context: Optional[Any] = None) -> None: ... def apply(self, func: Callable[..., Any], args: Iterable[Any] = ..., @@ -34,8 +34,8 @@ class Pool(): func: Callable[..., Any], args: Iterable[Any] = ..., kwds: Dict[str, Any] = ..., - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def map(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., @@ -43,8 +43,8 @@ class Pool(): def map_async(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., chunksize: Optional[int] = ..., - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def imap(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., @@ -61,8 +61,8 @@ class Pool(): func: Callable[..., Any], iterable: Iterable[Iterable[Any]] = ..., chunksize: Optional[int] = ..., - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def close(self) -> None: ... def terminate(self) -> None: ... def join(self) -> None: ... diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index af9f9ebae..c3b789393 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -22,17 +22,17 @@ class ThreadPool(): func: Callable[..., Any], args: Iterable[Any] = ..., kwds: Dict[str, Any] = ..., - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def map(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., chunksize: Optional[int] = None) -> List[Any]: ... def map_async(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., - chunksize: Optional[int] = None, - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + chunksize: Optional[Optional[int]] = None, + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def imap(self, func: Callable[..., Any], iterable: Iterable[Any] = ..., @@ -49,8 +49,8 @@ class ThreadPool(): func: Callable[..., Any], iterable: Iterable[Iterable[Any]] = ..., chunksize: Optional[int] = None, - callback: Callable[..., None] = None, - error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ... + callback: Optional[Callable[..., None]] = None, + error_callback: Optional[Callable[[BaseException], None]] = None) -> AsyncResult: ... def close(self) -> None: ... def terminate(self) -> None: ... def join(self) -> None: ... diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index d884fb95c..38b4669d2 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -1,7 +1,7 @@ # Stubs for unittest.mock import sys -from typing import Any +from typing import Any, Optional if sys.version_info >= (3, 3): FILTER_DIR = ... # type: Any @@ -33,7 +33,7 @@ if sys.version_info >= (3, 3): class NonCallableMock(Any): def __new__(cls, *args: Any, **kw: Any) -> Any: ... - def __init__(self, spec: Any = None, wraps: Any = None, name: Any = None, spec_set: Any = None, parent: Any = None, _spec_state: Any = None, _new_name: Any ='', _new_parent: Any = None, _spec_as_instance: Any = False, _eat_self: Any = None, unsafe: Any = False, **kwargs: Any) -> None: ... + def __init__(self, spec: Optional[Any] = None, wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any ='', _new_parent: Optional[Any] = None, _spec_as_instance: Any = False, _eat_self: Optional[Any] = None, unsafe: Any = False, **kwargs: Any) -> None: ... def attach_mock(self, mock: Any, attribute: Any) -> Any: ... def mock_add_spec(self, spec: Any, spec_set: Any = False) -> Any: ... return_value = ... # type: Any @@ -45,7 +45,7 @@ if sys.version_info >= (3, 3): mock_calls = ... # type: Any side_effect = ... # type: Any method_calls = ... # type: Any - def reset_mock(self, visited: bool = None) -> None: ... + def reset_mock(self, visited: Optional[bool] = None) -> None: ... def configure_mock(self, **kwargs: Any) -> None: ... def __getattr__(self, name: Any) -> Any: ... def __dir__(self) -> Any: ... @@ -59,7 +59,7 @@ if sys.version_info >= (3, 3): class CallableMixin(Base): side_effect = ... # type: Any - def __init__(self, spec: Any = None, side_effect: Any = None, return_value: Any = ..., wraps: Any = None, name: Any = None, spec_set: Any = None, parent: Any = None, _spec_state: Any = None, _new_name: Any = '', _new_parent: Any = None, **kwargs: Any) -> None: ... + def __init__(self, spec: Optional[Any] = None, side_effect: Optional[Any] = None, return_value: Any = ..., wraps: Optional[Any] = None, name: Optional[Any] = None, spec_set: Optional[Any] = None, parent: Optional[Any] = None, _spec_state: Optional[Any] = None, _new_name: Any = '', _new_parent: Optional[Any] = None, **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... class Mock(CallableMixin, NonCallableMock): @@ -93,8 +93,8 @@ if sys.version_info >= (3, 3): def stop(self) -> Any: ... class _patcher: - def __call__(self, target: Any, new: Any = None, spec: Any = None, create: Any = False, spec_set: Any = None, autospec: Any = None, new_callable: Any = None, **kwargs: Any) -> Any: ... - def object(self, target: Any, attribute: str, new: Any = None, spec: Any = None, create: Any = False, spec_set: Any = None, autospec: Any = None, new_callable: Any = None, **kwargs: Any) -> _patch: ... + def __call__(self, target: Any, new: Optional[Any] = None, spec: Optional[Any] = None, create: Any = False, spec_set: Optional[Any] = None, autospec: Optional[Any] = None, new_callable: Optional[Any] = None, **kwargs: Any) -> Any: ... + def object(self, target: Any, attribute: str, new: Optional[Any] = None, spec: Optional[Any] = None, create: Any = False, spec_set: Optional[Any] = None, autospec: Optional[Any] = None, new_callable: Optional[Any] = None, **kwargs: Any) -> _patch: ... patch = ... # type: _patcher @@ -127,7 +127,7 @@ if sys.version_info >= (3, 3): def __init__(self, name: Any, parent: Any) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def create_mock(self) -> Any: ... - def __get__(self, obj: Any, _type: Any = None) -> Any: ... + def __get__(self, obj: Any, _type: Optional[Any] = None) -> Any: ... class _ANY: def __eq__(self, other: Any) -> bool: ... @@ -136,11 +136,11 @@ if sys.version_info >= (3, 3): ANY = ... # type: Any class _Call(tuple): - def __new__(cls, value: Any = ..., name: Any = None, parent: Any = None, two: bool = False, from_kall: bool = True) -> Any: ... + def __new__(cls, value: Any = ..., name: Optional[Any] = None, parent: Optional[Any] = None, two: bool = False, from_kall: bool = True) -> Any: ... name = ... # type: Any parent = ... # type: Any from_kall = ... # type: Any - def __init__(self, value: Any = ..., name: Any = None, parent: Any = None, two: bool = False, from_kall: bool = True) -> None: ... + def __init__(self, value: Any = ..., name: Optional[Any] = None, parent: Optional[Any] = None, two: bool = False, from_kall: bool = True) -> None: ... def __eq__(self, other: Any) -> bool: ... __ne__ = ... # type: Any def __call__(self, *args: Any, **kwargs: Any) -> Any: ... @@ -151,7 +151,7 @@ if sys.version_info >= (3, 3): call = ... # type: Any - def create_autospec(spec: Any, spec_set: Any = False, instance: Any = False, _parent: Any = None, _name: Any = None, **kwargs: Any) -> Any: ... + def create_autospec(spec: Any, spec_set: Any = False, instance: Any = False, _parent: Optional[Any] = None, _name: Optional[Any] = None, **kwargs: Any) -> Any: ... class _SpecState: spec = ... # type: Any @@ -160,9 +160,9 @@ if sys.version_info >= (3, 3): parent = ... # type: Any instance = ... # type: Any name = ... # type: Any - def __init__(self, spec: Any, spec_set: Any = False, parent: Any = None, name: Any = None, ids: Any = None, instance: Any = False) -> None: ... + def __init__(self, spec: Any, spec_set: Any = False, parent: Optional[Any] = None, name: Optional[Any] = None, ids: Optional[Any] = None, instance: Any = False) -> None: ... - def mock_open(mock: Any = None, read_data: Any = '') -> Any: ... + def mock_open(mock: Optional[Any] = None, read_data: Any = '') -> Any: ... class PropertyMock(Mock): def __get__(self, obj: Any, obj_type: Any) -> Any: ... diff --git a/third_party/3/six/__init__.pyi b/third_party/3/six/__init__.pyi index 333bd27ce..80f6766b1 100644 --- a/third_party/3/six/__init__.pyi +++ b/third_party/3/six/__init__.pyi @@ -84,12 +84,12 @@ def byte2int(bs: binary_type) -> int: ... def indexbytes(buf: binary_type, i: int) -> int: ... def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... -def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = None) -> None: ... +def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: Optional[str] = None) -> None: ... @overload -def assertRaisesRegex(self: unittest.TestCase, msg: str = None) -> Any: ... +def assertRaisesRegex(self: unittest.TestCase, msg: Optional[str] = None) -> Any: ... @overload def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... -def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: str = None) -> None: ... +def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: Optional[str] = None) -> None: ... exec_ = exec diff --git a/third_party/3/werkzeug/wrappers.pyi b/third_party/3/werkzeug/wrappers.pyi index 59b5b9359..031e37766 100644 --- a/third_party/3/werkzeug/wrappers.pyi +++ b/third_party/3/werkzeug/wrappers.pyi @@ -76,7 +76,14 @@ class BaseResponse: status = ... # type: str direct_passthrough = ... # type: bool response = ... # type: Iterable[bytes] - def __init__(self, response: Union[Iterable[bytes], bytes]=None, status: Union[str, int]=None, headers: Union[Headers, Mapping[str, str], Sequence[Tuple[str, str]]]=None, mimetype: str=None, content_type: str=None, direct_passthrough: bool=False) -> None: ... + def __init__(self, response: Optional[Union[Iterable[bytes], bytes]]=None, + status: Optional[Union[str, int]]=None, + headers: Optional[Union[Headers, + Mapping[str, str], + Sequence[Tuple[str, str]]]]=None, + mimetype: Optional[str] = None, + content_type: Optional[str] = None, + direct_passthrough: bool=False) -> None: ... def call_on_close(self, func): ... @classmethod def force_type(cls, response, environ=None): ...