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

Extra tests for literals #115

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Extra tests for literals #115

wants to merge 2 commits into from

Conversation

nielsdebruin
Copy link
Contributor

What's changed?

The TabsAndIndentsVisitor cannot correctly handle literals that are not assigned to anything. Currently, this PR add tests to illustrate this behavior.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@nielsdebruin nielsdebruin marked this pull request as ready for review January 10, 2025 09:36
@nielsdebruin nielsdebruin changed the title Fix multiline string literals Extra test for literals Jan 10, 2025
@nielsdebruin nielsdebruin changed the title Extra test for literals Extra tests for literals Jan 10, 2025
Comment on lines +706 to +711
def my_function():
a = """
This is a string that
should align with the function body.
"""
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, if you test this with PyCharm you will notice that it doesn't indent the contents of the string literal. This only happens when you remove the assignment, which identifies the string literal as a doc comment.

This is one area where Java text blocks behave differently. Their content is always stripped of all common leading indentation. As a result the text blocks can be indented without the string's runtime value changing. I think this is an extremely useful feature which I miss in Python. But that explains why the formatter must only indent the contents of doc comment string literals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants