Skip to content

PTH201 fix does not consider trailing comma #15165

Closed
@InSyncWithFoo

Description

from pathlib import Path

# Before:
_ = Path(".",)
#        ^^^ PTH201

# After:
_ = Path(,)

This happens because the fix is a simple range deletion:

let [Expr::StringLiteral(ast::ExprStringLiteral { value, range })] = &*arguments.args else {
    return;
};

if matches!(value.to_str(), "" | ".") {
    let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
    diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(*range)));
    checker.diagnostics.push(diagnostic);
}

Perhaps it should instead replace arguments.range with ()?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions