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 remi.lapeyre
Recipients eric.smith, remi.lapeyre, rhettinger, yselivanov
Date 2019-01-02.00:12:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1546387974.33.0.310266178925.issue35527@roundup.psfhosted.org>
In-reply-to
Content
Hi @rhettinger, this is similar to #33474.

I started working on an implementation of this.

With the implementation you propose, if a field has both init=True and frozen=True, it may be set after the creation of the instance:

        @dataclass
        class Person:
            ssn: int = field(init=False, frozen=True)
            name: str

        p = Person(name='foo')
        p.name = 'bar'
        p.ssn = 1234

Wouldn't this conflict with the purpose of safe hashing?

I think it would need __setattr__ to be:

      def __setattr__(self, attr, value):
            if attr in {'ssn', 'birth_city'}:
                 raise TypeError(
                     f'{attr!r} is not settable after initialization')
            return super(cls, self).__setattr__(self, name, attr)

wouldn't it?
History
Date User Action Args
2019-01-02 00:12:55remi.lapeyresetrecipients: + remi.lapeyre, rhettinger, eric.smith, yselivanov
2019-01-02 00:12:54remi.lapeyresetmessageid: <1546387974.33.0.310266178925.issue35527@roundup.psfhosted.org>
2019-01-02 00:12:54remi.lapeyrelinkissue35527 messages
2019-01-02 00:12:54remi.lapeyrecreate