<!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--> <!--You can feel free to delete the sections that do not apply.--> ### Bug report Anyone tried: ~~~ >>> import matplotlib >>> len(matplotlib.rcParams) 0 ~~~ A great example of shooting yourself in the foot with multiple inheritance. Essentially, we do ~~~ class RcParams(MutableMapping, dict): def __getitem__(self, key): return dict.__getitem__(self, key) def __setitem__(self, key, val): return dict.__setitem__(self, key, val) ~~~ but do not reimplement `__len__`. You can work out the consequences yourself. ### Proposed solution Do not inherit `RcParams` from dict, and use a private data dict instead.
Activity
timhoffm commentedon Oct 20, 2018
Fun fact: This results in
rcParams.clear()to not have any effect.tacaswell commentedon Oct 23, 2018
Could we just implement
__len__as a quicker fix? I am curious of this ever worked....timhoffm commentedon Oct 24, 2018
Yes, implementing
__len__is probably a workaround, and I'm fine with that. Don't have time to go into the details in the next days.I assume that this worked when
RcParamswas just inheriting from dict (not tested).Anyway, in the long term, we should aim at just inheriting from
MutableMapping.anntzer commentedon Oct 25, 2018
I think it's a bug in CPython: https://bugs.python.org/issue35063
timhoffm commentedon Oct 25, 2018
Not having fully read the bug, but implementing
__len__would work around this, right?anntzer commentedon Oct 25, 2018
Yes.
The bug is that RcParams() should have raised an exception given than
__len__is a not-overridden abstractmethod.timhoffm commentedon Nov 4, 2018
Closing as the current problem is fixed by #12630.
Still, I would like to get rid of the dict-inheritance in the the long run (#12577).