Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AttributeError when using PYTHONOPTIMIZE (due to stripped docstring) #17970

Closed
@emmanuelle

Description

@emmanuelle

Bug report

As I was investigating why the scikit-image CI build using PYTHONOPTIMIZE=2 was failing, I identified the following problem:
when using export PYTHONOPTIMIZE=2, the following code results in an AttributeError

In [1]: from mpl_toolkits.axes_grid1 import make_axes_locatable                                                                                   
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2bee72614a62> in <module>
----> 1 from mpl_toolkits.axes_grid1 import make_axes_locatable

~/sandbox/venv_mpl/lib/python3.7/site-packages/mpl_toolkits/axes_grid1/__init__.py in <module>
----> 1 from . import axes_size as Size
      2 from .axes_divider import Divider, SubplotDivider, make_axes_locatable
      3 from .axes_grid import Grid, ImageGrid, AxesGrid
      4 
      5 from .parasite_axes import host_subplot, host_axes

~/sandbox/venv_mpl/lib/python3.7/site-packages/mpl_toolkits/axes_grid1/axes_size.py in <module>
     13 
     14 from matplotlib import cbook
---> 15 from matplotlib.axes import Axes
     16 
     17 

~/sandbox/venv_mpl/lib/python3.7/site-packages/matplotlib/axes/__init__.py in <module>
----> 1 from ._subplots import *
      2 from ._axes import *

~/sandbox/venv_mpl/lib/python3.7/site-packages/matplotlib/axes/_subplots.py in <module>
      4 from matplotlib import cbook, docstring
      5 import matplotlib.artist as martist
----> 6 from matplotlib.axes._axes import Axes
      7 from matplotlib.gridspec import GridSpec, SubplotSpec
      8 import matplotlib._layoutbox as layoutbox

~/sandbox/venv_mpl/lib/python3.7/site-packages/matplotlib/axes/_axes.py in <module>
     69 
     70 
---> 71 class Axes(_AxesBase):
     72     """
     73     The `Axes` contains most of the figure elements: `~.axis.Axis`,

~/sandbox/venv_mpl/lib/python3.7/site-packages/matplotlib/axes/_axes.py in Axes()
   5303             where=where, interpolate=interpolate, step=step, **kwargs)
   5304 
-> 5305     fill_between.__doc__ = _fill_between_x_or_y.__doc__.format(
   5306         dir="horizontal", ind="x", dep="y")
   5307     fill_between = _preprocess_data(

AttributeError: 'NoneType' object has no attribute 'format'

using matplotlib 3.3.0 in a fresh environment.

The reason is that docstrings are stripped from the code when using PYTHONOPTIMIZE with 1 or 2, hence fill_between.__doc__ is None. One solution could be to put this line in a try/except block.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions