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

Remove redundant condition from has_magic_trailing_comma #4023

Merged
merged 2 commits into from Nov 8, 2023

Conversation

bluetech
Copy link
Contributor

@bluetech bluetech commented Nov 4, 2023

Simplify the has_magic_trailing_comma logic (it will make #3918 a bit easier to implement).

The second if cannot be true at its execution point, because it is already covered by the first if. The condition
comma.parent.type == syms.subscriptlist always holds if closing.parent.type == syms.trailer holds, because subscriptlist only appears inside trailer in the grammar:

trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: (subscript|star_expr) (',' (subscript|star_expr))* [',']

NOTE: I split the PR to two commits, the first one is just a refactor with no logical changes, but makes the argument above easier to follow. The commits should be squashed when merging.

The second `if` cannot be true at its execution point, because it is
already covered by the first `if`. The condition
`comma.parent.type == syms.subscriptlist` always holds if
`closing.parent.type == syms.trailer` holds, because `subscriptlist`
only appears inside `trailer` in the grammar:

```
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: (subscript|star_expr) (',' (subscript|star_expr))* [',']
```
@bluetech
Copy link
Contributor Author

bluetech commented Nov 4, 2023

cc @hauntsaninja - you added some of the condition in 4ebf14d, maybe you can poke a hole in my logic :)

Also c4bd2e3 made a change here (removing the return comma.parent.type == syms.listmaker part), I haven't looked into why though.

@JelleZijlstra
Copy link
Collaborator

Also c4bd2e3 made a change here (removing the return comma.parent.type == syms.listmaker part), I haven't looked into why though.

Looks like the listmaker condition was only used if preview style for that year was off. Turning on the preview style by default meant that that branch was dead.

@JelleZijlstra JelleZijlstra added the skip news Pull requests that don't need a changelog entry. label Nov 4, 2023
Copy link

github-actions bot commented Nov 4, 2023

diff-shades reports zero changes comparing this PR (ac21ded) to main (c54c213).


What is this? | Workflow run | diff-shades documentation

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Seems like you're correct, and diff-shades also found nothing changed by this refactor.

@bluetech
Copy link
Contributor Author

bluetech commented Nov 4, 2023

The branch is only relevant when --skip-magic-trailing-comma is used. I'm not sure whether diff-shades uses each project own config, and if so if any of the projects use the flag (I can check if necessary).

There's always a risk with changes like this of unexpected breakage, so it'd be nice to get some assurance like diff-shades. If diff-shades doesn't cover it, I'll look for some projects which use skip-magic-trailing-comma and check them.

@JelleZijlstra
Copy link
Collaborator

I'll run it on our internal codebase to check.

@JelleZijlstra JelleZijlstra merged commit 72e7a2e into psf:main Nov 8, 2023
41 of 42 checks passed
@bluetech bluetech deleted the rm-redundant-branch branch November 9, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news Pull requests that don't need a changelog entry.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants