mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-28 22:56:55 +08:00
Add several Python 3.8 annotations (#3347)
This commit is contained in:
@@ -3,6 +3,9 @@ import typing
|
||||
from typing import Any, Optional, ClassVar
|
||||
|
||||
PyCF_ONLY_AST: int
|
||||
if sys.version_info >= (3, 8):
|
||||
PyCF_TYPE_COMMENTS: int
|
||||
PyCF_ALLOW_TOP_LEVEL_AWAIT: int
|
||||
|
||||
_identifier = str
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import sys
|
||||
# from _ast below when loaded in an unorthodox way by the Dropbox
|
||||
# internal Bazel integration.
|
||||
import typing as _typing
|
||||
from typing import overload, Any, Iterator, Optional, Union, TypeVar
|
||||
from typing import Any, Iterator, Optional, Tuple, TypeVar, Union, overload
|
||||
|
||||
# The same unorthodox Bazel integration causes issues with sys, which
|
||||
# is imported in both modules. unfortunately we can't just rename sys,
|
||||
@@ -16,27 +16,36 @@ if sys.version_info >= (3, 8):
|
||||
else:
|
||||
from typing_extensions import Literal
|
||||
|
||||
class NodeVisitor():
|
||||
class NodeVisitor:
|
||||
def visit(self, node: AST) -> Any: ...
|
||||
def generic_visit(self, node: AST) -> Any: ...
|
||||
|
||||
class NodeTransformer(NodeVisitor):
|
||||
def generic_visit(self, node: AST) -> Optional[AST]: ...
|
||||
|
||||
_T = TypeVar('_T', bound=AST)
|
||||
_T = TypeVar("_T", bound=AST)
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: Literal["exec"] = ...,
|
||||
type_comments: bool = ..., feature_version: int = ...) -> Module: ...
|
||||
|
||||
def parse(
|
||||
source: Union[str, bytes],
|
||||
filename: Union[str, bytes] = ...,
|
||||
mode: Literal["exec"] = ...,
|
||||
type_comments: bool = ...,
|
||||
feature_version: Union[None, int, Tuple[int, int]] = ...,
|
||||
) -> Module: ...
|
||||
@overload
|
||||
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...,
|
||||
type_comments: bool = ..., feature_version: int = ...) -> AST: ...
|
||||
def parse(
|
||||
source: Union[str, bytes],
|
||||
filename: Union[str, bytes] = ...,
|
||||
mode: str = ...,
|
||||
type_comments: bool = ...,
|
||||
feature_version: Union[None, int, Tuple[int, int]] = ...,
|
||||
) -> AST: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: Literal["exec"] = ...) -> Module: ...
|
||||
|
||||
@overload
|
||||
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ...
|
||||
|
||||
@@ -48,4 +57,5 @@ def increment_lineno(node: _T, n: int = ...) -> _T: ...
|
||||
def iter_child_nodes(node: AST) -> Iterator[AST]: ...
|
||||
def iter_fields(node: AST) -> Iterator[_typing.Tuple[str, Any]]: ...
|
||||
def literal_eval(node_or_string: Union[str, AST]) -> Any: ...
|
||||
def get_source_segment(source: str, node: AST, *, padded: bool = ...) -> Optional[str]: ...
|
||||
def walk(node: AST) -> Iterator[AST]: ...
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import sys
|
||||
from typing import Any, Callable, Generic, Dict, Iterable, Mapping, Optional, Sequence, Tuple, Type, TypeVar, NamedTuple, Union, overload
|
||||
|
||||
_AnyCallable = Callable[..., Any]
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_S = TypeVar("_S")
|
||||
|
||||
@overload
|
||||
def reduce(function: Callable[[_T, _S], _T],
|
||||
sequence: Iterable[_S], initial: _T) -> _T: ...
|
||||
@@ -25,10 +27,13 @@ class _lru_cache_wrapper(Generic[_T]):
|
||||
def cache_info(self) -> _CacheInfo: ...
|
||||
def cache_clear(self) -> None: ...
|
||||
|
||||
class lru_cache():
|
||||
def __init__(self, maxsize: Optional[int] = ..., typed: bool = ...) -> None: ...
|
||||
def __call__(self, f: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def lru_cache(maxsize: Optional[int] = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
|
||||
@overload
|
||||
def lru_cache(maxsize: Callable[..., _T], typed: bool = ...) -> _lru_cache_wrapper[_T]: ...
|
||||
else:
|
||||
def lru_cache(maxsize: Optional[int] = ..., typed: bool = ...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ...
|
||||
|
||||
WRAPPER_ASSIGNMENTS: Sequence[str]
|
||||
WRAPPER_UPDATES: Sequence[str]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Stubs for gc
|
||||
|
||||
from typing import Any, Dict, List, Tuple
|
||||
import sys
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
|
||||
DEBUG_COLLECTABLE: int
|
||||
@@ -16,7 +17,10 @@ def disable() -> None: ...
|
||||
def enable() -> None: ...
|
||||
def get_count() -> Tuple[int, int, int]: ...
|
||||
def get_debug() -> int: ...
|
||||
def get_objects() -> List[Any]: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def get_objects(generation: Optional[int] = ...) -> List[Any]: ...
|
||||
else:
|
||||
def get_objects() -> List[Any]: ...
|
||||
def get_referents(*objs: Any) -> List[Any]: ...
|
||||
def get_referrers(*objs: Any) -> List[Any]: ...
|
||||
def get_stats() -> List[Dict[str, Any]]: ...
|
||||
|
||||
@@ -14,6 +14,8 @@ class NullTranslations:
|
||||
def lgettext(self, message: str) -> str: ...
|
||||
def ngettext(self, singular: str, plural: str, n: int) -> str: ...
|
||||
def lngettext(self, singular: str, plural: str, n: int) -> str: ...
|
||||
def pgettext(self, context: str, message: str) -> str: ...
|
||||
def npgettext(self, context: str, msgid1: str, msgid2: str, n: int) -> str: ...
|
||||
def info(self) -> Any: ...
|
||||
def charset(self) -> Any: ...
|
||||
def output_charset(self) -> Any: ...
|
||||
@@ -52,5 +54,9 @@ def gettext(message: str) -> str: ...
|
||||
def lgettext(message: str) -> str: ...
|
||||
def ngettext(singular: str, plural: str, n: int) -> str: ...
|
||||
def lngettext(singular: str, plural: str, n: int) -> str: ...
|
||||
def pgettext(context: str, message: str) -> str: ...
|
||||
def dpgettext(domain: str, context: str, message: str) -> str: ...
|
||||
def npgettext(context: str, msgid1: str, msgid2: str, n: int) -> str: ...
|
||||
def dnpgettext(domain: str, context: str, msgid1: str, msgid2: str, n: int) -> str: ...
|
||||
|
||||
Catalog = translation
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from typing import Any, IO, Optional
|
||||
from os.path import _PathType
|
||||
import _compression
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
def open(filename, mode: str = ..., compresslevel: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ...) -> IO[Any]: ...
|
||||
@@ -45,5 +46,8 @@ class _GzipReader(_compression.DecompressReader):
|
||||
def __init__(self, fp: IO[bytes]) -> None: ...
|
||||
def read(self, size: int = ...) -> bytes: ...
|
||||
|
||||
def compress(data, compresslevel: int = ...) -> bytes: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def compress(data, compresslevel: int = ..., *, mtime: Optional[float] = ...) -> bytes: ...
|
||||
else:
|
||||
def compress(data, compresslevel: int = ...) -> bytes: ...
|
||||
def decompress(data: bytes) -> bytes: ...
|
||||
|
||||
@@ -611,7 +611,10 @@ class NamedTuple(Tuple[Any, ...]):
|
||||
@classmethod
|
||||
def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ...
|
||||
|
||||
def _asdict(self) -> collections.OrderedDict[str, Any]: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def _asdict(self) -> Dict[str, Any]: ...
|
||||
else:
|
||||
def _asdict(self) -> collections.OrderedDict[str, Any]: ...
|
||||
def _replace(self: _T, **kwargs: Any) -> _T: ...
|
||||
|
||||
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
|
||||
|
||||
Reference in New Issue
Block a user