From 558d88ef922de81fbcac102d28208c8face6feaa Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sat, 29 Feb 2020 05:18:06 -0800 Subject: [PATCH] cgi: various improvements (#3790) - add max_num_fields to FieldStorage - fix various types based on default values --- stdlib/2and3/cgi.pyi | 16 ++++++++++------ tests/stubtest_whitelists/py35.txt | 1 - tests/stubtest_whitelists/py36.txt | 1 - tests/stubtest_whitelists/py37.txt | 1 - tests/stubtest_whitelists/py3_common.txt | 3 --- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/stdlib/2and3/cgi.pyi b/stdlib/2and3/cgi.pyi index 5d901d93d..8211f5163 100644 --- a/stdlib/2and3/cgi.pyi +++ b/stdlib/2and3/cgi.pyi @@ -3,7 +3,7 @@ from typing import Any, AnyStr, Dict, IO, Iterable, List, Mapping, Optional, Tup _T = TypeVar('_T', bound=FieldStorage) -def parse(fp: IO[Any] = ..., environ: Mapping[str, str] = ..., +def parse(fp: Optional[IO[Any]] = ..., environ: Mapping[str, str] = ..., keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ... if sys.version_info < (3, 8): def parse_qs(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ... @@ -12,7 +12,7 @@ if sys.version_info >= (3, 7): def parse_multipart(fp: IO[Any], pdict: Mapping[str, bytes], encoding: str = ..., errors: str = ...) -> Dict[str, List[Any]]: ... else: def parse_multipart(fp: IO[Any], pdict: Mapping[str, bytes]) -> Dict[str, List[bytes]]: ... -def parse_header(s: str) -> Tuple[str, Dict[str, str]]: ... +def parse_header(line: str) -> Tuple[str, Dict[str, str]]: ... def test(environ: Mapping[str, str] = ...) -> None: ... def print_environ(environ: Mapping[str, str] = ...) -> None: ... def print_form(form: Dict[str, Any]) -> None: ... @@ -21,7 +21,7 @@ def print_environ_usage() -> None: ... if sys.version_info < (3,): def escape(s: AnyStr, quote: bool = ...) -> AnyStr: ... elif sys.version_info < (3, 8): - def escape(s: str, quote: bool = ...) -> str: ... + def escape(s: str, quote: Optional[bool] = ...) -> str: ... class MiniFieldStorage: # The first five "Any" attributes here are always None, but mypy doesn't support that @@ -64,10 +64,14 @@ class FieldStorage(object): list: Optional[List[Any]] value: Union[None, bytes, List[Any]] - if sys.version_info >= (3, 0): - def __init__(self, fp: IO[Any] = ..., headers: Mapping[str, str] = ..., outerboundary: bytes = ..., + if sys.version_info >= (3, 6): + def __init__(self, fp: Optional[IO[Any]] = ..., headers: Optional[Mapping[str, str]] = ..., outerboundary: bytes = ..., environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ..., - limit: int = ..., encoding: str = ..., errors: str = ...) -> None: ... + limit: Optional[int] = ..., encoding: str = ..., errors: str = ..., max_num_fields: Optional[int] = ...) -> None: ... + elif sys.version_info >= (3, 0): + def __init__(self, fp: Optional[IO[Any]] = ..., headers: Optional[Mapping[str, str]] = ..., outerboundary: bytes = ..., + environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ..., + limit: Optional[int] = ..., encoding: str = ..., errors: str = ...) -> None: ... else: def __init__(self, fp: IO[Any] = ..., headers: Mapping[str, str] = ..., outerboundary: bytes = ..., environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ... diff --git a/tests/stubtest_whitelists/py35.txt b/tests/stubtest_whitelists/py35.txt index a34230f81..bd9b5cfc7 100644 --- a/tests/stubtest_whitelists/py35.txt +++ b/tests/stubtest_whitelists/py35.txt @@ -17,7 +17,6 @@ asyncio.runners asyncio.tasks.Task.__init__ bdb.GENERATOR_AND_COROUTINE_FLAGS builtins.str.maketrans -cgi.escape cmath.log codecs.StreamRecoder.seek collections.Reversible diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index 5648ba139..69eaaecb1 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -9,7 +9,6 @@ asyncio.protocols.BufferedProtocol asyncio.runners asyncio.tasks.Task._wakeup builtins.str.maketrans -cgi.escape cmath.log codecs.StreamRecoder.seek collections.AsyncGenerator.ag_await diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index 1e9428cd5..8611d110a 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -22,7 +22,6 @@ asyncio.selector_events.BaseSelectorEventLoop.create_unix_server builtins.dict.get builtins.reversed builtins.str.maketrans -cgi.escape cmath.log collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index f3547480a..10be133d3 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -125,9 +125,6 @@ bz2.BZ2File.readinto bz2.BZ2File.readlines bz2.BZ2File.write bz2.BZ2File.writelines -cgi.FieldStorage.__init__ -cgi.parse -cgi.parse_header codecs.BufferedIncrementalDecoder.decode codecs.CodecInfo.decode codecs.CodecInfo.encode