From 4b4ced5fa0418f626033d88702833d3185bbf18f Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 25 Feb 2021 16:09:58 -0700 Subject: [PATCH] Added missing type annotations and type arguments (#5070) Co-authored-by: Eric Traut Co-authored-by: Shantanu --- pyrightconfig.json | 12 +-------- stdlib/asyncio/sslproto.pyi | 2 +- .../DateTimeRange/datetimerange/__init__.pyi | 16 ++++++------ stubs/MarkupSafe/markupsafe/__init__.pyi | 6 ++--- stubs/cachetools/cachetools/func.pyi | 8 +++--- stubs/click/click/_termui_impl.pyi | 7 +++-- stubs/click/click/core.pyi | 26 +++++++++---------- stubs/click/click/formatting.pyi | 4 +-- stubs/click/click/termui.pyi | 2 +- stubs/click/click/utils.pyi | 13 +++++++--- stubs/decorator/decorator.pyi | 2 +- stubs/frozendict/frozendict.pyi | 6 ++--- stubs/nmap/nmap/nmap.pyi | 4 ++- stubs/openssl-python/OpenSSL/crypto.pyi | 10 +++---- stubs/polib/polib.pyi | 4 +-- stubs/simplejson/simplejson/encoder.pyi | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 313549aac..1ffb8c0be 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -14,25 +14,15 @@ "stubs/backports", "stubs/backports_abc", "stubs/boto", - "stubs/cachetools", "stubs/chardet", - "stubs/click", "stubs/cryptography", "stubs/dateparser", - "stubs/DateTimeRange", - "stubs/decorator", "stubs/docutils", "stubs/fb303", "stubs/Flask", - "stubs/frozendict", "stubs/Jinja2", "stubs/kazoo", "stubs/Markdown", - "stubs/MarkupSafe", - "stubs/mock", - "stubs/nmap", - "stubs/openssl-python", - "stubs/polib", "stubs/paramiko", "stubs/protobuf", "stubs/pymssql", @@ -91,4 +81,4 @@ "reportOverlappingOverload": "none", "reportPropertyTypeMismatch": "none", "reportSelfClsParameterName": "none" -} +} \ No newline at end of file diff --git a/stdlib/asyncio/sslproto.pyi b/stdlib/asyncio/sslproto.pyi index 8d1c44aee..a267736ec 100644 --- a/stdlib/asyncio/sslproto.pyi +++ b/stdlib/asyncio/sslproto.pyi @@ -106,7 +106,7 @@ class SSLProtocol(protocols.Protocol): loop: events.AbstractEventLoop, app_protocol: protocols.BaseProtocol, sslcontext: ssl.SSLContext, - waiter: futures.Future, + waiter: futures.Future[Any], server_side: bool = ..., server_hostname: Optional[str] = ..., call_connection_made: bool = ..., diff --git a/stubs/DateTimeRange/datetimerange/__init__.pyi b/stubs/DateTimeRange/datetimerange/__init__.pyi index 4b9f1372d..53372f47a 100644 --- a/stubs/DateTimeRange/datetimerange/__init__.pyi +++ b/stubs/DateTimeRange/datetimerange/__init__.pyi @@ -16,13 +16,13 @@ class DateTimeRange(object): start_time_format: str = ..., end_time_format: str = ..., ) -> None: ... - def __eq__(self, other) -> bool: ... - def __ne__(self, other) -> bool: ... - def __add__(self, other) -> DateTimeRange: ... - def __iadd__(self, other) -> DateTimeRange: ... - def __sub__(self, other) -> DateTimeRange: ... - def __isub__(self, other) -> DateTimeRange: ... - def __contains__(self, x) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __add__(self, other: datetime.timedelta) -> DateTimeRange: ... + def __iadd__(self, other: datetime.timedelta) -> DateTimeRange: ... + def __sub__(self, other: datetime.timedelta) -> DateTimeRange: ... + def __isub__(self, other: datetime.timedelta) -> DateTimeRange: ... + def __contains__(self, x: Union[datetime.timedelta, DateTimeRange, str]) -> bool: ... @property def start_datetime(self) -> datetime.datetime: ... @property @@ -32,7 +32,7 @@ class DateTimeRange(object): def is_set(self) -> bool: ... def validate_time_inversion(self) -> None: ... def is_valid_timerange(self) -> bool: ... - def is_intersection(self, x) -> bool: ... + def is_intersection(self, x: DateTimeRange) -> bool: ... def get_start_time_str(self) -> str: ... def get_end_time_str(self) -> str: ... def get_timedelta_second(self) -> float: ... diff --git a/stubs/MarkupSafe/markupsafe/__init__.pyi b/stubs/MarkupSafe/markupsafe/__init__.pyi index f73d05dfc..9e54f9fe3 100644 --- a/stubs/MarkupSafe/markupsafe/__init__.pyi +++ b/stubs/MarkupSafe/markupsafe/__init__.pyi @@ -14,7 +14,7 @@ class Markup(text_type): def __mul__(self, num: int) -> Markup: ... def __rmul__(self, num: int) -> Markup: ... def __mod__(self, *args: Any) -> Markup: ... - def join(self, seq: Iterable[text_type]): ... + def join(self, seq: Iterable[text_type]) -> text_type: ... def split(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> List[text_type]: ... def rsplit(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> List[text_type]: ... def splitlines(self, keepends: bool = ...) -> List[text_type]: ... @@ -24,8 +24,8 @@ class Markup(text_type): def escape(cls, s: text_type) -> Markup: ... # noqa: F811 def partition(self, sep: text_type) -> Tuple[Markup, Markup, Markup]: ... def rpartition(self, sep: text_type) -> Tuple[Markup, Markup, Markup]: ... - def format(self, *args, **kwargs) -> Markup: ... - def __html_format__(self, format_spec) -> Markup: ... + def format(self, *args: Any, **kwargs: Any) -> Markup: ... + def __html_format__(self, format_spec: text_type) -> Markup: ... def __getslice__(self, start: int, stop: int) -> Markup: ... def __getitem__(self, i: Union[int, slice]) -> Markup: ... def capitalize(self) -> Markup: ... diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi index 04f72b94c..1fca79773 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -5,7 +5,7 @@ _T = TypeVar("_T") _F = TypeVar("_F", bound=Callable[..., Any]) _RET = Callable[[_F], _F] -def lfu_cache(maxsize: int = ..., typed: bool = ...) -> _RET: ... -def lru_cache(maxsize: int = ..., typed: bool = ...) -> _RET: ... -def rr_cache(maxsize: int = ..., choice: Optional[Callable[[Sequence[_T]], _T]] = ..., typed: bool = ...) -> _RET: ... -def ttl_cache(maxsize: int = ..., ttl: float = ..., timer: float = ..., typed: bool = ...) -> _RET: ... +def lfu_cache(maxsize: int = ..., typed: bool = ...) -> _RET[_F]: ... +def lru_cache(maxsize: int = ..., typed: bool = ...) -> _RET[_F]: ... +def rr_cache(maxsize: int = ..., choice: Optional[Callable[[Sequence[_T]], _T]] = ..., typed: bool = ...) -> _RET[_F]: ... +def ttl_cache(maxsize: int = ..., ttl: float = ..., timer: float = ..., typed: bool = ...) -> _RET[_F]: ... diff --git a/stubs/click/click/_termui_impl.pyi b/stubs/click/click/_termui_impl.pyi index 43e98ac34..4f8036cdb 100644 --- a/stubs/click/click/_termui_impl.pyi +++ b/stubs/click/click/_termui_impl.pyi @@ -1,4 +1,5 @@ -from typing import Generic, Optional, TypeVar +from types import TracebackType +from typing import Generic, Optional, Type, TypeVar _T = TypeVar("_T") @@ -6,7 +7,9 @@ class ProgressBar(Generic[_T]): def update(self, n_steps: int) -> None: ... def finish(self) -> None: ... def __enter__(self) -> ProgressBar[_T]: ... - def __exit__(self, exc_type, exc_value, tb) -> None: ... + def __exit__( + self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType] + ) -> None: ... def __iter__(self) -> ProgressBar[_T]: ... def next(self) -> _T: ... def __next__(self) -> _T: ... diff --git a/stubs/click/click/core.pyi b/stubs/click/click/core.pyi index ccc88d522..82fb48a4f 100644 --- a/stubs/click/click/core.pyi +++ b/stubs/click/click/core.pyi @@ -86,8 +86,8 @@ class Context: def exit(self, code: Union[int, str] = ...) -> NoReturn: ... def get_usage(self) -> str: ... def get_help(self) -> str: ... - def invoke(self, callback: Union[Command, Callable[..., Any]], *args, **kwargs) -> Any: ... - def forward(self, callback: Union[Command, Callable[..., Any]], *args, **kwargs) -> Any: ... + def invoke(self, callback: Union[Command, Callable[..., Any]], *args: Any, **kwargs: Any) -> Any: ... + def forward(self, callback: Union[Command, Callable[..., Any]], *args: Any, **kwargs: Any) -> Any: ... class BaseCommand: allow_extra_args: bool @@ -98,7 +98,7 @@ class BaseCommand: def __init__(self, name: str, context_settings: Optional[Dict[Any, Any]] = ...) -> None: ... def get_usage(self, ctx: Context) -> str: ... def get_help(self, ctx: Context) -> str: ... - def make_context(self, info_name: str, args: List[str], parent: Optional[Context] = ..., **extra) -> Context: ... + def make_context(self, info_name: str, args: List[str], parent: Optional[Context] = ..., **extra: Any) -> Context: ... def parse_args(self, ctx: Context, args: List[str]) -> List[str]: ... def invoke(self, ctx: Context) -> Any: ... def main( @@ -107,9 +107,9 @@ class BaseCommand: prog_name: Optional[str] = ..., complete_var: Optional[str] = ..., standalone_mode: bool = ..., - **extra, + **extra: Any, ) -> Any: ... - def __call__(self, *args, **kwargs) -> Any: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class Command(BaseCommand): callback: Optional[Callable[..., Any]] @@ -164,7 +164,7 @@ class MultiCommand(Command): subcommand_metavar: Optional[str] = ..., chain: bool = ..., result_callback: Optional[Callable[..., Any]] = ..., - **attrs, + **attrs: Any, ) -> None: ... def resultcallback(self, replace: bool = ...) -> Callable[[_F], _F]: ... def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None: ... @@ -174,14 +174,14 @@ class MultiCommand(Command): class Group(MultiCommand): commands: Dict[str, Command] - def __init__(self, name: Optional[str] = ..., commands: Optional[Dict[str, Command]] = ..., **attrs) -> None: ... - def add_command(self, cmd: Command, name: Optional[str] = ...): ... - def command(self, *args, **kwargs) -> Callable[[Callable[..., Any]], Command]: ... - def group(self, *args, **kwargs) -> Callable[[Callable[..., Any]], Group]: ... + def __init__(self, name: Optional[str] = ..., commands: Optional[Dict[str, Command]] = ..., **attrs: Any) -> None: ... + def add_command(self, cmd: Command, name: Optional[str] = ...) -> None: ... + def command(self, *args: Any, **kwargs: Any) -> Callable[[Callable[..., Any]], Command]: ... + def group(self, *args: Any, **kwargs: Any) -> Callable[[Callable[..., Any]], Group]: ... class CommandCollection(MultiCommand): sources: List[MultiCommand] - def __init__(self, name: Optional[str] = ..., sources: Optional[List[MultiCommand]] = ..., **attrs) -> None: ... + def __init__(self, name: Optional[str] = ..., sources: Optional[List[MultiCommand]] = ..., **attrs: Any) -> None: ... def add_source(self, multi_cmd: MultiCommand) -> None: ... class _ParamType: @@ -277,9 +277,9 @@ class Option(Parameter): hidden: bool = ..., show_choices: bool = ..., show_envvar: bool = ..., - **attrs, + **attrs: Any, ) -> None: ... def prompt_for_value(self, ctx: Context) -> Any: ... class Argument(Parameter): - def __init__(self, param_decls: Optional[List[str]] = ..., required: Optional[bool] = ..., **attrs) -> None: ... + def __init__(self, param_decls: Optional[List[str]] = ..., required: Optional[bool] = ..., **attrs: Any) -> None: ... diff --git a/stubs/click/click/formatting.pyi b/stubs/click/click/formatting.pyi index a1fbd23be..1c6b76238 100644 --- a/stubs/click/click/formatting.pyi +++ b/stubs/click/click/formatting.pyi @@ -22,12 +22,12 @@ class HelpFormatter: prog: str, args: str = ..., prefix: str = ..., - ): ... + ) -> None: ... def write_heading(self, heading: str) -> None: ... def write_paragraph(self) -> None: ... def write_text(self, text: str) -> None: ... def write_dl(self, rows: Iterable[Iterable[str]], col_max: int = ..., col_spacing: int = ...) -> None: ... - def section(self, name) -> ContextManager[None]: ... + def section(self, name: str) -> ContextManager[None]: ... def indentation(self) -> ContextManager[None]: ... def getvalue(self) -> str: ... diff --git a/stubs/click/click/termui.pyi b/stubs/click/click/termui.pyi index 3225f6788..bb584adbe 100644 --- a/stubs/click/click/termui.pyi +++ b/stubs/click/click/termui.pyi @@ -89,7 +89,7 @@ def secho( blink: Optional[bool] = ..., reverse: Optional[bool] = ..., reset: bool = ..., -): ... +) -> None: ... def edit( text: Optional[str] = ..., editor: Optional[str] = ..., diff --git a/stubs/click/click/utils.pyi b/stubs/click/click/utils.pyi index 7db0fbed3..c0ae9e254 100644 --- a/stubs/click/click/utils.pyi +++ b/stubs/click/click/utils.pyi @@ -1,11 +1,12 @@ -from typing import IO, Any, AnyStr, Generic, Iterator, List, Optional, Text, TypeVar +from types import TracebackType +from typing import IO, Any, AnyStr, Generic, Iterator, List, Optional, Text, Type, TypeVar _T = TypeVar("_T") def _posixify(name: str) -> str: ... def safecall(func: _T) -> _T: ... def make_str(value: Any) -> str: ... -def make_default_short_help(help: str, max_length: int = ...): ... +def make_default_short_help(help: str, max_length: int = ...) -> str: ... class LazyFile(object): name: str @@ -20,14 +21,18 @@ class LazyFile(object): def close(self) -> None: ... def close_intelligently(self) -> None: ... def __enter__(self) -> LazyFile: ... - def __exit__(self, exc_type, exc_value, tb): ... + def __exit__( + self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType] + ) -> None: ... def __iter__(self) -> Iterator[Any]: ... class KeepOpenFile(Generic[AnyStr]): _file: IO[AnyStr] def __init__(self, file: IO[AnyStr]) -> None: ... def __enter__(self) -> KeepOpenFile[AnyStr]: ... - def __exit__(self, exc_type, exc_value, tb): ... + def __exit__( + self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType] + ) -> None: ... def __iter__(self) -> Iterator[AnyStr]: ... def echo( diff --git a/stubs/decorator/decorator.pyi b/stubs/decorator/decorator.pyi index 0d6238e75..28f52a735 100644 --- a/stubs/decorator/decorator.pyi +++ b/stubs/decorator/decorator.pyi @@ -5,7 +5,7 @@ _C = TypeVar("_C", bound=Callable[..., Any]) _Func = TypeVar("_Func", bound=Callable[..., Any]) _T = TypeVar("_T") -def get_init(cls): ... +def get_init(cls: type) -> None: ... if sys.version_info >= (3,): from inspect import getfullargspec as getfullargspec, iscoroutinefunction as iscoroutinefunction diff --git a/stubs/frozendict/frozendict.pyi b/stubs/frozendict/frozendict.pyi index 704a44c13..d8c349de2 100644 --- a/stubs/frozendict/frozendict.pyi +++ b/stubs/frozendict/frozendict.pyi @@ -7,7 +7,7 @@ _VT = TypeVar("_VT") class frozendict(Mapping[_KT, _VT], Generic[_KT, _VT]): - dict_cls: Type[Dict] = ... + dict_cls: Type[Dict[Any, Any]] = ... @overload def __init__(self, **kwargs: _VT) -> None: ... @overload @@ -22,6 +22,6 @@ class frozendict(Mapping[_KT, _VT], Generic[_KT, _VT]): def __repr__(self) -> str: ... def __hash__(self) -> int: ... -class FrozenOrderedDict(frozendict): +class FrozenOrderedDict(frozendict[_KT, _VT]): - dict_cls: Type[collections.OrderedDict] = ... + dict_cls: Type[collections.OrderedDict[Any, Any]] = ... diff --git a/stubs/nmap/nmap/nmap.pyi b/stubs/nmap/nmap/nmap.pyi index bcf8ed96e..5e4be5adc 100644 --- a/stubs/nmap/nmap/nmap.pyi +++ b/stubs/nmap/nmap/nmap.pyi @@ -70,7 +70,9 @@ class PortScanner(object): def has_host(self, host: str) -> bool: ... def csv(self) -> str: ... -def __scan_progressive__(self, hosts: Text, ports: Text, arguments: Text, callback: Optional[_Callback], sudo: bool) -> None: ... +def __scan_progressive__( + self: object, hosts: Text, ports: Text, arguments: Text, callback: Optional[_Callback], sudo: bool +) -> None: ... class PortScannerAsync(object): def __init__(self) -> None: ... diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index e38a26f9c..5e9e3e69d 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -18,7 +18,7 @@ class PKey: def __init__(self) -> None: ... def to_cryptography_key(self) -> _Key: ... @classmethod - def from_cryptography_key(cls, crypto_key: _Key): ... + def from_cryptography_key(cls, crypto_key: _Key) -> PKey: ... def generate_key(self, type: int, bits: int) -> None: ... def check(self) -> bool: ... def type(self) -> int: ... @@ -175,7 +175,7 @@ class PKCS12: def set_ca_certificates(self, cacerts: Iterable[X509]) -> None: ... def set_friendlyname(self, name: bytes) -> None: ... def get_friendlyname(self) -> bytes: ... - def export(self, passphrase: Optional[str] = ..., iter: int = ..., maciter: int = ...): ... + def export(self, passphrase: Optional[str] = ..., iter: int = ..., maciter: int = ...) -> bytes: ... class NetscapeSPKI: def __init__(self) -> None: ... @@ -186,9 +186,9 @@ class NetscapeSPKI: def set_pubkey(self, pkey: PKey) -> None: ... def load_publickey(type: int, buffer: _StrLike) -> PKey: ... -def load_privatekey(type: int, buffer: bytes, passphrase: Optional[Union[str, Callable[[int], int]]] = ...): ... -def dump_certificate_request(type: int, req: X509Req): ... -def load_certificate_request(type, buffer: _StrLike) -> X509Req: ... +def load_privatekey(type: int, buffer: bytes, passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> PKey: ... +def dump_certificate_request(type: int, req: X509Req) -> bytes: ... +def load_certificate_request(type: int, buffer: _StrLike) -> X509Req: ... def sign(pkey: PKey, data: _StrLike, digest: str) -> bytes: ... def verify(cert: X509, signature: bytes, data: _StrLike, digest: str) -> None: ... def dump_crl(type: int, crl: CRL) -> bytes: ... diff --git a/stubs/polib/polib.pyi b/stubs/polib/polib.pyi index 4f5d0c992..85f43669d 100644 --- a/stubs/polib/polib.pyi +++ b/stubs/polib/polib.pyi @@ -42,7 +42,7 @@ class _BaseFile(List[_TB]): def ordered_metadata(self) -> List[Text]: ... def to_binary(self) -> bytes: ... -class POFile(_BaseFile): +class POFile(_BaseFile[POEntry]): def __unicode__(self) -> Text: ... def save_as_mofile(self, fpath: Text) -> None: ... def percent_translated(self) -> int: ... @@ -52,7 +52,7 @@ class POFile(_BaseFile): def obsolete_entries(self) -> List[POEntry]: ... def merge(self, refpot: POFile) -> None: ... -class MOFile(_BaseFile): +class MOFile(_BaseFile[MOEntry]): MAGIC: int MAGIC_SWAPPED: int magic_number: Optional[int] diff --git a/stubs/simplejson/simplejson/encoder.pyi b/stubs/simplejson/simplejson/encoder.pyi index ab6f40f1b..9a3c5e4d9 100644 --- a/stubs/simplejson/simplejson/encoder.pyi +++ b/stubs/simplejson/simplejson/encoder.pyi @@ -1,7 +1,7 @@ from typing import Any class JSONEncoder(object): - def __init__(self, *args, **kwargs): ... + def __init__(self, *args: Any, **kwargs: Any) -> None: ... def encode(self, o: Any): ... def default(self, o: Any): ... def iterencode(self, o: Any, _one_shot: bool): ...