False positive when importing Axes3D

Bug #1512632 reported by Robert Pollak
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
Won't Fix
Wishlist
Unassigned

Bug Description

The following script gives the pyflakes warning "'Axes3D' imported but unused". However, the import is necessary.

from https://de.wikipedia.org/wiki/Matplotlib:
```
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm)
plt.show()
```

As a workaround, I have added the line
> assert Axes3D # suppress "unused import" warning
after the import, since "# NOQA" does not work (https://github.com/kevinw/pyflakes/issues/31).

Revision history for this message
Phil Frost (bitglue) wrote :

Why is it necessary? Do you want it to be available in your module's namespace? Then you can reference it in __all__ to suppress the warning. Or do you just need to import it for some side effect? That's not a great design, but if you can't change that, then you should be able to `del Axes3D` to avoid the warning.

Do either of these solutions work?

Changed in pyflakes:
importance: Undecided → Wishlist
Revision history for this message
Robert Pollak (robert-pollak) wrote :

The import has the side effect to make the `projection='3d'` available.
The script works even when I `del Axes3D` directly after its import - so this suggestion does the job, thank you.

Phil Frost (bitglue)
Changed in pyflakes:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.