Skip to content

Use built-in generics #5050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions stdlib/cgi.pyi
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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: ...

Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? It seems a bit weird to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it maybe because of this?

list: Optional[_list[Any]]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, without the type alias, there is an error, since list is aliased by this.


class FieldStorage(object):
FieldStorageClass: Optional[_type]
keep_blank_values: int
Expand All @@ -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__(
Expand Down Expand Up @@ -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: ...
Expand All @@ -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):
Expand All @@ -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]: ...
6 changes: 2 additions & 4 deletions stdlib/getopt.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down