FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`traceback`: py313 updates by AlexWaygood · Pull Request #12032 · python/typeshed · GitHub

Repository navigation

traceback: py313 updates - #12032

Merged
AlexWaygood merged 4 commits into
python:mainfrom
AlexWaygood:313-traceback
May 27, 2024
Merged

AlexWaygood merged 4 commits into
python:mainfrom
AlexWaygood:313-traceback

Conversation

Copy link
Copy Markdown
Member

A bunch of functions also have new **kwargs parameters in Python 3.13. I deliberately haven't added these, as the only additional keyword argument you should be passing is _colorize -- and that's a private implementation detail that deliberately isn't exposed.

This comment has been minimized.

Comment thread stdlib/traceback.pyi Outdated
Comment on lines +89 to +100
@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]: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think we need - or should - special case show_group. If show_group is True, but the exception is not an exception group, it will be printed as normal. If it's False, but it is an exception group, only a single exception will be printed - and that is fine. I think it was a deliberate design decision that this works either way, but cc @iritkatriel.

Also, format_exception_only now has a colorize option, defaulting to False, which has weirdly being hidden in the kwargs.

AlexWaygood May 27, 2024 •
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I agree we don't need to special-case show_group. I added some special-casing because it seemed to me like it was a case similar to others in typeshed, where we alert users to code that wouldn't necessarily generate an exception at runtime, but would be useless. AFAIK, there's no possible reason to pass show_group=True if the object being passed in is not known to be an ExceptionGroup instance, so it seems indicative of a probable bug if a user does that -- therefore something that a type checker could usefully complain about.

Having said all that, however, I also wasn't sure that this was worth the added complexity here, so I'll remove the special-casing for show_group.

Also, format_exception_only now has a colorize option, defaulting to False, which has weirdly being hidden in the kwargs.

Yes, but I discussed in the PR description why I was deliberately not adding the private _colorize or colorize keyword arguments to any of the traceback functions in this PR. See e.g. python/cpython#111567 (comment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

AFAIK, there's no possible reason to pass show_group=True if the object being passed in is not known to be an ExceptionGroup instance, so it seems indicative of a probable bug if a user does that -- therefore something that a type checker could usefully complain about.

I have to admit that my understanding is limited, but I think the point is that if you have a BaseException you don't know whether it's a group or not. And maybe you want to format all group members in case it's a group:

try:
    ...  # might raise an exception group or single exceptions
except BaseException as exc:
    format_exception_group(exc, show_group=True)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

yeah, that's a fair point

AlexWaygood requested a review from srittau May 27, 2024 11:41
AlexWaygood merged commit de0fc0a into python:main May 27, 2024
AlexWaygood deleted the 313-traceback branch May 27, 2024 11:56

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL