-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 __dict__ inheritance #1777
Conversation
It might be better to fix this by defining |
I'm not sure that would do anything as I think that's already true: In [1]: from collections import namedtuple
In [2]: Foo = namedtuple('Foo', 'foo bar')
In [3]: class Bar(Foo): __eq__ = lambda self, other: True
In [4]: f = Foo(1, 2)
In [5]: f.__slots__
Out[5]: ()
In [6]: b = Bar(1, 2)
In [7]: b.__slots__
Out[7]: () |
Without getting in to the subtleties of it all (I'd have to spend a while researching them!): >>> class Wibble(Foo): pass
>>> Wibble(1, 2).__dict__
{}
>>> class Wobble(Foo): __slots__ = ()
>>> Wobble(1, 2).__dict__
OrderedDict([('foo', 1), ('bar', 2)]) |
Oh, of course, I tested it by setting |
62b1c3a
to
8301dd5
Compare
OK, switched to |
Not sure... probably yes. It appeals from a consistency point of view, and the derivatives were all intended to be immutable. Out of interest, how did you spot the need for this PR? (I'm trying to recreate the relevant test failures so I can better understand the possible impact.) |
I think I've tracked this down to things like |
Enough vagueness! If I have to choose an option, then 👍 for slots. 😉 |
8301dd5
to
a50b362
Compare
I added it to everything except |
Tests currently broken by ContinuumIO/anaconda-issues#445. |
We could define |
This should restore the __dict__ property that is necessary in some places.
a50b362
to
6c05c00
Compare
Yep, seems to work alright. |
Looks good. 👍 |
Python 3 __dict__ inheritance
For whatever reason, the
__dict__
property does not get inherited, so it needs to be re-implemented in a few classes.