Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TracebackException swallows attributes of falsey Exception and falsey ExceptionGroup. #132308

Open
Labels
stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@YvesDup

Description

@YvesDup

Bug report

Bug description:

Description

import traceback as tbclass FalseyLenException(Exception):    def __len__(self):        return 0class FalseyBoolException(Exception):    def __bool__(self):        return Falsedef tracebackexception_swallows_cause_and_context():    try:        raise FalseyBoolException("Oh") from KeyError    except Exception as e:        print(f'{e = }, {e.__cause__ = }')        tb.print_exception(e)    print("---"*20)    try:        try:            1/0        except:            raise FalseyLenException("Ah")    except Exception as e:        print(f'{e = }, {e.__context__ = }')        tb.print_exception(e)    print("---"*20)if __name__ == "__main__":    tracebackexception_swallows_cause_and_context()

Ouptput is:

e = FalseyBoolException('Oh'), e.__cause__ = KeyError()Traceback (most recent call last):  File "/Users/yves/Desktop/Bugs/gh-132XXX.py", line 13, in tracebackexception_swallows_cause_and_context    raise FalseyBoolException("Oh") from KeyErrorFalseyBoolException: Oh------------------------------------------------------------e = FalseyLenException('Ah'), e.__context__ = ZeroDivisionError('division by zero')Traceback (most recent call last):  File "/Users/yves/Desktop/Bugs/gh-132XXX.py", line 23, in tracebackexception_swallows_cause_and_context    raise FalseyLenException("Ah")FalseyLenException: Ah

TheCause orContext descriptions are not printed as expected.

Where Does it from ?

These following tests are wrong.

if (eande.__cause__isnotNone

It should be:if (e is not None and e.__cause__ is not None
if (eande.__context__isnotNone

It should be:if (e is not None and and e.__context__ is not None

Linked Issues

See:#132129

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp