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 AlexWaygood
Recipients AlexWaygood, eric.smith, landonjpginn
Date 2021-12-19.19:07:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639940853.69.0.67230788767.issue46134@roundup.psfhosted.org>
In-reply-to
Content
Thanks for the bug report, Landon! I think I can reproduce this with a slightly shorter code snippet, but I don't think this is a bug:

```
>>> from dataclasses import dataclass, field
>>> @dataclass
... class Character:
...     sort_index: int = field(init=False, repr=False)
...     intelligence: int
...     def __post_init__(self):
...         self.sortindex = self.intelligence
... 
>>> c = Character(intelligence=50)
>>> c
Character(intelligence=50)
>>> c.sortindex
50
>>> c.sort_index
AttributeError: 'Character' object has no attribute 'sort_index'. Did you mean: 'sortindex'?
```

This seems like the correct error message to me.

The issue is that your "Character" class has a field named "sort_index", but that field is never assigned to. Instead, you assign an attribute named "sortindex" in your __post_init__ method. So the error message is correct: an instance of your Character class has no attribute "sort_index" (it only has a field named "sort_index"), but it *does* have an attribute "sortindex".
History
Date User Action Args
2021-12-19 19:07:33AlexWaygoodsetrecipients: + AlexWaygood, eric.smith, landonjpginn
2021-12-19 19:07:33AlexWaygoodsetmessageid: <1639940853.69.0.67230788767.issue46134@roundup.psfhosted.org>
2021-12-19 19:07:33AlexWaygoodlinkissue46134 messages
2021-12-19 19:07:33AlexWaygoodcreate