From 7468ab9c90e385365dda0ed017ba1514a892fab8 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 24 May 2024 16:20:40 -0400 Subject: [PATCH 1/4] `traceback`: py313 updates --- stdlib/@tests/stubtest_allowlists/py313.txt | 7 +- stdlib/traceback.pyi | 80 ++++++++++++++++----- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 6402c18c0967..66163e8210bc 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -222,12 +222,7 @@ tkinter.Text.count tkinter.Wm.wm_attributes tkinter.tix trace.CoverageResults.write_results -traceback.StackSummary.should_show_carets -traceback.TracebackException.__init__ -traceback.TracebackException.exc_type -traceback.TracebackException.exc_type_str -traceback.TracebackException.format_exception_only -traceback.format_exception_only +traceback.StackSummary.should_show_carets # https://github.com/python/cpython/pull/112670#discussion_r1613952301 turtle.RawTurtle.settiltangle turtle.__all__ turtle.settiltangle diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 39803003cfe5..6ca64502a9cd 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -3,7 +3,7 @@ from _typeshed import SupportsWrite, Unused from collections.abc import Generator, Iterable, Iterator, Mapping from types import FrameType, TracebackType from typing import Any, Literal, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "extract_stack", @@ -85,7 +85,21 @@ def format_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> # undocumented def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file: SupportsWrite[str] | None = None) -> None: ... -if sys.version_info >= (3, 10): +if sys.version_info >= (3, 13): + @overload + def format_exception_only(exc: BaseExceptionGroup[BaseException], /, *, show_group: bool = False) -> list[str]: ... + @overload + def format_exception_only( + exc: Unused, /, value: BaseExceptionGroup[BaseException], *, show_group: bool = False + ) -> list[str]: ... + @overload + def format_exception_only(exc: BaseException | None, /, *, show_group: Literal[False] = False) -> list[str]: ... + @overload + def format_exception_only( + exc: Unused, /, value: BaseException | None, *, show_group: Literal[False] = False + ) -> list[str]: ... + +elif sys.version_info >= (3, 10): @overload def format_exception_only(exc: BaseException | None, /) -> list[str]: ... @overload @@ -111,13 +125,20 @@ class TracebackException: __context__: TracebackException __suppress_context__: bool stack: StackSummary - exc_type: type[BaseException] filename: str lineno: int text: str offset: int msg: str - if sys.version_info >= (3, 11): + if sys.version_info >= (3, 13): + @property + def exc_type_str(self) -> str: ... + @property + @deprecated("Deprecated in 3.13. Use exc_type_str instead.") + def exc_type(self) -> type[BaseException] | None: ... + else: + exc_type: type[BaseException] + if sys.version_info >= (3, 13): def __init__( self, exc_type: type[BaseException], @@ -130,12 +151,15 @@ class TracebackException: compact: bool = False, max_group_width: int = 15, max_group_depth: int = 10, + save_exc_type: bool = True, _seen: set[int] | None = None, ) -> None: ... - @classmethod - def from_exception( - cls, - exc: BaseException, + elif sys.version_info >= (3, 11): + def __init__( + self, + exc_type: type[BaseException], + exc_value: BaseException, + exc_traceback: TracebackType | None, *, limit: int | None = None, lookup_lines: bool = True, @@ -143,7 +167,8 @@ class TracebackException: compact: bool = False, max_group_width: int = 15, max_group_depth: int = 10, - ) -> Self: ... + _seen: set[int] | None = None, + ) -> None: ... elif sys.version_info >= (3, 10): def __init__( self, @@ -157,6 +182,20 @@ class TracebackException: compact: bool = False, _seen: set[int] | None = None, ) -> None: ... + else: + def __init__( + self, + exc_type: type[BaseException], + exc_value: BaseException, + exc_traceback: TracebackType | None, + *, + limit: int | None = None, + lookup_lines: bool = True, + capture_locals: bool = False, + _seen: set[int] | None = None, + ) -> None: ... + + if sys.version_info >= (3, 11): @classmethod def from_exception( cls, @@ -166,19 +205,21 @@ class TracebackException: lookup_lines: bool = True, capture_locals: bool = False, compact: bool = False, + max_group_width: int = 15, + max_group_depth: int = 10, ) -> Self: ... - else: - def __init__( - self, - exc_type: type[BaseException], - exc_value: BaseException, - exc_traceback: TracebackType | None, + elif sys.version_info >= (3, 10): + @classmethod + def from_exception( + cls, + exc: BaseException, *, limit: int | None = None, lookup_lines: bool = True, capture_locals: bool = False, - _seen: set[int] | None = None, - ) -> None: ... + compact: bool = False, + ) -> Self: ... + else: @classmethod def from_exception( cls, exc: BaseException, *, limit: int | None = None, lookup_lines: bool = True, capture_locals: bool = False @@ -190,7 +231,10 @@ class TracebackException: else: def format(self, *, chain: bool = True) -> Generator[str, None, None]: ... - def format_exception_only(self) -> Generator[str, None, None]: ... + if sys.version_info >= (3, 13): + def format_exception_only(self, *, show_group: bool = False) -> Generator[str, None, None]: ... + else: + def format_exception_only(self) -> Generator[str, None, None]: ... if sys.version_info >= (3, 11): def print(self, *, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ... From 8ae73e398475fb509cca04d3aadfbb1eb739536f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 24 May 2024 16:27:41 -0400 Subject: [PATCH 2/4] placate stubtest --- stdlib/traceback.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 6ca64502a9cd..0885fc2f5fc7 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -232,7 +232,7 @@ class TracebackException: def format(self, *, chain: bool = True) -> Generator[str, None, None]: ... if sys.version_info >= (3, 13): - def format_exception_only(self, *, show_group: bool = False) -> Generator[str, None, None]: ... + def format_exception_only(self, *, show_group: bool = False, _depth: int = 0) -> Generator[str, None, None]: ... else: def format_exception_only(self) -> Generator[str, None, None]: ... From cd5f9cda4397aeb2bbba3397c13f39758a8e13ad Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 27 May 2024 12:41:07 +0100 Subject: [PATCH 3/4] remove special-casing for `show_group` --- stdlib/traceback.pyi | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 0885fc2f5fc7..e14dff7fcd25 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -87,16 +87,10 @@ def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file if sys.version_info >= (3, 13): @overload - def format_exception_only(exc: BaseExceptionGroup[BaseException], /, *, show_group: bool = False) -> list[str]: ... + def format_exception_only(exc: BaseException | None, /, *, show_group: bool = False) -> list[str]: ... @overload def format_exception_only( - exc: Unused, /, value: BaseExceptionGroup[BaseException], *, show_group: bool = False - ) -> list[str]: ... - @overload - def format_exception_only(exc: BaseException | None, /, *, show_group: Literal[False] = False) -> list[str]: ... - @overload - def format_exception_only( - exc: Unused, /, value: BaseException | None, *, show_group: Literal[False] = False + exc: Unused, /, value: BaseException | None, *, show_group: bool = False ) -> list[str]: ... elif sys.version_info >= (3, 10): From 3b0564636e4a55551bcd7e6499cc17295cb51b49 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 May 2024 11:42:46 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/traceback.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index e14dff7fcd25..075c0f4b9de8 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -89,9 +89,7 @@ if sys.version_info >= (3, 13): @overload def format_exception_only(exc: BaseException | None, /, *, show_group: bool = False) -> list[str]: ... @overload - def format_exception_only( - exc: Unused, /, value: BaseException | None, *, show_group: bool = False - ) -> list[str]: ... + def format_exception_only(exc: Unused, /, value: BaseException | None, *, show_group: bool = False) -> list[str]: ... elif sys.version_info >= (3, 10): @overload