From 26fa57ab78ce5a460a4283db38198f9fee117eda Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 19 May 2022 19:14:12 -0700 Subject: [PATCH] traceback: update for py311 (#7886) --- stdlib/traceback.pyi | 47 +++++++++++++++++++++++++++-- tests/stubtest_allowlists/py311.txt | 4 --- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 5c4d323a2..16151f943 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -96,6 +96,12 @@ def clear_frames(tb: TracebackType) -> None: ... def walk_stack(f: FrameType | None) -> Iterator[tuple[FrameType, int]]: ... def walk_tb(tb: TracebackType | None) -> Iterator[tuple[FrameType, int]]: ... +if sys.version_info >= (3, 11): + class _ExceptionPrintContext: + def __init__(self) -> None: ... + def indent(self) -> str: ... + def emit(self, text_gen: str | Iterable[str], margin_char: str | None = ...) -> Generator[str, None, None]: ... + class TracebackException: __cause__: TracebackException __context__: TracebackException @@ -107,7 +113,34 @@ class TracebackException: text: str offset: int msg: str - if sys.version_info >= (3, 10): + if sys.version_info >= (3, 11): + def __init__( + self, + exc_type: type[BaseException], + exc_value: BaseException, + exc_traceback: TracebackType | None, + *, + limit: int | None = ..., + lookup_lines: bool = ..., + capture_locals: bool = ..., + compact: bool = ..., + max_group_width: int = ..., + max_group_depth: int = ..., + _seen: set[int] | None = ..., + ) -> None: ... + @classmethod + def from_exception( + cls: type[Self], + exc: BaseException, + *, + limit: int | None = ..., + lookup_lines: bool = ..., + capture_locals: bool = ..., + compact: bool = ..., + max_group_width: int = ..., + max_group_depth: int = ..., + ) -> Self: ... + elif sys.version_info >= (3, 10): def __init__( self, exc_type: type[BaseException], @@ -148,9 +181,16 @@ class TracebackException: ) -> Self: ... def __eq__(self, other: object) -> bool: ... - def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ... + if sys.version_info >= (3, 11): + def format(self, *, chain: bool = ..., _ctx: _ExceptionPrintContext | None = ...) -> Generator[str, None, None]: ... + else: + def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ... + def format_exception_only(self) -> Generator[str, None, None]: ... + if sys.version_info >= (3, 11): + def print(self, *, file: SupportsWrite[str] | None = ..., chain: bool = ...) -> None: ... + class FrameSummary(Iterable[Any]): if sys.version_info >= (3, 11): def __init__( @@ -213,4 +253,7 @@ class StackSummary(list[FrameSummary]): ) -> StackSummary: ... @classmethod def from_list(cls, a_list: list[_PT]) -> StackSummary: ... + if sys.version_info >= (3, 11): + def format_frame_summary(self, frame_summary: FrameSummary) -> str: ... + def format(self) -> list[str]: ... diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index b664146e8..dc2c5dcf1 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -97,10 +97,6 @@ symtable.SymbolTable.has_exec sys.UnraisableHookArgs # Not exported from sys sys.exception tkinter._VersionInfoType.__doc__ -traceback.StackSummary.format_frame_summary -traceback.TracebackException.__init__ -traceback.TracebackException.format -traceback.TracebackException.print types.ClassMethodDescriptorType.__get__ types.CodeType.co_exceptiontable types.CodeType.co_qualname