Skip to content

Commit

Permalink
Added missing type annotations in various stdlib stubs. (#4402)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Traut <erictr@microsoft.com>
  • Loading branch information
erictraut and msfterictraut authored Aug 7, 2020
1 parent 10a5b07 commit baaffed
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
3 changes: 2 additions & 1 deletion stdlib/2and3/imaplib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sys
import time
from socket import socket as _socket
from ssl import SSLContext, SSLSocket
from types import TracebackType
from typing import IO, Any, Callable, Dict, List, Optional, Pattern, Text, Tuple, Type, Union
from typing_extensions import Literal

Expand Down Expand Up @@ -60,7 +61,7 @@ class IMAP4:
if sys.version_info >= (3, 5):
def enable(self, capability: str) -> _CommandResults: ...
def __enter__(self) -> IMAP4: ...
def __exit__(self, *args) -> None: ...
def __exit__(self, t: Optional[Type[BaseException]], v: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...
def expunge(self) -> _CommandResults: ...
def fetch(self, message_set: str, message_parts: str) -> Tuple[str, _AnyResponseData]: ...
def getacl(self, mailbox: str) -> _CommandResults: ...
Expand Down
26 changes: 13 additions & 13 deletions stdlib/2and3/pydoc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class HTMLDoc(Doc):
marginalia: Optional[str] = ...,
gap: str = ...,
) -> str: ...
def bigsection(self, title: str, *args) -> str: ...
def bigsection(self, title: str, *args: Any) -> str: ...
def preformat(self, text: str) -> str: ...
def multicolumn(self, list: List[Any], format: Callable[[Any], str], cols: int = ...) -> str: ...
def grey(self, text: str) -> str: ...
Expand All @@ -119,15 +119,15 @@ class HTMLDoc(Doc):
def formattree(
self, tree: List[Union[Tuple[type, Tuple[type, ...]], List[Any]]], modname: str, parent: Optional[type] = ...
) -> str: ...
def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ...
def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored: Any) -> str: ...
def docclass(
self,
object: object,
name: Optional[str] = ...,
mod: Optional[str] = ...,
funcs: Mapping[str, str] = ...,
classes: Mapping[str, str] = ...,
*ignored,
*ignored: Any,
) -> str: ...
def formatvalue(self, object: object) -> str: ...
def docroutine(
Expand All @@ -139,14 +139,14 @@ class HTMLDoc(Doc):
classes: Mapping[str, str] = ...,
methods: Mapping[str, str] = ...,
cl: Optional[type] = ...,
*ignored,
*ignored: Any,
) -> str: ...
def docproperty(
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored: Any
) -> str: ...
def docother(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored) -> str: ...
def docother(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored: Any) -> str: ...
def docdata(
self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored
self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored: Any
) -> str: ...
def index(self, dir: str, shadowed: Optional[MutableMapping[str, bool]] = ...) -> str: ...
def filelink(self, url: str, path: str) -> str: ...
Expand Down Expand Up @@ -175,17 +175,17 @@ class TextDoc(Doc):
parent: Optional[type] = ...,
prefix: str = ...,
) -> str: ...
def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored) -> str: ...
def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ...
def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored: Any) -> str: ...
def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored: Any) -> str: ...
def formatvalue(self, object: object) -> str: ...
def docroutine(
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored: Any
) -> str: ...
def docproperty(
self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored
self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored: Any
) -> str: ...
def docdata(
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored
self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored: Any
) -> str: ...
def docother(
self,
Expand All @@ -195,7 +195,7 @@ class TextDoc(Doc):
parent: Optional[str] = ...,
maxlen: Optional[int] = ...,
doc: Optional[Any] = ...,
*ignored,
*ignored: Any,
) -> str: ...

def pager(text: str) -> None: ...
Expand Down
44 changes: 21 additions & 23 deletions stdlib/2and3/sqlite3/dbapi2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Date = date
Time = time
Timestamp = datetime

def DateFromTicks(ticks): ...
def TimeFromTicks(ticks): ...
def TimestampFromTicks(ticks): ...
def DateFromTicks(ticks: float) -> Date: ...
def TimeFromTicks(ticks: float) -> Time: ...
def TimestampFromTicks(ticks: float) -> Timestamp: ...

version_info: str
sqlite_version_info: Tuple[int, int, int]
Expand All @@ -26,8 +26,6 @@ if sys.version_info >= (3,):
else:
Binary = buffer

def register_adapters_and_converters(): ...

# The remaining definitions are imported from _sqlite3.

