Skip to content

Conversation

@CodeMan62
Copy link
Contributor

Summary

closes #19204

Test Plan

  1. test case is added in dedicated file
  2. locally tested the code manually

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good, just one suggestion to avoid allocating a second string.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jul 14, 2025
CodeMan62 and others added 3 commits July 15, 2025 07:16
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
@CodeMan62
Copy link
Contributor Author

Done as said

@dscorbett
Copy link

Does this add extra parentheses if the generator expression is already parenthesized?

@CodeMan62
Copy link
Contributor Author

I think it will, but I don't think it will affect the result. I have tested it

@ntBre
Copy link
Contributor

ntBre commented Jul 15, 2025

Does this add extra parentheses if the generator expression is already parenthesized?

That's a good point. Can we add a test case demonstrating this behavior? I think we should be able to use parenthesized_range to see if the expression already has parentheses and avoid adding new ones:

/// Returns the [`TextRange`] of a given expression including parentheses, if the expression is
/// parenthesized; or `None`, if the expression is not parenthesized.
pub fn parenthesized_range(
expr: ExprRef,

@CodeMan62
Copy link
Contributor Author

Sure we can and i am adding it!

@CodeMan62 CodeMan62 requested a review from ntBre July 19, 2025 15:35
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! Just one more minor simplification suggestion.

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
@ntBre ntBre changed the title [perflint] Parenthesize generator expressions (PERF401) [perflint] Parenthesize generator expressions (PERF401) Jul 23, 2025
@ntBre ntBre merged commit 1dcef1a into astral-sh:main Jul 23, 2025
35 checks passed
dcreager added a commit that referenced this pull request Jul 23, 2025
* main:
  [ty] Fix narrowing and reachability of class patterns with arguments (#19512)
  [ty] Implemented partial support for "find references" language server feature. (#19475)
  [`flake8-use-pathlib`] Add autofix for `PTH101`, `PTH104`, `PTH105`, `PTH121` (#19404)
  [`perflint`] Parenthesize generator expressions (`PERF401`) (#19325)
  [`pep8-naming`] Fix `N802` false positives for `CGIHTTPRequestHandler` and `SimpleHTTPRequestHandler` (#19432)
  [`pylint`] Handle empty comments after line continuation (`PLR2044`) (#19405)
  Move concise diagnostic rendering to `ruff_db` (#19398)
  [ty] highlight the argument in `static_assert` error messages (#19426)
  [ty] Infer single-valuedness for enums based on `int`/`str` (#19510)
  [ty] Restructure submodule query around `File` dependency
  [ty] Make `Module` a Salsa ingredient
  [ty] Reachability analysis for `isinstance(…)` branches (#19503)
  [ty] Normalize single-member enums to their instance type (#19502)
  [ty] Invert `ty_ide` and `ty_project` dependency (#19501)
  [ty] Implement mock language server for testing (#19391)
  [ty] Detect enums if metaclass is a subtype of EnumType/EnumMeta (#19481)
  [ty] perform type narrowing for places marked `global` too (#19381)
AlexWaygood pushed a commit that referenced this pull request Jul 25, 2025
## Summary
closes #19204 

## Test Plan
1. test case is added in dedicated file
2. locally tested the code manually

---------

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Co-authored-by: CodeMan62 <sharmahimanshu150082007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PERF401 fix should parenthesize generator expressions

3 participants