Skip to content

[RFC] Quo vadis re: classes #223

@hynek

Description

@hynek

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ThinkingNeeds more braining.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions