Added a few missing type arguments for generic types used in stdlib stubs

I just found and fixed a bug in pyright's "missing type arguments" check. When type arguments were omitted for a generic type within a subscript expression, the error was being suppressed. With this bug fixed, I found several new cases where type arguments were missing in stdlib stubs. (#5130)

Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
Eric Traut
2021-03-22 18:28:04 -07:00
committed by GitHub
parent a68fb50788
commit 0ec182227c
11 changed files with 15 additions and 14 deletions

View File

@@ -174,11 +174,11 @@ class SupportsWrite(Protocol[_T_contra]):
def write(self, __s: _T_contra) -> Any: ...
if sys.version_info >= (3,):
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array, mmap.mmap]
WriteableBuffer = Union[bytearray, memoryview, array.array, mmap.mmap]
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap]
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap]
else:
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array, mmap.mmap, buffer]
WriteableBuffer = Union[bytearray, memoryview, array.array, mmap.mmap, buffer]
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
if sys.version_info >= (3, 10):
from types import NoneType as NoneType

View File

@@ -7,7 +7,7 @@ from typing import Any, Dict, Iterable, Optional, Tuple, Union, overload
class _HasWrapper:
__wrapper__: Union[_HasWrapper, FunctionType]
_FuncType = Union[FunctionType, _HasWrapper, functools.partial, functools.partialmethod]
_FuncType = Union[FunctionType, _HasWrapper, functools.partial[Any], functools.partialmethod[Any]]
if sys.version_info >= (3, 7):
@overload

View File

@@ -5,7 +5,7 @@ from typing import Any, BinaryIO, Iterable, List, NoReturn, Optional, Tuple, Typ
if sys.version_info >= (3, 8):
# These are based in socket, maybe move them out into _typeshed.pyi or such
_Address = Union[tuple, str]
_Address = Union[Tuple[Any, ...], str]
_RetAddress = Any
_WriteBuffer = Union[bytearray, memoryview]
_CMSG = Tuple[int, int, bytes]

View File

@@ -72,7 +72,7 @@ pythonapi: PyDLL = ...
# Anything that implements the read-write buffer interface.
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
_WritableBuffer = _UnionT[bytearray, memoryview, array, _CData]
_WritableBuffer = _UnionT[bytearray, memoryview, array[Any], _CData]
# Same as _WritableBuffer, but also includes read-only buffer types (like bytes).
_ReadOnlyBuffer = _UnionT[_WritableBuffer, bytes]

View File

@@ -86,7 +86,7 @@ def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: int = ...) -> int: ...
def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: bytes) -> bytes: ...
_ReadOnlyBuffer = bytes
_WritableBuffer = Union[bytearray, memoryview, array]
_WritableBuffer = Union[bytearray, memoryview, array[Any]]
@overload
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: int = ..., __mutate_flag: bool = ...) -> int: ...
@overload

View File

@@ -1,4 +1,5 @@
import sys
from typing import Any
# This is a >=3.7 module, so we conditionally include its source.
if sys.version_info >= (3, 7):
@@ -8,7 +9,7 @@ if sys.version_info >= (3, 7):
from typing import BinaryIO, ContextManager, Iterator, TextIO, Union
Package = Union[str, ModuleType]
Resource = Union[str, os.PathLike]
Resource = Union[str, os.PathLike[Any]]
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ...
def read_binary(package: Package, resource: Resource) -> bytes: ...

View File

@@ -19,7 +19,7 @@ XML_PARAM_ENTITY_PARSING_NEVER: int
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int
XML_PARAM_ENTITY_PARSING_ALWAYS: int
_Model = Tuple[int, int, Optional[str], tuple]
_Model = Tuple[int, int, Optional[str], Tuple[Any, ...]]
class XMLParserType(object):
def Parse(self, __data: Union[Text, bytes], __isfinal: bool = ...) -> int: ...

View File

@@ -604,7 +604,7 @@ class timeout(error):
# Addresses can be either tuples of varying lengths (AF_INET, AF_INET6,
# AF_NETLINK, AF_TIPC) or strings (AF_UNIX).
_Address = Union[tuple, str]
_Address = Union[Tuple[Any, ...], str]
_RetAddress = Any
# TODO Most methods allow bytes as address objects

View File

@@ -8,7 +8,7 @@ class error(Exception): ...
_FmtType = Union[bytes, Text]
if sys.version_info >= (3,):
_BufferType = Union[array[int], bytes, bytearray, memoryview, mmap]
_WriteBufferType = Union[array, bytearray, memoryview, mmap]
_WriteBufferType = Union[array[Any], bytearray, memoryview, mmap]
else:
_BufferType = Union[array[int], bytes, bytearray, buffer, memoryview, mmap]
_WriteBufferType = Union[array[Any], bytearray, buffer, memoryview, mmap]

View File

@@ -13,7 +13,7 @@ class _SupportsTimeTuple(Protocol):
def timetuple(self) -> time.struct_time: ...
_DateTimeComparable = Union[DateTime, datetime, str, _SupportsTimeTuple]
_Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime, DateTime, Binary]
_Marshallable = Union[None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime, DateTime, Binary]
_XMLDate = Union[int, datetime, Tuple[int, ...], time.struct_time]
_HostType = Union[Tuple[str, Dict[str, str]], str]

View File

@@ -7,7 +7,7 @@ from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Patte
from xmlrpc.client import Fault
_Marshallable = Union[
None, bool, int, float, str, bytes, tuple, list, dict, datetime
None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime
] # TODO: Recursive type on tuple, list, dict
# The dispatch accepts anywhere from 0 to N arguments, no easy way to allow this in mypy