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

Issues when showing brokenException.__notes__ #103895

Closed
Assignees
ambv
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@pR0Ps

Description

@pR0Ps

Bug report

Whennotes on an exception cannot be shown because therepr andstr raise exceptions, a<note str() failed> message is shown instead. In the case whereexception.__notes__ is not a sequence and cannot be shown, a<__notes__ repr() failed> is shown. In the second case, the message does not include a trailing newline.

__notes__ is a list containing a broken "note" - output includes a newline:

classA:def__repr__(self):raiseException()e=Exception()e.__notes__= [A()]# !!!raisee
user@host $ ./repro.pyTraceback (most recent call last):  File "./repro.py", line 8, in <module>    raise eException<note str() failed>user@host $

__notes__ is just a single broken "note" - output does not include a newline:

classA:def__repr__(self):raiseException()e=Exception()e.__notes__=A()# !!!raisee
user@host $ ./repro.pyTraceback (most recent call last):  File "./repro.py", line 8, in <module>    raise eException<__notes__ repr() failed>user@host $

Additionally, when__notes__ is a string/bytes, the contents are expoded over multiple lines because of anisinstance(__notes__, Sequence) check.

String:

e=Exception()e.__notes__="a note"raisee
user@host $ ./repro.pyTraceback (most recent call last):  File "./repro.py", line 8, in <module>    raise eExceptionanoteuser@host $

Bytes:

e=Exception()e.__notes__=b"a note"raisee
user@host $ ./repro.pyTraceback (most recent call last):  File "./repro.py", line 8, in <module>    raise eException9732110111116101user@host $

Even though the above are all edge cases, since there are some checks that handle these cases already, it makes sense to handle them more gracefully.

Your environment

  • CPython versions tested on: 3.12.0a7+
  • Operating system and architecture: macOS Mojave (x86)

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-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