Add Optional[] for all remaining cases of x: <type> = None (#1424)

* Final round of adding Optional[] to type of arguments with default = None
* Update Travis to use --no-implicit-optionals and clarify CONTRIBUTING.md
This commit is contained in:
Guido van Rossum
2017-06-21 10:50:21 -07:00
committed by Matthias Kramm
parent 81f77b17ec
commit 350563223f
18 changed files with 152 additions and 133 deletions

View File

@@ -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]: ...