Add flags to pass on --warn-unused-ignores and --no-implicit-optional to mypy (#1421)

* Add flags to pass on --warn-unused-ignores and --no-implicit-optional to mypy
* Make implicit Optional explicit in arg types (2and3 part)
* Convert {stdlib,third_party}/2 to explicit Optional
This commit is contained in:
Guido van Rossum
2017-06-20 22:18:49 -07:00
committed by Jelle Zijlstra
parent 30256097ea
commit 04fe184dcf
23 changed files with 257 additions and 237 deletions

View File

@@ -485,7 +485,7 @@ class slice(object):
@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]):
@@ -676,13 +676,13 @@ class xrange(Sized, Iterable[int], Reversible[int]):
def __reversed__(self) -> Iterator[int]: ...
class property(object):
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: ...
@@ -716,7 +716,7 @@ def filter(function: Callable[[_T], Any],
def filter(function: None,
iterable: Iterable[Optional[_T]]) -> List[_T]: ...
def format(o: object, format_spec: str = '') -> str: ... # TODO unicode
def getattr(o: Any, name: unicode, default: Any = None) -> Any: ...
def getattr(o: Any, name: unicode, default: Optional[Any] = None) -> Any: ...
def hasattr(o: Any, name: unicode) -> bool: ...
def hash(o: object) -> int: ...
def hex(i: int) -> str: ... # TODO __index__
@@ -941,12 +941,12 @@ class ResourceWarning(Warning): ...
def eval(s: str, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ...) -> Any: ...
def exec(object: str,
globals: Dict[str, Any] = None,
locals: Dict[str, Any] = None) -> Any: ... # TODO code object as source
globals: Optional[Dict[str, Any]] = None,
locals: Optional[Dict[str, Any]] = None) -> Any: ... # TODO code object as source
def cmp(x: Any, y: Any) -> int: ...
def execfile(filename: str, globals: Dict[str, Any] = None, locals: Dict[str, Any] = None) -> None: ...
def execfile(filename: str, globals: Optional[Dict[str, Any]] = None, locals: Optional[Dict[str, Any]] = None) -> None: ...
class file(BinaryIO):
@overload
@@ -958,7 +958,7 @@ class file(BinaryIO):
def __iter__(self) -> Iterator[str]: ...
def read(self, n: int = ...) -> str: ...
def __enter__(self) -> BinaryIO: ...
def __exit__(self, t: type = None, exc: BaseException = None, tb: Any = None) -> bool: ...
def __exit__(self, t: Optional[type] = None, exc: Optional[BaseException] = None, tb: Optional[Any] = None) -> bool: ...
def flush(self) -> None: ...
def fileno(self) -> int: ...
def isatty(self) -> bool: ...
@@ -976,6 +976,6 @@ class file(BinaryIO):
def truncate(self, pos: Optional[int] = ...) -> int: ...
# Very old builtins
def apply(func: Callable[..., _T], args: Sequence[Any] = None, kwds: Mapping[str, Any] = None) -> _T: ...
def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = None, kwds: Optional[Mapping[str, Any]] = None) -> _T: ...
_N = TypeVar('_N', bool, int, float, complex)
def coerce(x: _N, y: _N) -> Tuple[_N, _N]: ...

View File

@@ -41,7 +41,7 @@ class Request(object):
def add_header(self, key: str, val: str) -> None: ...
def add_unredirected_header(self, key: str, val: str) -> None: ...
def has_header(self, header_name: str) -> bool: ...
def get_header(self, header_name: str, default: str = None) -> str: ...
def get_header(self, header_name: str, default: Optional[str] = None) -> str: ...
def header_items(self): ...
class OpenerDirector(object):

View File

@@ -2,7 +2,7 @@ from abc import abstractmethod
import asyncore
import socket
import sys
from typing import Union, Tuple, Sequence
from typing import Optional, Sequence, Tuple, Union
class simple_producer:
@@ -12,7 +12,7 @@ class simple_producer:
class async_chat(asyncore.dispatcher):
ac_in_buffer_size = ... # type: int
ac_out_buffer_size = ... # type: int
def __init__(self, sock: socket.socket = None, map: asyncore._maptype = None) -> None: ...
def __init__(self, sock: Optional[socket.socket] = None, map: Optional[asyncore._maptype] = None) -> None: ...
@abstractmethod
def collect_incoming_data(self, data: bytes) -> None: ...

View File

@@ -25,7 +25,7 @@ def poll2(timeout: float = ..., map: _maptype = ...) -> None: ...
poll3 = poll2
def loop(timeout: float = ..., use_poll: bool = ..., map: _maptype = ..., count: int = None) -> None: ...
def loop(timeout: float = ..., use_poll: bool = ..., map: _maptype = ..., count: Optional[int] = None) -> None: ...
# Not really subclass of socket.socket; it's only delegation.
@@ -39,7 +39,7 @@ class dispatcher:
closing = ... # type: bool
ignore_log_types = ... # type: frozenset[str]
def __init__(self, sock: socket.socket = None, map: _maptype = ...) -> None: ...
def __init__(self, sock: Optional[socket.socket] = None, map: _maptype = ...) -> None: ...
def add_channel(self, map: _maptype = ...) -> None: ...
def del_channel(self, map: _maptype = ...) -> None: ...
def create_socket(self, family: int, type: int) -> None: ...

View File

@@ -1,21 +1,21 @@
# Stubs for bz2
from typing import Any, BinaryIO, TextIO, IO, Union
from typing import Any, BinaryIO, TextIO, IO, Optional, Union
def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
def decompress(data: bytes) -> bytes: ...
def open(filename: Union[str, bytes, IO[Any]],
mode: str = 'rb',
encoding: str = None,
errors: str = None,
newline: str = None) -> IO[Any]: ...
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None) -> IO[Any]: ...
class BZ2File(BinaryIO):
def __init__(self,
filename: Union[str, bytes, IO[Any]],
mode: str = "r",
buffering: Any = None,
buffering: Optional[Any] = None,
compresslevel: int = 9) -> None: ...
class BZ2Compressor(object):

View File

@@ -1,15 +1,15 @@
# NOTE: This stub is incomplete - only contains some global functions
from typing import Any, Dict
from typing import Any, Dict, Optional
def run(statement: str,
globals: Dict[str, Any] = None,
locals: Dict[str, Any] = None) -> None:
globals: Optional[Dict[str, Any]] = None,
locals: Optional[Dict[str, Any]] = None) -> None:
...
def runeval(expression: str,
globals: Dict[str, Any] = None,
locals: Dict[str, Any] = None) -> Any:
globals: Optional[Dict[str, Any]] = None,
locals: Optional[Dict[str, Any]] = None) -> Any:
...
def runctx(statement: str,
@@ -23,7 +23,7 @@ def runcall(*args: Any, **kwds: Any) -> Any:
def set_trace() -> None:
...
def post_mortem(t: Any = None) -> None:
def post_mortem(t: Optional[Any] = None) -> None:
...
def pm() -> None: