Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add parenthesized flag to ExprTuple and ExprGenerator #9614

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jan 22, 2024

Summary

This PR adds an parenthesized prop to ExprTuple and ExprGenerator that expose if the tuple/genrator is parenthesized in the source.

The information is useful during linting and formatting, and dedecting if a tuple is parenthesized is somewhat involved.

Should this information be present in the AST: IMO, properties that are needed more than once are worth tracking in the AST, even if they don't have any semantical meaning.
It also simplifies implementing the new parser where it otherwise would need to be necessary to track the information separately.

Test Plan

I added new tests and reviewed the snapshot changes

@MichaReiser MichaReiser marked this pull request as draft January 22, 2024 13:14
@MichaReiser MichaReiser added internal An internal refactor or improvement parser Related to the parser labels Jan 22, 2024
Copy link
Contributor

github-actions bot commented Jan 22, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

warning: Detected debug build without --no-cache.
error: Failed to read examples/How_to_handle_rate_limits.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: trailing comma at line 47 column 4

Formatter (preview)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

ruff format --preview

warning: Detected debug build without --no-cache.
error: Failed to read examples/How_to_handle_rate_limits.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: trailing comma at line 47 column 4

@charliermarsh
Copy link
Member

If we track this for tuples, should we also track it for generators, where it's also optional?

@charliermarsh
Copy link
Member

I def support this. I think I tried to pitch it at one point but there wasn't enough interest 😂

@MichaReiser MichaReiser changed the title Add is_parenthesized flag to ExprTuple Add is_parenthesized flag to ExprTuple and ExprGenerator Feb 26, 2024
@MichaReiser MichaReiser changed the title Add is_parenthesized flag to ExprTuple and ExprGenerator Add parenthesized flag to ExprTuple and ExprGenerator Feb 26, 2024
@MichaReiser MichaReiser marked this pull request as ready for review February 26, 2024 13:38
@MichaReiser MichaReiser enabled auto-merge (squash) February 26, 2024 15:30
@MichaReiser MichaReiser merged commit 77c5561 into main Feb 26, 2024
17 checks passed
@MichaReiser MichaReiser deleted the tuple_is_parenthesized branch February 26, 2024 15:35
nkxxll pushed a commit to nkxxll/ruff that referenced this pull request Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement parser Related to the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants