From 2465b8a67d611f6e0a27c5e445700500bc89a427 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Wed, 3 Mar 2021 23:55:57 +0300 Subject: [PATCH] Enable pyi stubs for several modules (PY-41509, PY-46229) _ast, _dummy_thread, datetimerange, dummy_thread, dummy_threading, formatter, jwt, platform, string, thread GitOrigin-RevId: a8010a0bd2381712599be0f96b35ce74e3e0c7d2 --- .../helpers/typeshed/stdlib/@python2/_ast.pyi | 303 ++++++++++++++ .../typeshed/stdlib/@python2/dummy_thread.pyi | 21 + .../typeshed/stdlib/@python2/platform.pyi | 45 +++ .../typeshed/stdlib/@python2/string.pyi | 68 ++++ .../typeshed/stdlib/@python2/thread.pyi | 27 ++ python/helpers/typeshed/stdlib/_ast.pyi | 376 ++++++++++++++++++ .../helpers/typeshed/stdlib/_dummy_thread.pyi | 21 + .../typeshed/stdlib/dummy_threading.pyi | 2 + python/helpers/typeshed/stdlib/formatter.pyi | 103 +++++ python/helpers/typeshed/stdlib/platform.pyi | 66 +++ python/helpers/typeshed/stdlib/string.pyi | 30 ++ .../stubs/DateTimeRange/METADATA.toml | 3 + .../DateTimeRange/datetimerange/__init__.pyi | 47 +++ .../helpers/typeshed/stubs/jwt/METADATA.toml | 2 + .../typeshed/stubs/jwt/jwt/__init__.pyi | 49 +++ .../typeshed/stubs/jwt/jwt/algorithms.pyi | 93 +++++ .../stubs/jwt/jwt/contrib/__init__.pyi | 0 .../jwt/jwt/contrib/algorithms/__init__.pyi | 0 .../jwt/jwt/contrib/algorithms/py_ecdsa.pyi | 10 + .../jwt/jwt/contrib/algorithms/pycrypto.pyi | 10 + python/testData/completion/import.after.py | 2 +- python/testData/completion/import.py | 2 +- .../osPathFunctions/main.py | 2 +- .../osPathFunctions/main_after.py | 4 +- .../quickFixes/PyAddImportQuickFixTest.java | 6 +- .../jetbrains/python/tools/PyTypeShedSync.kts | 10 - 26 files changed, 1284 insertions(+), 18 deletions(-) create mode 100644 python/helpers/typeshed/stdlib/@python2/_ast.pyi create mode 100644 python/helpers/typeshed/stdlib/@python2/dummy_thread.pyi create mode 100644 python/helpers/typeshed/stdlib/@python2/platform.pyi create mode 100644 python/helpers/typeshed/stdlib/@python2/string.pyi create mode 100644 python/helpers/typeshed/stdlib/@python2/thread.pyi create mode 100644 python/helpers/typeshed/stdlib/_ast.pyi create mode 100644 python/helpers/typeshed/stdlib/_dummy_thread.pyi create mode 100644 python/helpers/typeshed/stdlib/dummy_threading.pyi create mode 100644 python/helpers/typeshed/stdlib/formatter.pyi create mode 100644 python/helpers/typeshed/stdlib/platform.pyi create mode 100644 python/helpers/typeshed/stdlib/string.pyi create mode 100644 python/helpers/typeshed/stubs/DateTimeRange/METADATA.toml create mode 100644 python/helpers/typeshed/stubs/DateTimeRange/datetimerange/__init__.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/METADATA.toml create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/__init__.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/algorithms.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/contrib/__init__.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/__init__.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/py_ecdsa.pyi create mode 100644 python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/pycrypto.pyi diff --git a/python/helpers/typeshed/stdlib/@python2/_ast.pyi b/python/helpers/typeshed/stdlib/@python2/_ast.pyi new file mode 100644 index 000000000000..4ca7def60b04 --- /dev/null +++ b/python/helpers/typeshed/stdlib/@python2/_ast.pyi @@ -0,0 +1,303 @@ +import typing +from typing import Optional + +__version__: str +PyCF_ONLY_AST: int +_identifier = str + +class AST: + _attributes: typing.Tuple[str, ...] + _fields: typing.Tuple[str, ...] + def __init__(self, *args, **kwargs) -> None: ... + +class mod(AST): ... + +class Module(mod): + body: typing.List[stmt] + +class Interactive(mod): + body: typing.List[stmt] + +class Expression(mod): + body: expr + +class Suite(mod): + body: typing.List[stmt] + +class stmt(AST): + lineno: int + col_offset: int + +class FunctionDef(stmt): + name: _identifier + args: arguments + body: typing.List[stmt] + decorator_list: typing.List[expr] + +class ClassDef(stmt): + name: _identifier + bases: typing.List[expr] + body: typing.List[stmt] + decorator_list: typing.List[expr] + +class Return(stmt): + value: Optional[expr] + +class Delete(stmt): + targets: typing.List[expr] + +class Assign(stmt): + targets: typing.List[expr] + value: expr + +class AugAssign(stmt): + target: expr + op: operator + value: expr + +class Print(stmt): + dest: Optional[expr] + values: typing.List[expr] + nl: bool + +class For(stmt): + target: expr + iter: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class While(stmt): + test: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class If(stmt): + test: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class With(stmt): + context_expr: expr + optional_vars: Optional[expr] + body: typing.List[stmt] + +class Raise(stmt): + type: Optional[expr] + inst: Optional[expr] + tback: Optional[expr] + +class TryExcept(stmt): + body: typing.List[stmt] + handlers: typing.List[ExceptHandler] + orelse: typing.List[stmt] + +class TryFinally(stmt): + body: typing.List[stmt] + finalbody: typing.List[stmt] + +class Assert(stmt): + test: expr + msg: Optional[expr] + +class Import(stmt): + names: typing.List[alias] + +class ImportFrom(stmt): + module: Optional[_identifier] + names: typing.List[alias] + level: Optional[int] + +class Exec(stmt): + body: expr + globals: Optional[expr] + locals: Optional[expr] + +class Global(stmt): + names: typing.List[_identifier] + +class Expr(stmt): + value: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... +class slice(AST): ... + +_slice = slice # this lets us type the variable named 'slice' below + +class Slice(slice): + lower: Optional[expr] + upper: Optional[expr] + step: Optional[expr] + +class ExtSlice(slice): + dims: typing.List[slice] + +class Index(slice): + value: expr + +class Ellipsis(slice): ... + +class expr(AST): + lineno: int + col_offset: int + +class BoolOp(expr): + op: boolop + values: typing.List[expr] + +class BinOp(expr): + left: expr + op: operator + right: expr + +class UnaryOp(expr): + op: unaryop + operand: expr + +class Lambda(expr): + args: arguments + body: expr + +class IfExp(expr): + test: expr + body: expr + orelse: expr + +class Dict(expr): + keys: typing.List[expr] + values: typing.List[expr] + +class Set(expr): + elts: typing.List[expr] + +class ListComp(expr): + elt: expr + generators: typing.List[comprehension] + +class SetComp(expr): + elt: expr + generators: typing.List[comprehension] + +class DictComp(expr): + key: expr + value: expr + generators: typing.List[comprehension] + +class GeneratorExp(expr): + elt: expr + generators: typing.List[comprehension] + +class Yield(expr): + value: Optional[expr] + +class Compare(expr): + left: expr + ops: typing.List[cmpop] + comparators: typing.List[expr] + +class Call(expr): + func: expr + args: typing.List[expr] + keywords: typing.List[keyword] + starargs: Optional[expr] + kwargs: Optional[expr] + +class Repr(expr): + value: expr + +class Num(expr): + n: float + +class Str(expr): + s: str + +class Attribute(expr): + value: expr + attr: _identifier + ctx: expr_context + +class Subscript(expr): + value: expr + slice: _slice + ctx: expr_context + +class Name(expr): + id: _identifier + ctx: expr_context + +class List(expr): + elts: typing.List[expr] + ctx: expr_context + +class Tuple(expr): + elts: typing.List[expr] + ctx: expr_context + +class expr_context(AST): ... +class AugLoad(expr_context): ... +class AugStore(expr_context): ... +class Del(expr_context): ... +class Load(expr_context): ... +class Param(expr_context): ... +class Store(expr_context): ... +class boolop(AST): ... +class And(boolop): ... +class Or(boolop): ... +class operator(AST): ... +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... +class unaryop(AST): ... +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... +class cmpop(AST): ... +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + +class comprehension(AST): + target: expr + iter: expr + ifs: typing.List[expr] + +class excepthandler(AST): ... + +class ExceptHandler(excepthandler): + type: Optional[expr] + name: Optional[expr] + body: typing.List[stmt] + lineno: int + col_offset: int + +class arguments(AST): + args: typing.List[expr] + vararg: Optional[_identifier] + kwarg: Optional[_identifier] + defaults: typing.List[expr] + +class keyword(AST): + arg: _identifier + value: expr + +class alias(AST): + name: _identifier + asname: Optional[_identifier] diff --git a/python/helpers/typeshed/stdlib/@python2/dummy_thread.pyi b/python/helpers/typeshed/stdlib/@python2/dummy_thread.pyi new file mode 100644 index 000000000000..28041002a708 --- /dev/null +++ b/python/helpers/typeshed/stdlib/@python2/dummy_thread.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, NoReturn, Optional, Tuple + +class error(Exception): + def __init__(self, *args: Any) -> None: ... + +def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: Dict[str, Any] = ...) -> None: ... +def exit() -> NoReturn: ... +def get_ident() -> int: ... +def allocate_lock() -> LockType: ... +def stack_size(size: Optional[int] = ...) -> int: ... + +class LockType(object): + locked_status: bool + def __init__(self) -> None: ... + def acquire(self, waitflag: Optional[bool] = ...) -> bool: ... + def __enter__(self, waitflag: Optional[bool] = ...) -> bool: ... + def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ... + def release(self) -> bool: ... + def locked(self) -> bool: ... + +def interrupt_main() -> None: ... diff --git a/python/helpers/typeshed/stdlib/@python2/platform.pyi b/python/helpers/typeshed/stdlib/@python2/platform.pyi new file mode 100644 index 000000000000..44bbe4d62aa9 --- /dev/null +++ b/python/helpers/typeshed/stdlib/@python2/platform.pyi @@ -0,0 +1,45 @@ +from typing import Any, Optional, Tuple + +__copyright__: Any +DEV_NULL: Any + +def libc_ver(executable=..., lib=..., version=..., chunksize: int = ...): ... +def linux_distribution(distname=..., version=..., id=..., supported_dists=..., full_distribution_name: int = ...): ... +def dist(distname=..., version=..., id=..., supported_dists=...): ... + +class _popen: + tmpfile: Any + pipe: Any + bufsize: Any + mode: Any + def __init__(self, cmd, mode=..., bufsize: Optional[Any] = ...): ... + def read(self): ... + def readlines(self): ... + def close(self, remove=..., error=...): ... + __del__: Any + +def popen(cmd, mode=..., bufsize: Optional[Any] = ...): ... +def win32_ver(release: str = ..., version: str = ..., csd: str = ..., ptype: str = ...) -> Tuple[str, str, str, str]: ... +def mac_ver( + release: str = ..., versioninfo: Tuple[str, str, str] = ..., machine: str = ... +) -> Tuple[str, Tuple[str, str, str], str]: ... +def java_ver( + release: str = ..., vendor: str = ..., vminfo: Tuple[str, str, str] = ..., osinfo: Tuple[str, str, str] = ... +) -> Tuple[str, str, Tuple[str, str, str], Tuple[str, str, str]]: ... +def system_alias(system, release, version): ... +def architecture(executable=..., bits=..., linkage=...) -> Tuple[str, str]: ... +def uname() -> Tuple[str, str, str, str, str, str]: ... +def system() -> str: ... +def node() -> str: ... +def release() -> str: ... +def version() -> str: ... +def machine() -> str: ... +def processor() -> str: ... +def python_implementation() -> str: ... +def python_version() -> str: ... +def python_version_tuple() -> Tuple[str, str, str]: ... +def python_branch() -> str: ... +def python_revision() -> str: ... +def python_build() -> Tuple[str, str]: ... +def python_compiler() -> str: ... +def platform(aliased: int = ..., terse: int = ...) -> str: ... diff --git a/python/helpers/typeshed/stdlib/@python2/string.pyi b/python/helpers/typeshed/stdlib/@python2/string.pyi new file mode 100644 index 000000000000..03a6a2dfd800 --- /dev/null +++ b/python/helpers/typeshed/stdlib/@python2/string.pyi @@ -0,0 +1,68 @@ +from typing import Any, AnyStr, Iterable, List, Mapping, Optional, Sequence, Text, Tuple, Union, overload + +ascii_letters: str +ascii_lowercase: str +ascii_uppercase: str +digits: str +hexdigits: str +letters: str +lowercase: str +octdigits: str +punctuation: str +printable: str +uppercase: str +whitespace: str + +def capwords(s: AnyStr, sep: AnyStr = ...) -> AnyStr: ... + +# TODO: originally named 'from' +def maketrans(_from: str, to: str) -> str: ... +def atof(s: unicode) -> float: ... +def atoi(s: unicode, base: int = ...) -> int: ... +def atol(s: unicode, base: int = ...) -> int: ... +def capitalize(word: AnyStr) -> AnyStr: ... +def find(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rfind(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def index(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rindex(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def count(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def lower(s: AnyStr) -> AnyStr: ... +def split(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def rsplit(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def splitfields(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def join(words: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def joinfields(word: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def lstrip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def rstrip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def strip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def swapcase(s: AnyStr) -> AnyStr: ... +def translate(s: str, table: str, deletechars: str = ...) -> str: ... +def upper(s: AnyStr) -> AnyStr: ... +def ljust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def rjust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def center(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def zfill(s: AnyStr, width: int) -> AnyStr: ... +def replace(s: AnyStr, old: AnyStr, new: AnyStr, maxreplace: int = ...) -> AnyStr: ... + +class Template: + template: Text + def __init__(self, template: Text) -> None: ... + @overload + def substitute(self, mapping: Union[Mapping[str, str], Mapping[unicode, str]] = ..., **kwds: str) -> str: ... + @overload + def substitute(self, mapping: Union[Mapping[str, Text], Mapping[unicode, Text]] = ..., **kwds: Text) -> Text: ... + @overload + def safe_substitute(self, mapping: Union[Mapping[str, str], Mapping[unicode, str]] = ..., **kwds: str) -> str: ... + @overload + def safe_substitute(self, mapping: Union[Mapping[str, Text], Mapping[unicode, Text]], **kwds: Text) -> Text: ... + +# TODO(MichalPokorny): This is probably badly and/or loosely typed. +class Formatter(object): + def format(self, format_string: str, *args, **kwargs) -> str: ... + def vformat(self, format_string: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> str: ... + def parse(self, format_string: str) -> Iterable[Tuple[str, str, str, str]]: ... + def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... + def get_value(self, key: Union[int, str], args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... + def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], kwargs: Mapping[str, Any]) -> None: ... + def format_field(self, value: Any, format_spec: str) -> Any: ... + def convert_field(self, value: Any, conversion: str) -> Any: ... diff --git a/python/helpers/typeshed/stdlib/@python2/thread.pyi b/python/helpers/typeshed/stdlib/@python2/thread.pyi new file mode 100644 index 000000000000..b3ba062a498e --- /dev/null +++ b/python/helpers/typeshed/stdlib/@python2/thread.pyi @@ -0,0 +1,27 @@ +from typing import Any, Callable + +def _count() -> int: ... + +class error(Exception): ... + +class LockType: + def acquire(self, waitflag: int = ...) -> bool: ... + def acquire_lock(self, waitflag: int = ...) -> bool: ... + def release(self) -> None: ... + def release_lock(self) -> None: ... + def locked(self) -> bool: ... + def locked_lock(self) -> bool: ... + def __enter__(self) -> LockType: ... + def __exit__(self, typ: Any, value: Any, traceback: Any) -> None: ... + +class _local(object): ... +class _localdummy(object): ... + +def start_new(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... +def start_new_thread(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... +def interrupt_main() -> None: ... +def exit() -> None: ... +def exit_thread() -> Any: ... +def allocate_lock() -> LockType: ... +def get_ident() -> int: ... +def stack_size(size: int = ...) -> int: ... diff --git a/python/helpers/typeshed/stdlib/_ast.pyi b/python/helpers/typeshed/stdlib/_ast.pyi new file mode 100644 index 000000000000..1555652902ed --- /dev/null +++ b/python/helpers/typeshed/stdlib/_ast.pyi @@ -0,0 +1,376 @@ +import sys +import typing +from typing import Any, ClassVar, Optional + +PyCF_ONLY_AST: int +if sys.version_info >= (3, 8): + PyCF_TYPE_COMMENTS: int + PyCF_ALLOW_TOP_LEVEL_AWAIT: int + +_identifier = str + +class AST: + _attributes: ClassVar[typing.Tuple[str, ...]] + _fields: ClassVar[typing.Tuple[str, ...]] + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + # TODO: Not all nodes have all of the following attributes + lineno: int + col_offset: int + if sys.version_info >= (3, 8): + end_lineno: Optional[int] + end_col_offset: Optional[int] + type_comment: Optional[str] + +class mod(AST): ... + +if sys.version_info >= (3, 8): + class type_ignore(AST): ... + class TypeIgnore(type_ignore): ... + class FunctionType(mod): + argtypes: typing.List[expr] + returns: expr + +class Module(mod): + body: typing.List[stmt] + if sys.version_info >= (3, 8): + type_ignores: typing.List[TypeIgnore] + +class Interactive(mod): + body: typing.List[stmt] + +class Expression(mod): + body: expr + +class stmt(AST): ... + +class FunctionDef(stmt): + name: _identifier + args: arguments + body: typing.List[stmt] + decorator_list: typing.List[expr] + returns: Optional[expr] + +class AsyncFunctionDef(stmt): + name: _identifier + args: arguments + body: typing.List[stmt] + decorator_list: typing.List[expr] + returns: Optional[expr] + +class ClassDef(stmt): + name: _identifier + bases: typing.List[expr] + keywords: typing.List[keyword] + body: typing.List[stmt] + decorator_list: typing.List[expr] + +class Return(stmt): + value: Optional[expr] + +class Delete(stmt): + targets: typing.List[expr] + +class Assign(stmt): + targets: typing.List[expr] + value: expr + +class AugAssign(stmt): + target: expr + op: operator + value: expr + +class AnnAssign(stmt): + target: expr + annotation: expr + value: Optional[expr] + simple: int + +class For(stmt): + target: expr + iter: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class AsyncFor(stmt): + target: expr + iter: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class While(stmt): + test: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class If(stmt): + test: expr + body: typing.List[stmt] + orelse: typing.List[stmt] + +class With(stmt): + items: typing.List[withitem] + body: typing.List[stmt] + +class AsyncWith(stmt): + items: typing.List[withitem] + body: typing.List[stmt] + +class Raise(stmt): + exc: Optional[expr] + cause: Optional[expr] + +class Try(stmt): + body: typing.List[stmt] + handlers: typing.List[ExceptHandler] + orelse: typing.List[stmt] + finalbody: typing.List[stmt] + +class Assert(stmt): + test: expr + msg: Optional[expr] + +class Import(stmt): + names: typing.List[alias] + +class ImportFrom(stmt): + module: Optional[_identifier] + names: typing.List[alias] + level: int + +class Global(stmt): + names: typing.List[_identifier] + +class Nonlocal(stmt): + names: typing.List[_identifier] + +class Expr(stmt): + value: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... +class expr(AST): ... + +class BoolOp(expr): + op: boolop + values: typing.List[expr] + +class BinOp(expr): + left: expr + op: operator + right: expr + +class UnaryOp(expr): + op: unaryop + operand: expr + +class Lambda(expr): + args: arguments + body: expr + +class IfExp(expr): + test: expr + body: expr + orelse: expr + +class Dict(expr): + keys: typing.List[Optional[expr]] + values: typing.List[expr] + +class Set(expr): + elts: typing.List[expr] + +class ListComp(expr): + elt: expr + generators: typing.List[comprehension] + +class SetComp(expr): + elt: expr + generators: typing.List[comprehension] + +class DictComp(expr): + key: expr + value: expr + generators: typing.List[comprehension] + +class GeneratorExp(expr): + elt: expr + generators: typing.List[comprehension] + +class Await(expr): + value: expr + +class Yield(expr): + value: Optional[expr] + +class YieldFrom(expr): + value: expr + +class Compare(expr): + left: expr + ops: typing.List[cmpop] + comparators: typing.List[expr] + +class Call(expr): + func: expr + args: typing.List[expr] + keywords: typing.List[keyword] + +class FormattedValue(expr): + value: expr + conversion: Optional[int] + format_spec: Optional[expr] + +class JoinedStr(expr): + values: typing.List[expr] + +if sys.version_info < (3, 8): + class Num(expr): # Deprecated in 3.8; use Constant + n: complex + class Str(expr): # Deprecated in 3.8; use Constant + s: str + class Bytes(expr): # Deprecated in 3.8; use Constant + s: bytes + class NameConstant(expr): # Deprecated in 3.8; use Constant + value: Any + class Ellipsis(expr): ... # Deprecated in 3.8; use Constant + +class Constant(expr): + value: Any # None, str, bytes, bool, int, float, complex, Ellipsis + kind: Optional[str] + # Aliases for value, for backwards compatibility + s: Any + n: complex + +if sys.version_info >= (3, 8): + class NamedExpr(expr): + target: expr + value: expr + +class Attribute(expr): + value: expr + attr: _identifier + ctx: expr_context + +if sys.version_info >= (3, 9): + _SliceT = expr +else: + class slice(AST): ... + _SliceT = slice + +class Slice(_SliceT): + lower: Optional[expr] + upper: Optional[expr] + step: Optional[expr] + +if sys.version_info < (3, 9): + class ExtSlice(slice): + dims: typing.List[slice] + class Index(slice): + value: expr + +class Subscript(expr): + value: expr + slice: _SliceT + ctx: expr_context + +class Starred(expr): + value: expr + ctx: expr_context + +class Name(expr): + id: _identifier + ctx: expr_context + +class List(expr): + elts: typing.List[expr] + ctx: expr_context + +class Tuple(expr): + elts: typing.List[expr] + ctx: expr_context + +class expr_context(AST): ... + +if sys.version_info < (3, 9): + class AugLoad(expr_context): ... + class AugStore(expr_context): ... + class Param(expr_context): ... + class Suite(mod): + body: typing.List[stmt] + +class Del(expr_context): ... +class Load(expr_context): ... +class Store(expr_context): ... +class boolop(AST): ... +class And(boolop): ... +class Or(boolop): ... +class operator(AST): ... +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class MatMult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... +class unaryop(AST): ... +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... +class cmpop(AST): ... +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + +class comprehension(AST): + target: expr + iter: expr + ifs: typing.List[expr] + is_async: int + +class excepthandler(AST): ... + +class ExceptHandler(excepthandler): + type: Optional[expr] + name: Optional[_identifier] + body: typing.List[stmt] + +class arguments(AST): + if sys.version_info >= (3, 8): + posonlyargs: typing.List[arg] + args: typing.List[arg] + vararg: Optional[arg] + kwonlyargs: typing.List[arg] + kw_defaults: typing.List[Optional[expr]] + kwarg: Optional[arg] + defaults: typing.List[expr] + +class arg(AST): + arg: _identifier + annotation: Optional[expr] + +class keyword(AST): + arg: Optional[_identifier] + value: expr + +class alias(AST): + name: _identifier + asname: Optional[_identifier] + +class withitem(AST): + context_expr: expr + optional_vars: Optional[expr] diff --git a/python/helpers/typeshed/stdlib/_dummy_thread.pyi b/python/helpers/typeshed/stdlib/_dummy_thread.pyi new file mode 100644 index 000000000000..1260d42de958 --- /dev/null +++ b/python/helpers/typeshed/stdlib/_dummy_thread.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, NoReturn, Optional, Tuple + +TIMEOUT_MAX: int +error = RuntimeError + +def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: Dict[str, Any] = ...) -> None: ... +def exit() -> NoReturn: ... +def get_ident() -> int: ... +def allocate_lock() -> LockType: ... +def stack_size(size: Optional[int] = ...) -> int: ... + +class LockType(object): + locked_status: bool + def __init__(self) -> None: ... + def acquire(self, waitflag: Optional[bool] = ..., timeout: int = ...) -> bool: ... + def __enter__(self, waitflag: Optional[bool] = ..., timeout: int = ...) -> bool: ... + def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ... + def release(self) -> bool: ... + def locked(self) -> bool: ... + +def interrupt_main() -> None: ... diff --git a/python/helpers/typeshed/stdlib/dummy_threading.pyi b/python/helpers/typeshed/stdlib/dummy_threading.pyi new file mode 100644 index 000000000000..757cb8d4bd4c --- /dev/null +++ b/python/helpers/typeshed/stdlib/dummy_threading.pyi @@ -0,0 +1,2 @@ +from _dummy_threading import * +from _dummy_threading import __all__ as __all__ diff --git a/python/helpers/typeshed/stdlib/formatter.pyi b/python/helpers/typeshed/stdlib/formatter.pyi new file mode 100644 index 000000000000..31c45592a215 --- /dev/null +++ b/python/helpers/typeshed/stdlib/formatter.pyi @@ -0,0 +1,103 @@ +from typing import IO, Any, Iterable, List, Optional, Tuple + +AS_IS: None +_FontType = Tuple[str, bool, bool, bool] +_StylesType = Tuple[Any, ...] + +class NullFormatter: + writer: Optional[NullWriter] + def __init__(self, writer: Optional[NullWriter] = ...) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, x: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class AbstractFormatter: + writer: NullWriter + align: Optional[str] + align_stack: List[Optional[str]] + font_stack: List[_FontType] + margin_stack: List[int] + spacing: Optional[str] + style_stack: Any + nospace: int + softspace: int + para_end: int + parskip: int + hard_break: int + have_label: int + def __init__(self, writer: NullWriter) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... + def format_counter(self, format: Iterable[str], counter: int) -> str: ... + def format_letter(self, case: str, counter: int) -> str: ... + def format_roman(self, case: str, counter: int) -> str: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, font: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class NullWriter: + def __init__(self) -> None: ... + def flush(self) -> None: ... + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles: Tuple[Any, ...]) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class AbstractWriter(NullWriter): + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles: Tuple[Any, ...]) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class DumbWriter(NullWriter): + file: IO[str] + maxcol: int + def __init__(self, file: Optional[IO[str]] = ..., maxcol: int = ...) -> None: ... + def reset(self) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_literal_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + +def test(file: Optional[str] = ...) -> None: ... diff --git a/python/helpers/typeshed/stdlib/platform.pyi b/python/helpers/typeshed/stdlib/platform.pyi new file mode 100644 index 000000000000..73579dff3887 --- /dev/null +++ b/python/helpers/typeshed/stdlib/platform.pyi @@ -0,0 +1,66 @@ +import sys + +if sys.version_info < (3, 9): + import os + + DEV_NULL = os.devnull +from typing import NamedTuple, Optional, Tuple + +if sys.version_info >= (3, 8): + def libc_ver( + executable: Optional[str] = ..., lib: str = ..., version: str = ..., chunksize: int = ... + ) -> Tuple[str, str]: ... + +else: + def libc_ver(executable: str = ..., lib: str = ..., version: str = ..., chunksize: int = ...) -> Tuple[str, str]: ... + +if sys.version_info < (3, 8): + def linux_distribution( + distname: str = ..., + version: str = ..., + id: str = ..., + supported_dists: Tuple[str, ...] = ..., + full_distribution_name: bool = ..., + ) -> Tuple[str, str, str]: ... + def dist( + distname: str = ..., version: str = ..., id: str = ..., supported_dists: Tuple[str, ...] = ... + ) -> Tuple[str, str, str]: ... + +def win32_ver(release: str = ..., version: str = ..., csd: str = ..., ptype: str = ...) -> Tuple[str, str, str, str]: ... + +if sys.version_info >= (3, 8): + def win32_edition() -> str: ... + def win32_is_iot() -> bool: ... + +def mac_ver( + release: str = ..., versioninfo: Tuple[str, str, str] = ..., machine: str = ... +) -> Tuple[str, Tuple[str, str, str], str]: ... +def java_ver( + release: str = ..., vendor: str = ..., vminfo: Tuple[str, str, str] = ..., osinfo: Tuple[str, str, str] = ... +) -> Tuple[str, str, Tuple[str, str, str], Tuple[str, str, str]]: ... +def system_alias(system: str, release: str, version: str) -> Tuple[str, str, str]: ... +def architecture(executable: str = ..., bits: str = ..., linkage: str = ...) -> Tuple[str, str]: ... + +class uname_result(NamedTuple): + system: str + node: str + release: str + version: str + machine: str + processor: str + +def uname() -> uname_result: ... +def system() -> str: ... +def node() -> str: ... +def release() -> str: ... +def version() -> str: ... +def machine() -> str: ... +def processor() -> str: ... +def python_implementation() -> str: ... +def python_version() -> str: ... +def python_version_tuple() -> Tuple[str, str, str]: ... +def python_branch() -> str: ... +def python_revision() -> str: ... +def python_build() -> Tuple[str, str]: ... +def python_compiler() -> str: ... +def platform(aliased: bool = ..., terse: bool = ...) -> str: ... diff --git a/python/helpers/typeshed/stdlib/string.pyi b/python/helpers/typeshed/stdlib/string.pyi new file mode 100644 index 000000000000..a39e64dd32ca --- /dev/null +++ b/python/helpers/typeshed/stdlib/string.pyi @@ -0,0 +1,30 @@ +from typing import Any, Iterable, Mapping, Optional, Sequence, Tuple, Union + +ascii_letters: str +ascii_lowercase: str +ascii_uppercase: str +digits: str +hexdigits: str +octdigits: str +punctuation: str +printable: str +whitespace: str + +def capwords(s: str, sep: Optional[str] = ...) -> str: ... + +class Template: + template: str + def __init__(self, template: str) -> None: ... + def substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... + def safe_substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... + +# TODO(MichalPokorny): This is probably badly and/or loosely typed. +class Formatter: + def format(self, __format_string: str, *args: Any, **kwargs: Any) -> str: ... + def vformat(self, format_string: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> str: ... + def parse(self, format_string: str) -> Iterable[Tuple[str, Optional[str], Optional[str], Optional[str]]]: ... + def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... + def get_value(self, key: Union[int, str], args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any: ... + def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], kwargs: Mapping[str, Any]) -> None: ... + def format_field(self, value: Any, format_spec: str) -> Any: ... + def convert_field(self, value: Any, conversion: str) -> Any: ... diff --git a/python/helpers/typeshed/stubs/DateTimeRange/METADATA.toml b/python/helpers/typeshed/stubs/DateTimeRange/METADATA.toml new file mode 100644 index 000000000000..1fbfc0a8e92d --- /dev/null +++ b/python/helpers/typeshed/stubs/DateTimeRange/METADATA.toml @@ -0,0 +1,3 @@ +version = "0.1" +python2 = true +requires = ["types-python-dateutil"] diff --git a/python/helpers/typeshed/stubs/DateTimeRange/datetimerange/__init__.pyi b/python/helpers/typeshed/stubs/DateTimeRange/datetimerange/__init__.pyi new file mode 100644 index 000000000000..53372f47adfe --- /dev/null +++ b/python/helpers/typeshed/stubs/DateTimeRange/datetimerange/__init__.pyi @@ -0,0 +1,47 @@ +import datetime +from typing import Iterable, Optional, Union + +from dateutil.relativedelta import relativedelta + +class DateTimeRange(object): + NOT_A_TIME_STR: str + start_time_format: str + end_time_format: str + is_output_elapse: bool + separator: str + def __init__( + self, + start_datetime: Optional[Union[datetime.datetime, str]] = ..., + end_datetime: Optional[Union[datetime.datetime, str]] = ..., + start_time_format: str = ..., + end_time_format: str = ..., + ) -> None: ... + 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 + def end_datetime(self) -> datetime.datetime: ... + @property + def timedelta(self) -> datetime.timedelta: ... + def is_set(self) -> bool: ... + def validate_time_inversion(self) -> None: ... + def is_valid_timerange(self) -> 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: ... + def set_start_datetime(self, value: Optional[Union[datetime.datetime, str]], timezone: Optional[str] = ...) -> None: ... + def set_end_datetime(self, value: Optional[Union[datetime.datetime, str]], timezone: Optional[str] = ...) -> None: ... + def set_time_range( + self, start: Optional[Union[datetime.datetime, str]], end: Optional[Union[datetime.datetime, str]] + ) -> None: ... + def range(self, step: Union[datetime.timedelta, relativedelta]) -> Iterable[datetime.datetime]: ... + def intersection(self, x: DateTimeRange) -> DateTimeRange: ... + def encompass(self, x: DateTimeRange) -> DateTimeRange: ... + def truncate(self, percentage: float) -> None: ... diff --git a/python/helpers/typeshed/stubs/jwt/METADATA.toml b/python/helpers/typeshed/stubs/jwt/METADATA.toml new file mode 100644 index 000000000000..bc33636c49a8 --- /dev/null +++ b/python/helpers/typeshed/stubs/jwt/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.1" +requires = ["types-cryptography"] diff --git a/python/helpers/typeshed/stubs/jwt/jwt/__init__.pyi b/python/helpers/typeshed/stubs/jwt/jwt/__init__.pyi new file mode 100644 index 000000000000..d2b45a2de6ce --- /dev/null +++ b/python/helpers/typeshed/stubs/jwt/jwt/__init__.pyi @@ -0,0 +1,49 @@ +from typing import Any, Dict, Mapping, Optional, Union + +from cryptography.hazmat.primitives.asymmetric import rsa + +from . import algorithms + +def decode( + jwt: Union[str, bytes], + key: Union[str, bytes, rsa.RSAPublicKey, rsa.RSAPrivateKey] = ..., + verify: bool = ..., + algorithms: Optional[Any] = ..., + options: Optional[Mapping[Any, Any]] = ..., + **kwargs: Any, +) -> Dict[str, Any]: ... +def encode( + payload: Mapping[str, Any], + key: Union[str, bytes, rsa.RSAPublicKey, rsa.RSAPrivateKey], + algorithm: str = ..., + headers: Optional[Mapping[str, Any]] = ..., + json_encoder: Optional[Any] = ..., +) -> bytes: ... +def register_algorithm(alg_id: str, alg_obj: algorithms.Algorithm[Any]) -> None: ... +def unregister_algorithm(alg_id: str) -> None: ... + +class PyJWTError(Exception): ... +class InvalidTokenError(PyJWTError): ... +class DecodeError(InvalidTokenError): ... +class ExpiredSignatureError(InvalidTokenError): ... +class InvalidAudienceError(InvalidTokenError): ... +class InvalidIssuerError(InvalidTokenError): ... +class InvalidIssuedAtError(InvalidTokenError): ... +class ImmatureSignatureError(InvalidTokenError): ... +class InvalidKeyError(PyJWTError): ... +class InvalidAlgorithmError(InvalidTokenError): ... +class MissingRequiredClaimError(InvalidTokenError): ... +class InvalidSignatureError(DecodeError): ... + +# Compatibility aliases (deprecated) +ExpiredSignature = ExpiredSignatureError +InvalidAudience = InvalidAudienceError +InvalidIssuer = InvalidIssuerError + +# These aren't actually documented, but the package +# exports them in __init__.py, so we should at least +# make sure that mypy doesn't raise spurious errors +# if they're used. +get_unverified_header: Any +PyJWT: Any +PyJWS: Any diff --git a/python/helpers/typeshed/stubs/jwt/jwt/algorithms.pyi b/python/helpers/typeshed/stubs/jwt/jwt/algorithms.pyi new file mode 100644 index 000000000000..cb875074e2fe --- /dev/null +++ b/python/helpers/typeshed/stubs/jwt/jwt/algorithms.pyi @@ -0,0 +1,93 @@ +from hashlib import _Hash +from typing import Any, ClassVar, Dict, Generic, Optional, Set, TypeVar, Union + +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric.ec import ( + EllipticCurvePrivateKey, + EllipticCurvePrivateKeyWithSerialization, + EllipticCurvePublicKey, + EllipticCurvePublicKeyWithSerialization, +) +from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey +from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey +from cryptography.hazmat.primitives.asymmetric.utils import Prehashed +from cryptography.hazmat.primitives.hashes import HashAlgorithm + +requires_cryptography = Set[str] + +def get_default_algorithms() -> Dict[str, Algorithm[Any]]: ... + +_K = TypeVar("_K") + +class Algorithm(Generic[_K]): + def prepare_key(self, key: _K) -> _K: ... + def sign(self, msg: bytes, key: _K) -> bytes: ... + def verify(self, msg: bytes, key: _K, sig: bytes) -> bool: ... + @staticmethod + def to_jwk(key_obj: _K) -> str: ... + @staticmethod + def from_jwk(jwk: str) -> _K: ... + +class NoneAlgorithm(Algorithm[None]): + def prepare_key(self, key: Optional[str]) -> None: ... + +class _HashAlg: + def __call__(self, arg: Union[bytes, bytearray, memoryview] = ...) -> _Hash: ... + +class HMACAlgorithm(Algorithm[bytes]): + SHA256: ClassVar[_HashAlg] + SHA384: ClassVar[_HashAlg] + SHA512: ClassVar[_HashAlg] + hash_alg: _HashAlg + def __init__(self, hash_alg: _HashAlg) -> None: ... + def prepare_key(self, key: Union[str, bytes]) -> bytes: ... + @staticmethod + def to_jwk(key_obj: Union[str, bytes]) -> str: ... + @staticmethod + def from_jwk(jwk: Union[str, bytes]) -> bytes: ... + +# Only defined if cryptography is installed. +class RSAAlgorithm(Algorithm[Any]): + SHA256: ClassVar[hashes.SHA256] + SHA384: ClassVar[hashes.SHA384] + SHA512: ClassVar[hashes.SHA512] + hash_alg: Union[HashAlgorithm, Prehashed] + def __init__(self, hash_alg: Union[HashAlgorithm, Prehashed]) -> None: ... + def prepare_key(self, key: Union[bytes, str, RSAPrivateKey, RSAPublicKey]) -> Union[RSAPrivateKey, RSAPublicKey]: ... + @staticmethod + def to_jwk(key_obj: Any) -> str: ... + @staticmethod + def from_jwk(jwk: Union[str, bytes, Dict[str, Any]]) -> Union[RSAPrivateKey, RSAPublicKey]: ... + def sign(self, msg: bytes, key: RSAPrivateKey) -> bytes: ... + def verify(self, msg: bytes, key: RSAPublicKey, sig: bytes) -> bool: ... + +# Only defined if cryptography is installed. +class ECAlgorithm(Algorithm[Any]): + SHA256: ClassVar[hashes.SHA256] + SHA384: ClassVar[hashes.SHA384] + SHA512: ClassVar[hashes.SHA512] + hash_alg: Union[HashAlgorithm, Prehashed] + def __init__(self, hash_alg: Union[HashAlgorithm, Prehashed]) -> None: ... + def prepare_key( + self, key: Union[bytes, str, EllipticCurvePrivateKey, EllipticCurvePublicKey] + ) -> Union[EllipticCurvePrivateKey, EllipticCurvePublicKey]: ... + @staticmethod + def to_jwk(key_obj: Union[EllipticCurvePrivateKeyWithSerialization, EllipticCurvePublicKeyWithSerialization]) -> str: ... + @staticmethod + def from_jwk(jwk: Union[str, bytes]) -> Union[EllipticCurvePrivateKey, EllipticCurvePublicKey]: ... + def sign(self, msg: bytes, key: EllipticCurvePrivateKey) -> bytes: ... + def verify(self, msg: bytes, key: EllipticCurvePublicKey, sig: bytes) -> bool: ... + +# Only defined if cryptography is installed. Types should be tightened when +# cryptography gets type hints. +# See https://github.com/python/typeshed/issues/2542 +class RSAPSSAlgorithm(RSAAlgorithm): + def sign(self, msg: bytes, key: Any) -> bytes: ... + def verify(self, msg: bytes, key: Any, sig: bytes) -> bool: ... + +# Only defined if cryptography is installed. +class Ed25519Algorithm(Algorithm[Any]): + def __init__(self, **kwargs: Any) -> None: ... + def prepare_key(self, key: Union[str, bytes, Ed25519PrivateKey, Ed25519PublicKey]) -> Any: ... + def sign(self, msg: Union[str, bytes], key: Ed25519PrivateKey) -> bytes: ... + def verify(self, msg: Union[str, bytes], key: Ed25519PublicKey, sig: Union[str, bytes]) -> bool: ... diff --git a/python/helpers/typeshed/stubs/jwt/jwt/contrib/__init__.pyi b/python/helpers/typeshed/stubs/jwt/jwt/contrib/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/__init__.pyi b/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/py_ecdsa.pyi b/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/py_ecdsa.pyi new file mode 100644 index 000000000000..0f63de0a6cd0 --- /dev/null +++ b/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/py_ecdsa.pyi @@ -0,0 +1,10 @@ +import hashlib +from typing import Any + +from jwt.algorithms import Algorithm + +class ECAlgorithm(Algorithm[Any]): + SHA256: hashlib._Hash + SHA384: hashlib._Hash + SHA512: hashlib._Hash + def __init__(self, hash_alg: hashlib._Hash) -> None: ... diff --git a/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/pycrypto.pyi b/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/pycrypto.pyi new file mode 100644 index 000000000000..077684c67734 --- /dev/null +++ b/python/helpers/typeshed/stubs/jwt/jwt/contrib/algorithms/pycrypto.pyi @@ -0,0 +1,10 @@ +import hashlib +from typing import Any + +from jwt.algorithms import Algorithm + +class RSAAlgorithm(Algorithm[Any]): + SHA256: hashlib._Hash + SHA384: hashlib._Hash + SHA512: hashlib._Hash + def __init__(self, hash_alg: hashlib._Hash) -> None: ... diff --git a/python/testData/completion/import.after.py b/python/testData/completion/import.after.py index 28fc84bca8ff..00d37543a284 100644 --- a/python/testData/completion/import.after.py +++ b/python/testData/completion/import.after.py @@ -1 +1 @@ -import datetime \ No newline at end of file +import decimal \ No newline at end of file diff --git a/python/testData/completion/import.py b/python/testData/completion/import.py index 4d0b5becbc68..46b04eb86863 100644 --- a/python/testData/completion/import.py +++ b/python/testData/completion/import.py @@ -1 +1 @@ -import datet \ No newline at end of file +import deci \ No newline at end of file diff --git a/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main.py b/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main.py index d7519db480a5..3ba0109b6c26 100644 --- a/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main.py +++ b/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main.py @@ -1 +1 @@ -join \ No newline at end of file +commonpath \ No newline at end of file diff --git a/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main_after.py b/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main_after.py index 0f5e4be0b128..83be5c368383 100644 --- a/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main_after.py +++ b/python/testData/quickFixes/PyAddImportQuickFixTest/osPathFunctions/main_after.py @@ -1,3 +1,3 @@ -from os.path import join +from os.path import commonpath -join \ No newline at end of file +commonpath \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java index 8f88c1935636..3f8501c44573 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/PyAddImportQuickFixTest.java @@ -67,13 +67,13 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase { doMultiFileAutoImportTest("Import", fix -> { final List candidates = fix.getCandidates(); final List names = ContainerUtil.map(candidates, c -> c.getPresentableText()); - assertSameElements(names, "os.path.join()"); + assertSameElements(names, "os.path.commonpath()"); return true; }); }; runWithAdditionalFileInLibDir( "ntpath.py", - "def join(*args):\n" + + "def commonpath(paths):\n" + " pass", f -> runWithAdditionalFileInLibDir( "os.py", @@ -83,7 +83,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase { " import posixpath as path", f1 -> runWithAdditionalFileInLibDir( "posixpath.py", - "def join(*args):\n" + + "def commonpath(paths):\n" + " pass", fileConsumer ) diff --git a/python/tools/src/com/jetbrains/python/tools/PyTypeShedSync.kts b/python/tools/src/com/jetbrains/python/tools/PyTypeShedSync.kts index 09e7a1a849b4..c8cea9eb95d6 100644 --- a/python/tools/src/com/jetbrains/python/tools/PyTypeShedSync.kts +++ b/python/tools/src/com/jetbrains/python/tools/PyTypeShedSync.kts @@ -23,10 +23,8 @@ println("Syncing") sync(repo, bundled) val blacklist = sequenceOf( - "_ast", // leads to broken tests but could be enabled "_collections", "_decimal", - "_dummy_thread", "_functools", "_hotshot", "_markupbase", @@ -74,13 +72,10 @@ val blacklist = sequenceOf( "cstringio", "dataclasses", "dateparser", - "datetimerange", // leads to broken tests but could be enabled "decorator", "dircache", "dis", "docutils", - "dummy_thread", - "dummy_threading", "emoji", "encodings", "ensurepip", @@ -91,7 +86,6 @@ val blacklist = sequenceOf( "first", "flask", "fnmatch", - "formatter", // leads to broken tests but could be enabled "future_builtins", "geoip2", "getopt", @@ -107,7 +101,6 @@ val blacklist = sequenceOf( "imp", "itsdangerous", "jinja2", - "jwt", "kazoo", "lib2to3", "linecache", @@ -129,7 +122,6 @@ val blacklist = sequenceOf( "openssl-python", "optparse", // deprecated "pickletools", - "platform", // leads to broken tests but could be enabled "popen2", "poplib", "profile", @@ -168,7 +160,6 @@ val blacklist = sequenceOf( "spwd", "sre_compile", "stat", - "string", // leads to broken tests but could be enabled "stringio", "stringold", "stringprep", @@ -181,7 +172,6 @@ val blacklist = sequenceOf( "tabulate", "telnetlib", "termcolor", - "thread", "timeit", "tkinter", "toaiff",