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 spaces from import statements #7859

Merged
merged 2 commits into from
Oct 11, 2023
Merged

Remove spaces from import statements #7859

merged 2 commits into from
Oct 11, 2023

Conversation

konstin
Copy link
Member

@konstin konstin commented Oct 9, 2023

Summary Remove spaces from import statements such as

import tqdm .  tqdm
from tqdm .    auto import tqdm

See also #7760 for a better solution.

Test Plan New fixtures

@konstin konstin added the formatter Related to the formatter label Oct 9, 2023
// ```
if memchr::memchr(b'\\', f.context().source()[self.0.range()].as_bytes()).is_some() {
text(self.0.as_str(), Some(self.0.start())).fmt(f)
// The backslashes are line continuations
Copy link
Member

Choose a reason for hiding this comment

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

Can we restore the existing comment, and add a second example to explain that there can be arbitrary whitespace between dots? The new comment feels like a less-useful subset of the existing comment.

.chars()
.filter(|c| !is_python_whitespace(*c) && !matches!(c, '\n' | '\r' | '\\'))
.collect();
text(&no_whitespace, Some(self.0.start())).fmt(f)
Copy link
Member

Choose a reason for hiding this comment

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

Annoying that we pass &str in here only for it to be converted to String internally when formatting, but I don't see any alternative APIs.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could change the text element to use Cow, there are more places where we had owned strings previously.

**Summary** Remove spaces from import statements such as

```python
import tqdm .  tqdm
from tqdm .    auto import tqdm
```

See also #7760 for a better solution.

**Test Plan** New fixtures
@konstin konstin enabled auto-merge (squash) October 11, 2023 11:28
@konstin konstin merged commit 0f759af into main Oct 11, 2023
15 checks passed
@konstin konstin deleted the import-spaces branch October 11, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants