Skip to content
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

'Dictionary size changed during iteration' in mathtext.py #2925

Closed
takluyver opened this issue Mar 25, 2014 · 5 comments
Closed

'Dictionary size changed during iteration' in mathtext.py #2925

takluyver opened this issue Mar 25, 2014 · 5 comments

Comments

@takluyver
Copy link
Contributor

I'm not sure why this could have started recently, but we're seeing a test failure in IPython which comes from matplotlib:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.3.5/Frameworks/Python.framework/Versions/3.3/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/nose-1.3.1-py3.3.egg/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/IPython/testing/decorators.py", line 225, in skipper_func
    return f(*args, **kwargs)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/IPython/lib/tests/test_latextools.py", line 69, in test_latex_to_html
    img = latextools.latex_to_html("$x^2$")
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/IPython/lib/latextools.py", line 201, in latex_to_html
    base64_data = bytes_to_str(latex_to_png(s, encode=True), 'ascii')
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/IPython/lib/latextools.py", line 100, in latex_to_png
    bin_data = f(s, wrap)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/IPython/lib/latextools.py", line 116, in latex_to_png_mpl
    mt.to_png(f, s, fontsize=12)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.9-x86_64.egg/matplotlib/mathtext.py", line 3093, in to_png
    rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.9-x86_64.egg/matplotlib/mathtext.py", line 3058, in to_rgba
    x, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.9-x86_64.egg/matplotlib/mathtext.py", line 3031, in to_mask
    ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop)
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.9-x86_64.egg/matplotlib/mathtext.py", line 3002, in parse
    self.__class__._parser = Parser()
  File "/Users/minrk/env/sp33/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.9-x86_64.egg/matplotlib/mathtext.py", line 2171, in __init__
    for key, val in locals().items():
RuntimeError: dictionary changed size during iteration

Iterating over locals() is a bit icky, but if we have to do it, wrapping it like this should make it work:

for key, val in list(locals().items()):
    ...
@mdboom
Copy link
Member

mdboom commented Mar 25, 2014

That code has been there forever. I suspect this is Python 3 specific, if anything, but I wish I knew why it's never been noticed before.

@takluyver
Copy link
Contributor Author

Did you stop using 2to3? I think 2to3 would have added a list() call to it automatically. I guess Min updated mpl for the build jobs from 1.3 to 1.4.x while fixing something else. If 1.3 used 2to3 and 1.4 doesn't, that would explain the change. I'm surprised that your own test suite doesn't pick it up, though.

@mdboom
Copy link
Member

mdboom commented Mar 25, 2014

Yeah -- our test code certainly covers those lines, which is why I'm a bit stumped.

We stopped using 2to3 in favor of six for the 1.4.x series.

@takluyver
Copy link
Contributor Author

Bizarre. It's not a new change in Python, either - I can reproduce the error in Python 3.2.4.

@tacaswell
Copy link
Member

Closed as #2926 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants