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 AlexWaygood, Germandrummer92, JelleZijlstra, eric.smith, gvanrossum, kj
Date 2022-04-06.10:36:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649241405.12.0.115559104476.issue47237@roundup.psfhosted.org>
In-reply-to
Content
Here's the error without dataclasses:

------
from typing import Protocol

class SomeProtocol(Protocol):
    @property
    def some_value(self) -> str: ...

class SomeClass(SomeProtocol):
    def __init__(self, some_value):
        self.some_value = some_value

if __name__ == '__main__':
    a = SomeClass(some_value="value")
------

Traceback (most recent call last):
  File "foo.py", line 12, in <module>
    a = SomeClass(some_value="value")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "foo.py", line 9, in __init__
    self.some_value = some_value
    ^^^^^^^^^^^^^^^
AttributeError: property 'some_value' of 'SomeClass' object has no setter


And here it is without Protocol:
--------
class SomeProperty:
    @property
    def some_value(self) -> str: ...

class SomeClass(SomeProperty):
    def __init__(self, some_value):
        self.some_value = some_value

if __name__ == '__main__':
    a = SomeClass(some_value="value")
--------

Traceback (most recent call last):
  File "foo.py", line 10, in <module>
    a = SomeClass(some_value="value")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "foo.py", line 7, in __init__
    self.some_value = some_value
    ^^^^^^^^^^^^^^^
AttributeError: property 'some_value' of 'SomeClass' object has no setter
History
Date User Action Args
2022-04-06 10:36:45eric.smithsetrecipients: + eric.smith, gvanrossum, JelleZijlstra, kj, AlexWaygood, Germandrummer92
2022-04-06 10:36:45eric.smithsetmessageid: <1649241405.12.0.115559104476.issue47237@roundup.psfhosted.org>
2022-04-06 10:36:45eric.smithlinkissue47237 messages
2022-04-06 10:36:45eric.smithcreate