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

Python Substring: infine loop using ruff v0.1.2 #8299

Closed
bigluck opened this issue Oct 28, 2023 · 3 comments · Fixed by #8369
Closed

Python Substring: infine loop using ruff v0.1.2 #8299

bigluck opened this issue Oct 28, 2023 · 3 comments · Fixed by #8369
Assignees
Labels
bug Something isn't working

Comments

@bigluck
Copy link

bigluck commented Oct 28, 2023

Using ruff v0.1.2 and ruff-pre-commit v0.1.2, pre-commit fails with:

ruff.....................................................................Failed
- hook id: ruff
- exit code: 1

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 `my/service/folder/api_v0/router.py`, the rule codes E231, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

my/service/folder/api_v0/router.py:215:106: E231 Missing whitespace after ':'
Found 101 errors (100 fixed, 1 remaining).

The code is pretty straightforward:

from sqlalchemy.orm import DeclarativeBase

class Base(DeclarativeBase):
    pass

class MyClass(Base):
    file_uri: Mapped[str] = mapped_column(
        String(1024),
        nullable=False,
    )

...

def my_function(snapshot: MyClass):
    assert snapshot.file_uri is not None, f'Run "{req.run_id}" does not have a snapshot file.'
    snapshot_path = snapshot.file_uri[len(f's3://{self.s3_bucket_name}/'):]

Here my pyproject.toml settings:

[tool.mypy]
warn_return_any = true
warn_unused_configs = true

plugins = ["pydantic.mypy"]

# follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
disallow_any_generics = true
check_untyped_defs = true
no_implicit_reexport = true

# for strict mypy: (this is the tricky one :-))
disallow_untyped_defs = true

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true


[tool.coverage.run]
branch = true
omit = [".devenv/*", "stages/*", "tests/*", ".venv/*"]


[tool.coverage.report]


[tool.coverage.xml]
output = "cov.xml"


[tool.ruff]
# Enable Pyflakes and pycodestyle rules.
select = ["E", "F"]
# select = ["ALL"]
preview = true

# Never enforce `E501` (line length violations).
ignore = ["E501"]

# Always autofix, but never try to fix `F401` (unused imports).
fix = true
unfixable = ["F401"]


[tool.ruff.per-file-ignores]
# "__init__.py" = ["E402"]

It works when I set:

    snapshot_path = snapshot.file_uri[len(f's3://{self.s3_bucket_name}/'): len(snapshot.file_uri)]

but still, it wants a space between the first and the second length :/

@charliermarsh
Copy link
Member

Thank you for filing!

@charliermarsh charliermarsh added the bug Something isn't working label Oct 28, 2023
@FishAlchemist
Copy link
Contributor

FishAlchemist commented Oct 28, 2023

This is my simplified pyproject.toml, I don't know if it works for everywhere. Interestingly, I need to run Ruff in the directory where the Python file is located to trigger the issue.
E231 and E202 need to be selected at the same time, otherwise the problem does not occur.

[tool.ruff]
select = ["E231","E202"]
preview = true
fix = true

@charliermarsh
Copy link
Member

(I think flagging those errors in the first place is incorrect -- pycodestyle doesn't.)

@charliermarsh charliermarsh self-assigned this Oct 30, 2023
charliermarsh added a commit that referenced this issue Oct 30, 2023
## Summary

We were considering the `{` within an f-string to be a left brace, which
caused the "space-after-colon" rule to trigger incorrectly.

Closes #8299.
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

Successfully merging a pull request may close this issue.

3 participants