Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations for remaining Python 3.8 additions #3358

Merged
merged 34 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f897f45
Add os.add_dll_directory()
srittau Oct 13, 2019
6647511
Add memfd_create() and flags
srittau Oct 13, 2019
8bf6ffc
Add type annotation to flags
srittau Oct 13, 2019
7d071f5
Add stat_result.st_reparse_tag and flags
srittau Oct 13, 2019
4b52207
Add ncurses_version
srittau Oct 13, 2019
308ee3e
Add Path.link_to()
srittau Oct 13, 2019
667dcc3
Add Picker.reducer_override()
srittau Oct 13, 2019
1cff34d
Add plistlib.UID
srittau Oct 13, 2019
cf2232a
Add has_dualstack_ipv6() and create_server()
srittau Oct 13, 2019
ee982cd
Add shlex.join()
srittau Oct 13, 2019
74e5878
Add SSL methods and fields
srittau Oct 13, 2019
0936450
Add Python 3.8 statistics functions and classes
srittau Oct 13, 2019
8bb07d6
Remove obsolete sys.subversion
srittau Oct 13, 2019
c923869
Add sys.unraisablehook
srittau Oct 13, 2019
5d7d684
Add threading.excepthook
srittau Oct 13, 2019
412afbf
Add get_native_id() and Thread.native_id
srittau Oct 13, 2019
f6e1b3b
Add Python 3.8 tkinter methods
srittau Oct 13, 2019
87f288e
Add CLOCK_UPTIME_RAW
srittau Oct 13, 2019
0b2d1fa
Add SupportsIndex
srittau Oct 13, 2019
234cbe7
Add typing.get_origin() and get_args()
srittau Oct 13, 2019
1bfad81
Add unicodedata.is_normalized
srittau Oct 13, 2019
1007e37
Add unittest.mock.AsyncMock
srittau Oct 13, 2019
9ac36f0
Add unittest cleanup methods
srittau Oct 13, 2019
1b7fdb5
Add IsolatedAsyncioTestCase
srittau Oct 13, 2019
c0a553a
Add ElementTree.canonicalize() and C14NWriterTarget
srittau Oct 13, 2019
ce9306b
Consistency fixes
srittau Oct 13, 2019
ebd4979
Add missing classmethod decorator
srittau Oct 13, 2019
51efbb3
Remove dangling comma to make pytype happy
srittau Oct 13, 2019
c000bee
cProfile.Profile can be used as a context manager
srittau Oct 13, 2019
9f8132c
Add asyncio task name handling
srittau Oct 13, 2019
cf2e30f
mmap.flush() now always returns None
srittau Oct 13, 2019
df6ae2a
Add posonlyargcount to CodeType
srittau Oct 13, 2019
6c2dc66
Make flake8 happy
srittau Oct 13, 2019
001db39
Add name arg to concrete class
srittau Oct 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion stdlib/2and3/_curses.pyi
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions stdlib/2and3/cProfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
5 changes: 4 additions & 1 deletion stdlib/2and3/mmap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/2and3/pickle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions stdlib/2and3/plistlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
10 changes: 10 additions & 0 deletions stdlib/2and3/socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions stdlib/2and3/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions stdlib/2and3/threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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,):
Expand Down
14 changes: 8 additions & 6 deletions stdlib/2and3/time.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion stdlib/2and3/unicodedata.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]: ...
Expand Down
76 changes: 72 additions & 4 deletions stdlib/2and3/xml/etree/ElementTree.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion stdlib/3/_thread.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Stubs for _thread

import sys
from threading import Thread
from types import TracebackType
from typing import Any, Callable, Dict, NoReturn, Optional, Tuple, Type
from typing import Any, Callable, Dict, NamedTuple, NoReturn, Optional, Tuple, Type

error = RuntimeError

Expand Down Expand Up @@ -29,3 +31,18 @@ def get_ident() -> int: ...
def stack_size(size: int = ...) -> int: ...

TIMEOUT_MAX: int

