From 675de720d6bc9063ca900a1d79f4544925c3ceed Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 6 Mar 2022 23:22:08 -0800 Subject: [PATCH] Add some missing items to sys.pyi and types.pyi (#7447) --- stdlib/sys.pyi | 24 +++++++++++++++++++++++- stdlib/types.pyi | 4 ++++ tests/stubtest_allowlists/py310.txt | 1 - tests/stubtest_allowlists/py36.txt | 9 ++++----- tests/stubtest_allowlists/py37.txt | 4 ---- tests/stubtest_allowlists/py38.txt | 2 -- tests/stubtest_allowlists/py39.txt | 1 - 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index c437f3f66..89b636cd0 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -5,7 +5,20 @@ from importlib.abc import PathEntryFinder from importlib.machinery import ModuleSpec from io import TextIOWrapper from types import FrameType, ModuleType, TracebackType -from typing import Any, AsyncGenerator, Callable, NoReturn, Optional, Protocol, Sequence, TextIO, TypeVar, Union, overload +from typing import ( + Any, + AsyncGenerator, + Callable, + Coroutine, + NoReturn, + Optional, + Protocol, + Sequence, + TextIO, + TypeVar, + Union, + overload, +) from typing_extensions import Literal, final _T = TypeVar("_T") @@ -292,6 +305,10 @@ if sys.version_info < (3, 9): def getcheckinterval() -> int: ... # deprecated def setcheckinterval(__n: int) -> None: ... # deprecated +if sys.version_info < (3, 9): + # An 11-tuple or None + def callstats() -> tuple[int, int, int, int, int, int, int, int, int, int, int] | None: ... + if sys.version_info >= (3, 8): # Doesn't exist at runtime, but exported in the stubs so pytest etc. can annotate their code more easily. class UnraisableHookArgs: @@ -324,3 +341,8 @@ if sys.version_info >= (3, 6): if sys.version_info >= (3, 7): def get_coroutine_origin_tracking_depth() -> int: ... def set_coroutine_origin_tracking_depth(depth: int) -> None: ... + +if sys.version_info < (3, 8): + _CoroWrapper = Callable[[Coroutine[Any, Any, Any]], Any] + def set_coroutine_wrapper(__wrapper: _CoroWrapper) -> None: ... + def get_coroutine_wrapper() -> _CoroWrapper: ... diff --git a/stdlib/types.pyi b/stdlib/types.pyi index d305d5962..510f8d9eb 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -437,6 +437,10 @@ class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]): def cr_frame(self) -> FrameType: ... @property def cr_running(self) -> bool: ... + if sys.version_info >= (3, 7): + @property + def cr_origin(self) -> tuple[tuple[str, int, str], ...] | None: ... + def close(self) -> None: ... def __await__(self) -> Generator[Any, None, _V_co]: ... def send(self, __arg: _T_contra) -> _T_co: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index a4bfa1b67..f59e0150f 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -161,7 +161,6 @@ multiprocessing.managers.SharedMemoryServer.shutdown multiprocessing.managers.SharedMemoryServer.track_segment pyexpat.XMLParserType.SkippedEntityHandler pyexpat.XMLParserType.intern -types.CoroutineType.cr_origin typing._SpecialForm.__call__ unicodedata.UCD.is_normalized xml.parsers.expat.XMLParserType.SkippedEntityHandler diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index b3ce92694..201e0e05e 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -111,13 +111,15 @@ collections.Generator.gi_yieldfrom collections.Mapping.get # Adding None to the Union messed up mypy collections.Sequence.index # Supporting None in end is not mandatory +# Intentionally omitted because of syntax issues +asyncio.async +asyncio.tasks.async + # Exists at runtime, but missing from stubs _bisect.bisect _bisect.insort -asyncio.async asyncio.futures._TracebackLogger.loop asyncio.futures._TracebackLogger.source_traceback -asyncio.tasks.async calendar.HTMLCalendar.cssclasses distutils.cmd.install_misc distutils.sysconfig.expand_makefile_vars @@ -131,9 +133,6 @@ plistlib.Data.asBase64 plistlib.Data.fromBase64 ssl.SSLObject.verify_client_post_handshake ssl.SSLSocket.verify_client_post_handshake -sys.callstats -sys.get_coroutine_wrapper -sys.set_coroutine_wrapper tempfile.SpooledTemporaryFile.softspace tkinter.dnd.Icon tkinter.dnd.Tester diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index e0d94bde8..9a9173c76 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -116,9 +116,6 @@ ssl.Options.OP_ENABLE_MIDDLEBOX_COMPAT ssl.SSLObject.verify_client_post_handshake ssl.SSLSocket.verify_client_post_handshake stringprep.unicodedata # re-exported from unicodedata -sys.callstats -sys.get_coroutine_wrapper -sys.set_coroutine_wrapper tempfile.SpooledTemporaryFile.softspace tkinter.commondialog.[A-Z_]+ tkinter.commondialog.TclVersion @@ -137,5 +134,4 @@ tkinter.filedialog.TkVersion tkinter.filedialog.wantobjects tkinter.simpledialog.wantobjects tkinter.tix.wantobjects -types.CoroutineType.cr_origin typing._SpecialForm.__call__ diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index d51f85d6e..34c7df60e 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -136,7 +136,6 @@ plistlib.Data.fromBase64 pyexpat.XMLParserType.SkippedEntityHandler pyexpat.XMLParserType.intern stringprep.unicodedata # re-exported from unicodedata -sys.callstats tempfile.SpooledTemporaryFile.softspace tkinter.commondialog.[A-Z_]+ tkinter.commondialog.TclVersion @@ -155,7 +154,6 @@ tkinter.filedialog.TkVersion tkinter.filedialog.wantobjects tkinter.simpledialog.wantobjects tkinter.tix.wantobjects -types.CoroutineType.cr_origin typing._SpecialForm.__call__ unicodedata.UCD.is_normalized xml.parsers.expat.XMLParserType.SkippedEntityHandler diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 666290a70..6464c88c1 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -154,7 +154,6 @@ multiprocessing.managers.SharedMemoryServer.track_segment pyexpat.XMLParserType.SkippedEntityHandler pyexpat.XMLParserType.intern stringprep.unicodedata # re-exported from unicodedata -types.CoroutineType.cr_origin types.GenericAlias.__mro_entries__ typing._SpecialForm.__call__ typing._SpecialForm.__mro_entries__