Replace FancyEqMixin and FancyStrMixin with something that better implements their intent
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 10
Description
| @glyph reported | |
|---|---|
| Trac ID | trac#6529 |
| Type | enhancement |
| Created | 2013-05-30 00:22:56Z |
Despite being handy in many situations, FancyEqMixin and FancyStrMixin have a number of deficiencies:
- They don't support inheritance very well, because they don't aggregate
compareAttributesandshowAttributesacross their inheritance hierarchy automatically - You have to re-specify the list of "interesting" attributes twice, when it should really be the same in both cases; as well as likely being the same as at least part of the signature of
__init__. FancyEqMixinimplements equality and non-equality, but not ordering or hashing.- They're old-style, so it's clearly time for a rewrite anyway.
What I think these classes are really trying to do is provide helpers for someone trying to implement a value - that is, a functionally immutable type, something like a named tuple, so that you can refer to the structured parts of a datum.
I think that we should provide a twisted.python.util.Value superclass that provides all of these semantics in a nice bundle; possibly still decomposed so you can have bits of it a la carte. Something like this:
#!py
class MyValue(ValueType(attributes='a b c'.split(), mutable=['a'])):
def foo(self):
return self.b + self.c
This would say: we have attributes ['a', 'b', 'c']. The presence of a mutable attribute, 'a', would disqualify MyValue from having a __hash__, but it could still be compared. We could also have other flags, like "comparable".
Searchable metadata
trac-id__6529 6529
type__enhancement enhancement
reporter__glyph glyph
priority__normal normal
milestone__
branch__
branch_author__
status__new new
resolution__None None
component__core core
keywords__
time__1369873376000000 1369873376000000
changetime__1560836483983902 1560836483983902
version__None None
owner__None None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating FancyEqMixin and FancyStrMixin in the Twisted codebase and reading their existing behavior. The issue proposes a twisted.python.util.Value abstraction with shared attributes and value semantics, including comparison and hashing rules; done would require an agreed design and implementation covering those stated concerns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100