Skip to content

DOC501 should not raise on ImportError #14534

Closed
@Matt-Ord

Description

@Matt-Ord

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docstringRelated to docstring linting or formattingquestionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions