Skip to content

Safe fix for FURB180 can delete comments #22631

@ntBre

Description

@ntBre

This comment will be deleted:

import abc


class C(
    other_kwarg=1,
    # comment
    metaclass=abc.ABCMeta,
):
    pass

https://play.ruff.rs/f64dfdc1-811d-466f-8e49-0f400e1859d0


We should make the fix unsafe here if there are comments in the deletion range, as well as when there are other base classes:

let applicability = if class_def.bases().is_empty() {
Applicability::Safe
} else {
Applicability::Unsafe
};

and update the fix safety docs to reflect the other way the fix can be unsafe:

/// ## Fix safety
/// The rule's fix is unsafe if the class has base classes. This is because the base classes might
/// be validating the class's other base classes (e.g., `typing.Protocol` does this) or otherwise
/// alter runtime behavior if more base classes are added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violationsgood first issueGood for newcomerspreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions