Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[pycodestyle] Fix whitespace-related false positives and false negatives inside type-parameter lists #13704

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

AlexWaygood
Copy link
Member

Summary

Fixes #13699.

We had false positives and false negatives regarding whitespace in type-parameter lists, that led to conflicts between the linter and the formatter. Specifically, we emitted a false positive here:

def foo[T = int](): ...  # E251: Unexpected spaces around keyword / parameter equals

and a false negative here:

def foo[T:int](): ...  # should be an E231 error here (no space in between `T:` and `int`), but there isn't

This PR adds a TypeParamsState enum, to keep track of whether we're currently visiting the LogicalLineTokens in a type parameters list or not. The common solution is then used to fix the bugs in both rules.

Type parameter lists are new syntax that is only available in Python 3.13+, which is why this is only coming up now.

Test Plan

Fixtures have been added with examples of both class and function definitions that have type parameters

@AlexWaygood AlexWaygood added bug Something isn't working rule Implementing or modifying a lint rule python313 Related to Python 3.13 labels Oct 10, 2024
Copy link
Contributor

github-actions bot commented Oct 10, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! I leave the decision on whether to implement the optimization or not to you if it's feasible before the 0.7 release otherwise that can be deferred for later. I don't see any regression so it might be ok.

@AlexWaygood AlexWaygood merged commit d6b24b6 into main Oct 10, 2024
20 checks passed
@AlexWaygood AlexWaygood deleted the e251-tvar-default branch October 10, 2024 16:24
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working python313 Related to Python 3.13 rule Implementing or modifying a lint rule
Projects
None yet
3 participants