Improve csv module and float() signature (#1418)

* DictReader should not be abstract. Reformat long lines.
* Make restval optional for DictWriter.__init__.
* The arg to reader() is *Iterable*, not *Iterator*.
* Improve signature of float() (use Union instead of overload).
This commit is contained in:
Guido van Rossum
2017-06-20 13:04:10 -07:00
committed by Matthias Kramm
parent 945527dbc0
commit 86070643ac
3 changed files with 33 additions and 16 deletions

View File

@@ -144,14 +144,7 @@ class int(SupportsInt, SupportsFloat, SupportsAbs[int]):
def __nonzero__(self) -> bool: ...
class float(SupportsFloat, SupportsInt, SupportsAbs[float]):
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, x: SupportsFloat) -> None: ...
@overload
def __init__(self, x: unicode) -> None: ...
@overload
def __init__(self, x: bytearray) -> None: ...
def __init__(self, x: Union[SupportsFloat, str, unicode, bytearray] = ...) -> None: ...
def as_integer_ratio(self) -> Tuple[int, int]: ...
def hex(self) -> str: ...
def is_integer(self) -> bool: ...

View File

@@ -37,7 +37,7 @@ class _writer:
# TODO: precise type
def writer(csvfile: Any, dialect: Any = ..., **fmtparams: Any) -> _writer: ...
def reader(csvfile: Iterator[str], dialect: Any = ..., **fmtparams: Any) -> _reader: ...
def reader(csvfile: Iterable[str], dialect: Any = ..., **fmtparams: Any) -> _reader: ...
def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ...
def unregister_dialect(name: str) -> None: ...
def get_dialect(name: str) -> Dialect: ...

View File

@@ -2,12 +2,26 @@ from collections import OrderedDict
import sys
from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Union
from _csv import _reader, _writer, reader as reader, writer as writer, register_dialect as register_dialect, unregister_dialect as unregister_dialect, get_dialect as get_dialect, list_dialects as list_dialects, field_size_limit as field_size_limit, QUOTE_ALL as QUOTE_ALL, QUOTE_MINIMAL as QUOTE_MINIMAL, QUOTE_NONE as QUOTE_NONE, QUOTE_NONNUMERIC as QUOTE_NONNUMERIC, Error as Error
from _csv import (_reader,
_writer,
reader as reader,
writer as writer,
register_dialect as register_dialect,
unregister_dialect as unregister_dialect,
get_dialect as get_dialect,
list_dialects as list_dialects,
field_size_limit as field_size_limit,
QUOTE_ALL as QUOTE_ALL,
QUOTE_MINIMAL as QUOTE_MINIMAL,
QUOTE_NONE as QUOTE_NONE,
QUOTE_NONNUMERIC as QUOTE_NONNUMERIC,
Error as Error,
)
_Dialect = Union[str, Dialect]
_DictRow = Dict[str, Any]
class Dialect:
class Dialect(object):
delimiter = ... # type: str
quotechar = ... # type: Optional[str]
escapechar = ... # type: Optional[str]
@@ -45,7 +59,11 @@ if sys.version_info >= (3, 6):
dialect = ... # type: _Dialect
line_num = ... # type: int
fieldnames = ... # type: Sequence[str]
def __init__(self, f: Iterator[str], fieldnames: Sequence[str] = ..., restkey: Optional[str] = ..., restval: Optional[str] = ..., dialect: _Dialect = ..., *args: Any, **kwds: Any) -> None: ...
def __init__(self, f: Iterator[str], fieldnames: Sequence[str] = ...,
restkey: Optional[str] = ..., restval: Optional[str] = ..., dialect: _Dialect = ...,
*args: Any, **kwds: Any) -> None: ...
def __iter__(self) -> Iterator[OrderedDict[str, str]]: ...
def next(self) -> OrderedDict[str, str]: ...
else:
class DictReader(Iterator[Dict[str, str]]):
restkey = ... # type: Optional[str]
@@ -54,19 +72,25 @@ else:
dialect = ... # type: _Dialect
line_num = ... # type: int
fieldnames = ... # type: Sequence[str]
def __init__(self, f: Iterator[str], fieldnames: Sequence[str] = ..., restkey: Optional[str] = ..., restval: Optional[str] = ..., dialect: _Dialect = ..., *args: Any, **kwds: Any) -> None: ...
def __init__(self, f: Iterator[str], fieldnames: Sequence[str] = ...,
restkey: Optional[str] = ..., restval: Optional[str] = ..., dialect: _Dialect = ...,
*args: Any, **kwds: Any) -> None: ...
def __iter__(self) -> Iterator[OrderedDict[str, str]]: ...
def next(self) -> OrderedDict[str, str]: ...
class DictWriter:
class DictWriter(object):
fieldnames = ... # type: Sequence[str]
restval = ... # type: Optional[Any]
extrasaction = ... # type: str
writer = ... # type: _writer
def __init__(self, f: Any, fieldnames: Sequence[str], restval: Optional[Any], extrasaction: str = ..., dialect: _Dialect = ..., *args: Any, **kwds: Any) -> None: ...
def __init__(self, f: Any, fieldnames: Sequence[str],
restval: Optional[Any] = ..., extrasaction: str = ..., dialect: _Dialect = ...,
*args: Any, **kwds: Any) -> None: ...
def writeheader(self) -> None: ...
def writerow(self, rowdict: _DictRow) -> None: ...
def writerows(self, rowdicts: Iterable[_DictRow]) -> None: ...
class Sniffer:
class Sniffer(object):
preferred = ... # type: List[str]
def __init__(self) -> None: ...
def sniff(self, sample: str, delimiters: Optional[str] = ...) -> Dialect: ...