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

Infer indentation with imports when logical indent is absent #11608

Merged
merged 1 commit into from
May 30, 2024

Conversation

charliermarsh
Copy link
Member

Summary

In an __init__.py file, it's not uncommon to lack a logical indent (since it may just contain imports). In such cases, we were always falling back to four-space indent. This PR adds detection for indents within import groups.

Closes #11606.

@charliermarsh charliermarsh force-pushed the charlie/ident branch 2 times, most recently from af2a95e to bbe7a30 Compare May 30, 2024 03:46
@charliermarsh charliermarsh added isort Related to import sorting bug Something isn't working labels May 30, 2024
@@ -177,7 +209,6 @@ if True:
&Indentation("\t".to_string())
);

// TODO(charlie): Should non-significant whitespace be detected?
Copy link
Member Author

Choose a reason for hiding this comment

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

Ancient TODO!

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh merged commit bd46cd1 into main May 30, 2024
19 checks passed
@charliermarsh charliermarsh deleted the charlie/ident branch May 30, 2024 04:18
dhruvmanila added a commit that referenced this pull request Jun 20, 2024
## Summary

This PR avoids the `depth` counter when detecting indentation from
non-logical lines because it seems to never be used. It might have been
a leftover when the logic was added originally in #11608.

## Test Plan

`cargo insta test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working isort Related to import sorting
1 participant