mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 16:14:24 +08:00
Annotations for remaining Python 3.8 additions (#3358)
* Add os.add_dll_directory() * Add memfd_create() and flags * Add type annotation to flags * Add stat_result.st_reparse_tag and flags * Add ncurses_version * Add Path.link_to() * Add Picker.reducer_override() * Add plistlib.UID * Add has_dualstack_ipv6() and create_server() * Add shlex.join() * Add SSL methods and fields * Add Python 3.8 statistics functions and classes * Remove obsolete sys.subversion * Add sys.unraisablehook * Add threading.excepthook * Add get_native_id() and Thread.native_id * Add Python 3.8 tkinter methods * Add CLOCK_UPTIME_RAW * Add SupportsIndex * Add typing.get_origin() and get_args() * Add unicodedata.is_normalized * Add unittest.mock.AsyncMock Currently this is just an alias for Any like Mock and MagicMock. All of these classes should probably be sub-classing Any and add their own methods. See also #3224. * Add unittest cleanup methods * Add IsolatedAsyncioTestCase * Add ElementTree.canonicalize() and C14NWriterTarget * cProfile.Profile can be used as a context manager * Add asyncio task name handling * mmap.flush() now always returns None * Add posonlyargcount to CodeType
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from typing import Any, BinaryIO, IO, Optional, Tuple, Union, overload
|
||||
from typing import Any, BinaryIO, IO, NamedTuple, Optional, Tuple, Union, overload
|
||||
|
||||
_chtype = Union[str, bytes, int]
|
||||
|
||||
@@ -452,3 +452,7 @@ class _CursesWindow:
|
||||
def vline(self, ch: _chtype, n: int) -> None: ...
|
||||
@overload
|
||||
def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
_ncurses_version = NamedTuple("ncurses_version", [("major", int), ("minor", int), ("patch", int)])
|
||||
ncurses_version: _ncurses_version
|
||||
|
||||
@@ -22,3 +22,6 @@ class Profile:
|
||||
def run(self: _SelfT, cmd: str) -> _SelfT: ...
|
||||
def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ...
|
||||
def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def __enter__(self: _SelfT) -> _SelfT: ...
|
||||
def __exit__(self, *exc_info: Any) -> None: ...
|
||||
|
||||
@@ -35,7 +35,10 @@ class _mmap(Generic[AnyStr]):
|
||||
def close(self) -> None: ...
|
||||
def find(self, sub: AnyStr,
|
||||
start: int = ..., end: int = ...) -> int: ...
|
||||
def flush(self, offset: int = ..., size: int = ...) -> int: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def flush(self, offset: int = ..., size: int = ...) -> None: ...
|
||||
else:
|
||||
def flush(self, offset: int = ..., size: int = ...) -> int: ...
|
||||
def move(self, dest: int, src: int, count: int) -> None: ...
|
||||
def read(self, n: int = ...) -> AnyStr: ...
|
||||
def read_byte(self) -> AnyStr: ...
|
||||
|
||||
@@ -48,7 +48,8 @@ class Pickler:
|
||||
def dump(self, obj: Any) -> None: ...
|
||||
def clear_memo(self) -> None: ...
|
||||
def persistent_id(self, obj: Any) -> Any: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
def reducer_override(self, obj: Any) -> Any: ...
|
||||
|
||||
class Unpickler:
|
||||
if sys.version_info >= (3, 0):
|
||||
|
||||
@@ -55,3 +55,11 @@ if sys.version_info < (3, 7):
|
||||
class Data:
|
||||
data: bytes
|
||||
def __init__(self, data: bytes) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
class UID:
|
||||
data: int
|
||||
def __init__(self, data: int) -> None: ...
|
||||
def __index__(self) -> int: ...
|
||||
def __reduce__(self) -> Any: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
@@ -585,6 +585,16 @@ class socket:
|
||||
def create_connection(address: Tuple[Optional[str], int],
|
||||
timeout: Optional[float] = ...,
|
||||
source_address: Tuple[Union[bytearray, bytes, Text], int] = ...) -> socket: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def has_dualstack_ipv6() -> bool: ...
|
||||
def create_server(
|
||||
address: Tuple[str, int],
|
||||
*,
|
||||
family: AddressFamily = ...,
|
||||
backlog: Optional[int] = ...,
|
||||
reuse_port: bool = ...,
|
||||
dualstack_ipv6: bool = ...,
|
||||
) -> socket: ...
|
||||
|
||||
# the 5th tuple item is an address
|
||||
# TODO the "Tuple[Any, ...]" should be "Union[Tuple[str, int], Tuple[str, int, int, int]]" but that triggers
|
||||
|
||||
@@ -207,6 +207,8 @@ class SSLSocket(socket.socket):
|
||||
def unwrap(self) -> socket.socket: ...
|
||||
def version(self) -> Optional[str]: ...
|
||||
def pending(self) -> int: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def verify_client_post_handshake(self) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
class TLSVersion(enum.IntEnum):
|
||||
@@ -221,6 +223,8 @@ if sys.version_info >= (3, 7):
|
||||
class SSLContext:
|
||||
check_hostname: bool
|
||||
options: int
|
||||
if sys.version_info >= (3, 8):
|
||||
post_handshake_auth: bool
|
||||
@property
|
||||
def protocol(self) -> int: ...
|
||||
verify_flags: int
|
||||
@@ -285,6 +289,8 @@ if sys.version_info >= (3, 5):
|
||||
def do_handshake(self) -> None: ...
|
||||
def unwrap(self) -> None: ...
|
||||
def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def verify_client_post_handshake(self) -> None: ...
|
||||
|
||||
class MemoryBIO:
|
||||
pending: int
|
||||
|
||||
@@ -29,6 +29,9 @@ def enumerate() -> List[Thread]: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
def main_thread() -> Thread: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from _thread import get_native_id as get_native_id
|
||||
|
||||
def settrace(func: _TF) -> None: ...
|
||||
def setprofile(func: Optional[_PF]) -> None: ...
|
||||
def stack_size(size: int = ...) -> int: ...
|
||||
@@ -67,6 +70,9 @@ class Thread:
|
||||
def join(self, timeout: Optional[float] = ...) -> None: ...
|
||||
def getName(self) -> str: ...
|
||||
def setName(self, name: str) -> None: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@property
|
||||
def native_id(self) -> Optional[int]: ... # only available on some platforms
|
||||
def is_alive(self) -> bool: ...
|
||||
def isAlive(self) -> bool: ...
|
||||
def isDaemon(self) -> bool: ...
|
||||
@@ -160,6 +166,9 @@ class Event:
|
||||
def clear(self) -> None: ...
|
||||
def wait(self, timeout: Optional[float] = ...) -> bool: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from _thread import _ExceptHookArgs as ExceptHookArgs, ExceptHookArgs as _ExceptHookArgs # don't ask
|
||||
excepthook: Callable[[_ExceptHookArgs], Any]
|
||||
|
||||
class Timer(Thread):
|
||||
if sys.version_info >= (3,):
|
||||
|
||||
@@ -21,13 +21,15 @@ if sys.version_info >= (3, 7) and sys.platform != 'win32':
|
||||
CLOCK_UPTIME: int # FreeBSD, OpenBSD
|
||||
|
||||
if sys.version_info >= (3, 3) and sys.platform != 'win32':
|
||||
CLOCK_HIGHRES: int = ... # Solaris only
|
||||
CLOCK_MONOTONIC: int = ... # Unix only
|
||||
CLOCK_MONOTONIC_RAW: int = ... # Linux 2.6.28 or later
|
||||
CLOCK_PROCESS_CPUTIME_ID: int = ... # Unix only
|
||||
CLOCK_REALTIME: int = ... # Unix only
|
||||
CLOCK_THREAD_CPUTIME_ID: int = ... # Unix only
|
||||
CLOCK_HIGHRES: int # Solaris only
|
||||
CLOCK_MONOTONIC: int # Unix only
|
||||
CLOCK_MONOTONIC_RAW: int # Linux 2.6.28 or later
|
||||
CLOCK_PROCESS_CPUTIME_ID: int # Unix only
|
||||
CLOCK_REALTIME: int # Unix only
|
||||
CLOCK_THREAD_CPUTIME_ID: int # Unix only
|
||||
|
||||
if sys.version_info >= (3, 8) and sys.platform == "darwin":
|
||||
CLOCK_UPTIME_RAW: int
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
class struct_time(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Stubs for unicodedata (Python 2.7 and 3.4)
|
||||
import sys
|
||||
from typing import Any, Text, TypeVar, Union
|
||||
|
||||
ucd_3_2_0: UCD
|
||||
@@ -14,6 +14,8 @@ def decimal(__chr: Text, __default: _default = ...) -> Union[int, _default]: ...
|
||||
def decomposition(__chr: Text) -> Text: ...
|
||||
def digit(__chr: Text, __default: _default = ...) -> Union[int, _default]: ...
|
||||
def east_asian_width(__chr: Text) -> Text: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def is_normalized(__form: str, __unistr: str) -> bool: ...
|
||||
def lookup(__name: Union[Text, bytes]) -> Text: ...
|
||||
def mirrored(__chr: Text) -> int: ...
|
||||
def name(__chr: Text, __default: _default = ...) -> Union[Text, _default]: ...
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
# Stubs for xml.etree.ElementTree
|
||||
|
||||
from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Generator,
|
||||
IO,
|
||||
ItemsView,
|
||||
Iterable,
|
||||
Iterator,
|
||||
KeysView,
|
||||
List,
|
||||
MutableSequence,
|
||||
Optional,
|
||||
Protocol,
|
||||
Sequence,
|
||||
Text,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
import io
|
||||
import sys
|
||||
|
||||
@@ -43,6 +63,41 @@ else:
|
||||
# _fixtext function in the source). Client code knows best:
|
||||
_str_result_type = Any
|
||||
|
||||
_file_or_filename = Union[str, bytes, int, IO[Any]]
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
class _Writeable(Protocol):
|
||||
def write(self, __s: str) -> Any: ...
|
||||
|
||||
@overload
|
||||
def canonicalize(
|
||||
xml_data: Optional[_parser_input_type] = ...,
|
||||
*,
|
||||
out: None = ...,
|
||||
from_file: Optional[_file_or_filename] = ...,
|
||||
with_comments: bool = ...,
|
||||
strip_text: bool = ...,
|
||||
rewrite_prefixes: bool = ...,
|
||||
qname_aware_tags: Optional[Iterable[str]] = ...,
|
||||
qname_aware_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_tags: Optional[Iterable[str]] = ...,
|
||||
) -> str: ...
|
||||
@overload
|
||||
def canonicalize(
|
||||
xml_data: Optional[_parser_input_type] = ...,
|
||||
*,
|
||||
out: _Writeable,
|
||||
from_file: Optional[_file_or_filename] = ...,
|
||||
with_comments: bool = ...,
|
||||
strip_text: bool = ...,
|
||||
rewrite_prefixes: bool = ...,
|
||||
qname_aware_tags: Optional[Iterable[str]] = ...,
|
||||
qname_aware_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_tags: Optional[Iterable[str]] = ...,
|
||||
) -> None: ...
|
||||
|
||||
class Element(MutableSequence[Element]):
|
||||
tag: _str_result_type
|
||||
attrib: Dict[_str_result_type, _str_result_type]
|
||||
@@ -100,9 +155,6 @@ class QName:
|
||||
text: str
|
||||
def __init__(self, text_or_uri: _str_argument_type, tag: Optional[_str_argument_type] = ...) -> None: ...
|
||||
|
||||
|
||||
_file_or_filename = Union[str, bytes, int, IO[Any]]
|
||||
|
||||
class ElementTree:
|
||||
def __init__(self, element: Optional[Element] = ..., file: Optional[_file_or_filename] = ...) -> None: ...
|
||||
def getroot(self) -> Element: ...
|
||||
@@ -176,6 +228,22 @@ class TreeBuilder:
|
||||
def start(self, tag: _parser_input_type, attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ...
|
||||
def end(self, tag: _parser_input_type) -> Element: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
class C14NWriterTarget:
|
||||
def __init__(
|
||||
self,
|
||||
write: Callable[[str], Any],
|
||||
*,
|
||||
with_comments: bool = ...,
|
||||
strip_text: bool = ...,
|
||||
rewrite_prefixes: bool = ...,
|
||||
qname_aware_tags: Optional[Iterable[str]] = ...,
|
||||
qname_aware_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_attrs: Optional[Iterable[str]] = ...,
|
||||
exclude_tags: Optional[Iterable[str]] = ...,
|
||||
) -> None: ...
|
||||
|
||||
|
||||
class XMLParser:
|
||||
parser: Any
|
||||
target: TreeBuilder
|
||||
|
||||
Reference in New Issue
Block a user