Use protocol for print() file argument (#2848)

Also, use object instead of Any for values list
This commit is contained in:
Sebastian Rittau
2019-03-13 03:26:32 +01:00
committed by Jelle Zijlstra
parent cd088c44d2
commit 26fefcc704
2 changed files with 14 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ from typing import (
Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
SupportsComplex, SupportsRound, IO, BinaryIO, Union,
ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text,
Protocol,
)
from abc import abstractmethod, ABCMeta
from ast import mod
@@ -1316,10 +1317,14 @@ else:
def ord(c: Union[Text, bytes]) -> int: ...
if sys.version_info >= (3,):
def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ...
class _Writer(Protocol):
def write(self, s: str) -> Any: ...
def print(*values: object, sep: Text = ..., end: Text = ..., file: Optional[_Writer] = ..., flush: bool = ...) -> None: ...
else:
class _Writer(Protocol):
def write(self, s: Any) -> Any: ...
# This is only available after from __future__ import print_function.
def print(*values: Any, sep: Text = ..., end: Text = ..., file: Optional[IO[Any]] = ...) -> None: ...
def print(*values: object, sep: Text = ..., end: Text = ..., file: Optional[_Writer] = ...) -> None: ...
@overload
def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y
@overload