Closed
Description
I'm getting a 'false positive' on DOC501 when my package has an optional dependency on matplotlib
def get_axis_colorbar(axis: Axes) -> Colorbar | None:
"""Get a colorbar attached to the axis."""
if plt is None:
msg = "Matplotlib is not installed. Please install it with the 'plot' extra."
raise ImportError(msg) # Ruff warns here
for artist in axis.get_children():
if isinstance(artist, plt.cm.ScalarMappable) and artist.colorbar is not None:
return artist.colorbar
return None
Using ruff 0.8. It might be nice to be able to exclude ImportError from this rule, as it is not an error which a user would be 'expected' to see during runtime.