mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
[pyupgrade
] Rename private type parameters in PEP 695 generics (UP049
) (#15862)
## Summary This is a new rule to implement the renaming of PEP 695 type parameters with leading underscores after they have (presumably) been converted from standalone type variables by either UP046 or UP047. Part of #15642. I'm not 100% sure the fix is always safe, but I haven't come up with any counterexamples yet. `Renamer` seems pretty precise, so I don't think the usual issues with comments apply. I initially tried writing this as a rule that receives a `Stmt` rather than a `Binding`, but in that case the `checker.semantic().current_scope()` was the global scope, rather than the scope of the type parameters as I needed. Most of the other rules using `Renamer` also used `Binding`s, but it does have the downside of offering separate diagnostics for each parameter to rename. ## Test Plan New snapshot tests for UP049 alone and the combination of UP046, UP049, and PYI018. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
cb71393332
commit
6bb32355ef
13 changed files with 736 additions and 68 deletions
|
@ -542,6 +542,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Pyupgrade, "045") => (RuleGroup::Preview, rules::pyupgrade::rules::NonPEP604AnnotationOptional),
|
||||
(Pyupgrade, "046") => (RuleGroup::Preview, rules::pyupgrade::rules::NonPEP695GenericClass),
|
||||
(Pyupgrade, "047") => (RuleGroup::Preview, rules::pyupgrade::rules::NonPEP695GenericFunction),
|
||||
(Pyupgrade, "049") => (RuleGroup::Preview, rules::pyupgrade::rules::PrivateTypeParameter),
|
||||
|
||||
// pydocstyle
|
||||
(Pydocstyle, "100") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicModule),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue