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

Simplify code in lines.py #4167

Merged
merged 5 commits into from Jan 25, 2024
Merged

Conversation

hauntsaninja
Copy link
Collaborator

This has been getting a little messy. These changes neaten things up, we don't have to keep guarding against self.previous_line is not None, we make it clearer what logic has side effects, we reduce the amount of code that tricky before could touch, etc

This change is intended to be a no-op

This has been getting a little messy. These changes neaten things up, we
don't have to keep guarding against `self.previous_line is not None`, we
make it clearer what logic has side effects, we reduce the amount of
code that tricky `before` could touch, etc
@hauntsaninja hauntsaninja added the skip news Pull requests that don't need a changelog entry. label Jan 25, 2024
Comment on lines 626 to 628
if current_line.is_decorator or current_line.is_def or current_line.is_class:
if not current_line.is_decorator:
self.previous_defs.append(current_line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if current_line.is_decorator or current_line.is_def or current_line.is_class:
if not current_line.is_decorator:
self.previous_defs.append(current_line)
if current_line.is_def or current_line.is_class:
self.previous_defs.append(current_line)

This should be equivalent unless I'm missing something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed. Logic was previously inside _maybe_empty_lines_for_class_or_def and I'd just copied the guard around that function call.

@hauntsaninja hauntsaninja merged commit 17f7f29 into psf:main Jan 25, 2024
45 of 46 checks passed
RedGuy12 pushed a commit to RedGuy12/black that referenced this pull request Jan 26, 2024
This has been getting a little messy. These changes neaten things up, we
don't have to keep guarding against `self.previous_line is not None`, we
make it clearer what logic has side effects, we reduce the amount of
code that tricky `before` could touch, etc
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