Message408920
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". |
|
Date |
User |
Action |
Args |
2021-12-19 19:07:33 | AlexWaygood | set | recipients:
+ AlexWaygood, eric.smith, landonjpginn |
2021-12-19 19:07:33 | AlexWaygood | set | messageid: <1639940853.69.0.67230788767.issue46134@roundup.psfhosted.org> |
2021-12-19 19:07:33 | AlexWaygood | link | issue46134 messages |
2021-12-19 19:07:33 | AlexWaygood | create | |
|