homepage

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 Germandrummer92
Recipients Germandrummer92
Date 2022年04月06日.08:41:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649234476.2.0.0289467757353.issue47237@roundup.psfhosted.org>
In-reply-to
Content
Hi,
According to https://peps.python.org/pep-0544/#explicitly-declaring-implementation it should be possible to explicitly inherit from Protocols. This however breaks the dataclass constructor when using the @property decorator in the protocol, see this example:
```python
from typing import Protocol
from dataclasses import dataclass
class SomeProtocol(Protocol):
 @property
 def some_value(self) -> str: ...
@dataclass
class SomeDataclasss(SomeProtocol):
 some_value: str
if __name__ == '__main__':
 a = SomeDataclasss(some_value="value") # this crashes with AttributeError: can't set attribute 'some_value'
```
The pattern of @property in the protocol is one taken from the mypy docs (see https://mypy.readthedocs.io/en/stable/protocols.html#recursive-protocols for example). 
When removing the explicit inheritiance mypy also correctly typechecks the dataclass implementation when doing something like, only the explicit inheritance seems to fail in python
```python
a: SomeProtocol = SomeDataclass()
```
History
Date User Action Args
2022年04月06日 08:41:16Germandrummer92setrecipients: + Germandrummer92
2022年04月06日 08:41:16Germandrummer92setmessageid: <1649234476.2.0.0289467757353.issue47237@roundup.psfhosted.org>
2022年04月06日 08:41:16Germandrummer92linkissue47237 messages
2022年04月06日 08:41:15Germandrummer92create

AltStyle によって変換されたページ (->オリジナル) /