-
-
Notifications
You must be signed in to change notification settings - Fork 408
Description
Time for more existential questions.
Currently attrs has involuntarily two ways of attaching its methods. Both come with certain problems and there are (or are suspected) remedies.
We should really discuss this once and for all and transition towards one approach. Here’s what I’ve got:
We tack our methods to the existing class body.
Default behavior.
Problems
- Edge cases may appear because Python runtime is confused. As far as I can tell, so far only the inconsistence in the behavior of
__eq__and__hash__(cf. ) is a real problem so far.
Remedies
- Catch all edge cases. So far it’s only one that popped up so it seems manageable?
We create a new class in @attr.s and return it instead of the original
Happens if slots=True. This has the upside that we create a brand new class that doesn’t change so no edge cases are to be taken care of.
However, the user gets a different class, which comes with its own set of problems.
Problems
super()doesn’t work. TypeError when using super() and slots=True #102
Solutions
At this point, I find the confusingly broken super() worse than the default approach so I would prefer if we found a way to cheat __slots__ into existing classes and I’m not afraid of using C or meta programming to get there.
If others have more problems/solutions, I’ll happily add them.