Skip to content

Conversation

@augustelalande
Copy link
Contributor

@augustelalande augustelalande commented Mar 23, 2024

Summary

This error was found browsing https://github.com/qarmin/Automated-Fuzzer/actions/runs/8396966850. Which failed when trying to autofix the PT014 violation in the following code:

@pytest.mark.parametrize('data, spec', [(1.0, 1.0), (1.0, 1.0)])
def test_numbers(data, spec):
    ...

Investigation revealed that the implementation was not properly tested, when the duplicate value was also the last in the list. In particular the following function, which is in charge of finding the comma following an element to create the suggested fix,

fn trailing_comma(element: &Expr, source: &str) -> Option<TextSize> {
SimpleTokenizer::starts_at(element.end(), source)
.find(|token| token.kind == SimpleTokenKind::Comma)
.map(|token| token.start())
}

would find the next comma even if it was outside the list itself leading to a lot of code being deleted.

This PR fixes that.

Test Plan

Added misbehaving code to the test fixture.

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh added the bug Something isn't working label Mar 23, 2024
@charliermarsh charliermarsh changed the title Fix PT014 invalid fix Fix PT014 autofix for last item in list Mar 23, 2024
@charliermarsh charliermarsh merged commit 0c194f5 into astral-sh:main Mar 23, 2024
@augustelalande augustelalande deleted the pt014-fix-bug branch March 23, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants