Skip to content

Infer indentation with imports when logical indent is absent#11608

Merged
charliermarsh merged 1 commit intomainfrom
charlie/ident
May 30, 2024
Merged

Infer indentation with imports when logical indent is absent#11608
charliermarsh merged 1 commit intomainfrom
charlie/ident

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
&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!

@github-actions
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
@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix isort break the indent-width

1 participant