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

[Infinite loop] for pyi file #10077

Closed
gaborbernat opened this issue Feb 22, 2024 · 5 comments
Closed

[Infinite loop] for pyi file #10077

gaborbernat opened this issue Feb 22, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@gaborbernat
Copy link

https://github.com/tox-dev/pyproject-api/blob/df39546/src/pyproject_api/_backend.pyi#L1

❯ pre-commit run --all-files
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
Validate GitHub Workflows................................................Passed
codespell................................................................Passed
tox-ini-fmt..............................................................Passed
pyproject-fmt............................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

1 file reformatted, 15 files left unchanged

ruff.....................................................................Failed
- hook id: ruff
- exit code: 1
- files were modified by this hook

error: Failed to converge after 100 iterations.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BInfinite%20loop%5D

...quoting the contents of `src/pyproject_api/_backend.pyi`, the rule codes E302, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

src/pyproject_api/_backend.pyi:3:1: E302 Expected 2 blank lines, found 1
Found 105 errors (104 fixed, 1 remaining).
[*] 1 fixable with the --fix option.

@gaborbernat gaborbernat changed the title [Infinite loop] [Infinite loop] for pyi file Feb 22, 2024
@gaborbernat
Copy link
Author

For now, managed to sidestep the issue with tox-dev/pyproject-api@989d105 (#124)

@charliermarsh
Copy link
Member

Thanks! I'll take a look at this tonight.

@charliermarsh charliermarsh added the bug Something isn't working label Feb 22, 2024
@charliermarsh charliermarsh self-assigned this Feb 22, 2024
@MichaReiser
Copy link
Member

MichaReiser commented Feb 22, 2024

Okay, it seems this isn't specific to pyi files but the conflict is between E302 and I001 where I001 enforces at most 1 blank line (depending on what you specified in lines-after-imports and E302 enforces two empty lines.

That's also why I haven't been able to reproduce this behavior when running the above code in an isolated unit test where I001 isn't enabled.

@gaborbernat
Copy link
Author

I wonder if ruff should fail when conflicting settings are set, or pick a winner and ignore the other rules 🤔

@MichaReiser
Copy link
Member

MichaReiser commented Feb 23, 2024

@gaborbernat, thank you for all your high-quality issues with code examples. It makes fixing issues so much easier
@charliermarsh I'm working on this now. I change the blank line rule to not check empty lines after import statements if isort is enabled.

nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
…stral-sh#10096)

## Summary

This PR changes the `E3*` rules to respect the `isort`
`lines-after-imports` and `lines-between-types` settings. Specifically,
the following rules required changing

* `TooManyBlannkLines` : Respects both settings.
* `BlankLinesTopLevel`: Respects `lines-after-imports`. Doesn't need to
respect `lines-between-types` because it only applies to classes and
functions


The downside of this approach is that `isort` and the blank line rules
emit a diagnostic when there are too many blank lines. The fixes aren't
identical, the blank line is less opinionated, but blank lines accepts
the fix of `isort`.

<details>
	<summary>Outdated approach</summary>
Fixes
astral-sh#10077 (comment)

This PR changes the blank line rules to not enforce the number of blank
lines after imports (top-level) if isort is enabled and leave it to
isort to enforce the right number of lines (depends on the
`isort.lines-after-imports` and `isort.lines-between-types` settings).

The reason to give `isort` precedence over the blank line rules is that
they are configurable. Users that always want to blank lines after
imports can use `isort.lines-after-imports=2` to enforce that
(specifically for imports).

This PR does not fix the incompatibility with the formatter in pyi files
that only uses 0 to 1 blank lines. I'll address this separately.

</details>

## Review
The first commit is a small refactor that simplified implementing the
fix (and makes it easier to reason about what's mutable and what's not).


## Test Plan

I added a new test and verified that it fails with an error that the fix
never converges. I verified the snapshot output after implementing the
fix.

---------

Co-authored-by: Hoël Bagard <34478245+hoel-bagard@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants