This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients eric.smith, rhettinger
Date 2018-02-25.22:23:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Reported by Raymond Hettinger:

When working on the docs for dataclasses, something unexpected came up.  If a dataclass is specified to be frozen, that characteristic is inherited by subclasses which prevents them from assigning additional attributes:

    >>> @dataclass(frozen=True)
    class D:
            x: int = 10

    >>> class S(D):

    >>> s = S()
    >>> s.cached = True
    Traceback (most recent call last):
      File "<pyshell#49>", line 1, in <module>
        s.cached = True
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/", line 448, in _frozen_setattr
        raise FrozenInstanceError(f'cannot assign to field {name!r}')
    dataclasses.FrozenInstanceError: cannot assign to field 'cached'

Other immutable classes in Python don't behave the same way:

    >>> class T(tuple):

    >>> t = T([10, 20, 30])
    >>> t.cached = True

    >>> class F(frozenset):

    >>> f = F([10, 20, 30])
    >>> f.cached = True

    >>> class B(bytes):

    >>> b = B()
    >>> b.cached = True

Date User Action Args
2018-02-25 22:23:51eric.smithsetrecipients: + eric.smith, rhettinger
2018-02-25 22:23:51eric.smithsetmessageid: <>
2018-02-25 22:23:51eric.smithlinkissue32953 messages
2018-02-25 22:23:51eric.smithcreate