if sys.version_info >= (3, 8):
def get_native_id() -> int: ... # only available on some platforms

ExceptHookArgs = NamedTuple(
"ExceptHookArgs",
[
("exc_type", Type[BaseException]),
("exc_value", Optional[BaseException]),
("exc_traceback", Optional[TracebackType]),
("thread", Optional[Thread]),
]
)
def _ExceptHookArgs(args) -> ExceptHookArgs: ...
_excepthook: Callable[[ExceptHookArgs], Any]
7 changes: 6 additions & 1 deletion stdlib/3/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta):
# Future methods
def create_future(self) -> Future[Any]: ...
# Tasks methods
def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ...
if sys.version_info >= (3, 8):
def create_task(
self, coro: Union[Awaitable[_T], Generator[Any, None, _T]], *, name: Optional[str] = ...,
) -> Task[_T]: ...
else:
def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ...
def set_task_factory(self, factory: Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]) -> None: ...
def get_task_factory(self) -> Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]: ...
# Methods for interacting with threads
Expand Down
10 changes: 8 additions & 2 deletions stdlib/3/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ class AbstractEventLoop(metaclass=ABCMeta):
@abstractmethod
def create_future(self) -> Future[Any]: ...
# Tasks methods
@abstractmethod
def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ...
if sys.version_info >= (3, 8):
@abstractmethod
def create_task(
self, coro: Union[Awaitable[_T], Generator[Any, None, _T]], *, name: Optional[str] = ...,
) -> Task[_T]: ...
else:
@abstractmethod
def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ...
@abstractmethod
def set_task_factory(self, factory: Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]) -> None: ...
@abstractmethod
Expand Down
10 changes: 9 additions & 1 deletion stdlib/3/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Task(Future[_T], Generic[_T]):
def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ...
def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ...
def __repr__(self) -> str: ...
if sys.version_info >= (3, 8):
def get_name(self) -> str: ...
def set_name(self, value: object) -> None: ...
def get_stack(self, *, limit: int = ...) -> List[FrameType]: ...
def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ...
def cancel(self) -> bool: ...
Expand All @@ -108,5 +111,10 @@ class Task(Future[_T], Generic[_T]):

if sys.version_info >= (3, 7):
def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ...
def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task[Any]: ...
if sys.version_info >= (3, 8):
def create_task(
coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, name: Optional[str] = ...,
) -> Task[Any]: ...
else:
def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task[Any]: ...
def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task[Any]]: ...
30 changes: 30 additions & 0 deletions stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class stat_result:
st_atime_ns: int # time of most recent access, in nanoseconds
st_mtime_ns: int # time of most recent content modification in nanoseconds
st_ctime_ns: int # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
if sys.version_info >= (3, 8) and sys.platform == "win32":
st_reparse_tag: int

def __getitem__(self, i: int) -> int: ...

Expand Down Expand Up @@ -631,3 +633,31 @@ else:

if sys.version_info >= (3, 7):
def register_at_fork(func: Callable[..., object], when: str) -> None: ...

if sys.version_info >= (3, 8):
if sys.platform == "win32":
class _AddedDllDirectory:
path: Optional[str]
def close(self) -> None: ...
def __enter__(self: _T) -> _T: ...
def __exit__(self, *args: Any) -> None: ...
def add_dll_directory(path: str) -> _AddedDllDirectory: ...
if sys.platform == "linux":
MFD_CLOEXEC: int
MFD_ALLOW_SEALING: int
MFD_HUGETLB: int
MFD_HUGE_SHIFT: int
MFD_HUGE_MASK: int
MFD_HUGE_64KB: int
MFD_HUGE_512KB: int
MFD_HUGE_1MB: int
MFD_HUGE_2MB: int
MFD_HUGE_8MB: int
MFD_HUGE_16MB: int
MFD_HUGE_32MB: int
MFD_HUGE_256MB: int
MFD_HUGE_512MB: int
MFD_HUGE_1GB: int
MFD_HUGE_2GB: int
MFD_HUGE_16GB: int
def memfd_create(name: str, flags: int = ...) -> int: ...
Loading