Skip to content

Fix FrozenInstanceError displaying empty message in tracebacks#1514

Open
bysiber wants to merge 1 commit intopython-attrs:mainfrom
bysiber:fix/frozen-error-empty-message
Open

Fix FrozenInstanceError displaying empty message in tracebacks#1514
bysiber wants to merge 1 commit intopython-attrs:mainfrom
bysiber:fix/frozen-error-empty-message

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Summary

FrozenInstanceError (and FrozenAttributeError) display an empty error message in tracebacks despite having a msg class attribute.

@attr.s(frozen=True)
class Frozen:
    x = attr.ib()

Frozen(1).x = 2
# attr.exceptions.FrozenInstanceError        <-- no message!
# Expected: attr.exceptions.FrozenInstanceError: can't set attribute

The root cause is that FrozenError defines args as a class variable but never calls super().__init__() with the message. CPython's BaseException.__str__() reads from the C-level args slot which stays empty since __init__ was never passed any arguments.

The fix adds __init__ that passes self.msg to super().__init__(), so str(e) now correctly returns "can't set attribute".

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.

1 participant