From ffa0d984b489805a4587f09c5f6c81887c295600 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 22 Feb 2021 19:16:40 +0100 Subject: [PATCH] Use built-in generic --- stdlib/cgi.pyi | 40 +++++++++++++++++++++------------------- stdlib/getopt.pyi | 6 ++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/stdlib/cgi.pyi b/stdlib/cgi.pyi index c868d6521f3d..e940dca89050 100644 --- a/stdlib/cgi.pyi +++ b/stdlib/cgi.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import SupportsGetItem, SupportsItemAccess from builtins import type as _type -from typing import IO, Any, AnyStr, Dict, Iterable, Iterator, List, Mapping, Optional, Protocol, Tuple, TypeVar, Union +from typing import IO, Any, AnyStr, Iterable, Iterator, Mapping, Optional, Protocol, TypeVar, Union _T = TypeVar("_T", bound=FieldStorage) @@ -10,28 +10,28 @@ def parse( environ: SupportsItemAccess[str, str] = ..., keep_blank_values: bool = ..., strict_parsing: bool = ..., -) -> Dict[str, List[str]]: ... +) -> 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]]: ... - def parse_qsl(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> List[Tuple[str, str]]: ... + def parse_qs(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> dict[str, list[str]]: ... + def parse_qsl(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> list[tuple[str, str]]: ... if sys.version_info >= (3, 7): def parse_multipart( fp: IO[Any], pdict: SupportsGetItem[str, bytes], encoding: str = ..., errors: str = ... - ) -> Dict[str, List[Any]]: ... + ) -> dict[str, list[Any]]: ... else: - def parse_multipart(fp: IO[Any], pdict: SupportsGetItem[str, bytes]) -> Dict[str, List[bytes]]: ... + def parse_multipart(fp: IO[Any], pdict: SupportsGetItem[str, bytes]) -> dict[str, list[bytes]]: ... class _Environ(Protocol): def __getitem__(self, __k: str) -> str: ... def keys(self) -> Iterable[str]: ... -def parse_header(line: str) -> Tuple[str, Dict[str, str]]: ... +def parse_header(line: str) -> tuple[str, dict[str, str]]: ... def test(environ: _Environ = ...) -> None: ... def print_environ(environ: _Environ = ...) -> None: ... -def print_form(form: Dict[str, Any]) -> None: ... +def print_form(form: dict[str, Any]) -> None: ... def print_directory() -> None: ... def print_environ_usage() -> None: ... @@ -47,15 +47,17 @@ class MiniFieldStorage: list: Any type: Any file: Optional[IO[bytes]] - type_options: Dict[Any, Any] + type_options: dict[Any, Any] disposition: Any - disposition_options: Dict[Any, Any] - headers: Dict[Any, Any] + disposition_options: dict[Any, Any] + headers: dict[Any, Any] name: Any value: Any def __init__(self, name: Any, value: Any) -> None: ... def __repr__(self) -> str: ... +_list = list + class FieldStorage(object): FieldStorageClass: Optional[_type] keep_blank_values: int @@ -69,16 +71,16 @@ class FieldStorage(object): bytes_read: int limit: Optional[int] disposition: str - disposition_options: Dict[str, str] + disposition_options: dict[str, str] filename: Optional[str] file: Optional[IO[bytes]] type: str - type_options: Dict[str, str] + type_options: dict[str, str] innerboundary: bytes length: int done: int - list: Optional[List[Any]] - value: Union[None, bytes, List[Any]] + list: Optional[_list[Any]] + value: Union[None, bytes, _list[Any]] if sys.version_info >= (3, 6): def __init__( @@ -125,8 +127,8 @@ class FieldStorage(object): def __getitem__(self, key: str) -> Any: ... def getvalue(self, key: str, default: Any = ...) -> Any: ... def getfirst(self, key: str, default: Any = ...) -> Any: ... - def getlist(self, key: str) -> List[Any]: ... - def keys(self) -> List[str]: ... + def getlist(self, key: str) -> _list[Any]: ... + def keys(self) -> _list[str]: ... if sys.version_info < (3, 0): def has_key(self, key: str) -> bool: ... def __contains__(self, key: str) -> bool: ... @@ -144,7 +146,7 @@ class FieldStorage(object): if sys.version_info < (3, 0): from UserDict import UserDict - class FormContentDict(UserDict[str, List[str]]): + class FormContentDict(UserDict[str, list[str]]): query_string: str def __init__(self, environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ... class SvFormContentDict(FormContentDict): @@ -159,4 +161,4 @@ if sys.version_info < (3, 0): def value(self, key: Any) -> Any: ... def length(self, key: Any) -> int: ... def stripped(self, key: Any) -> Any: ... - def pars(self) -> Dict[Any, Any]: ... + def pars(self) -> dict[Any, Any]: ... diff --git a/stdlib/getopt.pyi b/stdlib/getopt.pyi index c92be2a6a8e4..3f4b9211cd11 100644 --- a/stdlib/getopt.pyi +++ b/stdlib/getopt.pyi @@ -1,7 +1,5 @@ -from typing import List, Tuple - -def getopt(args: List[str], shortopts: str, longopts: List[str] = ...) -> Tuple[List[Tuple[str, str]], List[str]]: ... -def gnu_getopt(args: List[str], shortopts: str, longopts: List[str] = ...) -> Tuple[List[Tuple[str, str]], List[str]]: ... +def getopt(args: list[str], shortopts: str, longopts: list[str] = ...) -> tuple[list[tuple[str, str]], list[str]]: ... +def gnu_getopt(args: list[str], shortopts: str, longopts: list[str] = ...) -> tuple[list[tuple[str, str]], list[str]]: ... class GetoptError(Exception): msg: str