PARSE_COLNAMES: int
Expand Down Expand Up @@ -134,7 +132,7 @@ class Connection(object):
row_factory: Any
text_factory: Any
total_changes: Any
def __init__(self, *args, **kwargs): ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def close(self) -> None: ...
def commit(self) -> None: ...
def create_aggregate(self, name: str, num_params: int, aggregate_class: type) -> None: ...
Expand All @@ -148,16 +146,16 @@ class Connection(object):
# TODO: please check in executemany() if seq_of_parameters type is possible like this
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable[Any]]) -> Cursor: ...
def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ...
def interrupt(self, *args, **kwargs) -> None: ...
def iterdump(self, *args, **kwargs) -> Generator[str, None, None]: ...
def rollback(self, *args, **kwargs) -> None: ...
def interrupt(self, *args: Any, **kwargs: Any) -> None: ...
def iterdump(self, *args: Any, **kwargs: Any) -> Generator[str, None, None]: ...
def rollback(self, *args: Any, **kwargs: Any) -> None: ...
# TODO: set_authorizer(authorzer_callback)
# see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_authorizer
# returns [SQLITE_OK, SQLITE_DENY, SQLITE_IGNORE] so perhaps int
def set_authorizer(self, *args, **kwargs) -> None: ...
def set_authorizer(self, *args: Any, **kwargs: Any) -> None: ...
# set_progress_handler(handler, n) -> see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_progress_handler
def set_progress_handler(self, *args, **kwargs) -> None: ...
def set_trace_callback(self, *args, **kwargs): ...
def set_progress_handler(self, *args: Any, **kwargs: Any) -> None: ...
def set_trace_callback(self, *args: Any, **kwargs: Any) -> None: ...
# enable_load_extension and load_extension is not available on python distributions compiled
# without sqlite3 loadable extension support. see footnotes https://docs.python.org/3/library/sqlite3.html#f1
def enable_load_extension(self, enabled: bool) -> None: ...
Expand All @@ -172,9 +170,9 @@ class Connection(object):
name: str = ...,
sleep: float = ...,
) -> None: ...
def __call__(self, *args, **kwargs): ...
def __enter__(self, *args, **kwargs) -> Connection: ...
def __exit__(self, *args, **kwargs): ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def __enter__(self) -> Connection: ...
def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> None: ...

class Cursor(Iterator[Any]):
arraysize: Any
Expand All @@ -186,16 +184,16 @@ class Cursor(Iterator[Any]):
# TODO: Cursor class accepts exactly 1 argument
# required type is sqlite3.Connection (which is imported as _Connection)
# however, the name of the __init__ variable is unknown
def __init__(self, *args, **kwargs) -> None: ...
def close(self, *args, **kwargs) -> None: ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def close(self, *args: Any, **kwargs: Any) -> None: ...
def execute(self, sql: str, parameters: Iterable[Any] = ...) -> Cursor: ...
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable[Any]]) -> Cursor: ...
def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ...
def fetchall(self) -> List[Any]: ...
def fetchmany(self, size: Optional[int] = ...) -> List[Any]: ...
def fetchone(self) -> Any: ...
def setinputsizes(self, *args, **kwargs) -> None: ...
def setoutputsize(self, *args, **kwargs) -> None: ...
def setinputsizes(self, *args: Any, **kwargs: Any) -> None: ...
def setoutputsize(self, *args: Any, **kwargs: Any) -> None: ...
def __iter__(self) -> Cursor: ...
if sys.version_info >= (3, 0):
def __next__(self) -> Any: ...
Expand Down Expand Up @@ -280,21 +278,21 @@ else:
def __rmul__(self, other): ...

class PrepareProtocol(object):
def __init__(self, *args, **kwargs): ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class ProgrammingError(DatabaseError): ...

class Row(object):
def __init__(self, *args, **kwargs): ...
def keys(self, *args, **kwargs): ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def keys(self, *args: Any, **kwargs: Any): ...
def __eq__(self, other): ...
def __ge__(self, other): ...
def __getitem__(self, index): ...
def __gt__(self, other): ...
def __hash__(self): ...
def __iter__(self): ...
def __le__(self, other): ...
def __len__(self, *args, **kwargs): ...
def __len__(self, *args: Any, **kwargs: Any): ...
def __lt__(self, other): ...
def __ne__(self, other): ...

Expand Down
4 changes: 3 additions & 1 deletion stdlib/2and3/xml/dom/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

class Node:
ELEMENT_NODE: int
ATTRIBUTE_NODE: int
Expand Down Expand Up @@ -32,7 +34,7 @@ VALIDATION_ERR: int

class DOMException(Exception):
code: int
def __init__(self, *args, **kw) -> None: ...
def __init__(self, *args: Any, **kw: Any) -> None: ...
def _get_code(self) -> int: ...

class IndexSizeErr(DOMException): ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/3.9/zoneinfo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import typing
from datetime import tzinfo
from typing import Any, Iterable, Optional, Protocol, Sequence, Set, Type, Union
from typing import Any, AnyStr, Iterable, Optional, Protocol, Sequence, Set, Type, Union

_T = typing.TypeVar("_T", bound="ZoneInfo")

Expand All @@ -23,7 +23,7 @@ class ZoneInfo(tzinfo):
# Note: Both here and in clear_cache, the types allow the use of `str` where
# a sequence of strings is required. This should be remedied if a solution
# to this typing bug is found: https://github.com/python/typing/issues/256
def reset_tzpath(to: Optional[Sequence[Union[os.PathLike, str]]] = ...) -> None: ...
def reset_tzpath(to: Optional[Sequence[Union[os.PathLike[AnyStr], str]]] = ...) -> None: ...
def available_timezones() -> Set[str]: ...

TZPATH: Sequence[str]
Expand Down
2 changes: 1 addition & 1 deletion stdlib/3/json/decoder.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JSONDecoder:
object_hook: Callable[[Dict[str, Any]], Any]
parse_float: Callable[[str], Any]
parse_int: Callable[[str], Any]
parse_constant = ... # Callable[[str], Any]
parse_constant: Callable[[str], Any] = ...
strict: bool
object_pairs_hook: Callable[[List[Tuple[str, Any]]], Any]

Expand Down
2 changes: 1 addition & 1 deletion stdlib/3/statistics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _Number = TypeVar("_Number", float, Decimal, Fraction)

# Used in median_high, median_low
class _Sortable(Protocol):
def __lt__(self, other) -> bool: ...
def __lt__(self, other: Any) -> bool: ...

_SortableT = TypeVar("_SortableT", bound=_Sortable)

Expand Down

0 comments on commit baaffed

Please sign in to comment.