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

Rules SIM105 cause autofix error #7123

Closed
qarmin opened this issue Sep 4, 2023 · 1 comment
Closed

Rules SIM105 cause autofix error #7123

qarmin opened this issue Sep 4, 2023 · 1 comment
Assignees
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.

Comments

@qarmin
Copy link

qarmin commented Sep 4, 2023

Ruff 0.0.287 (latest changes from main branch)

ruff  *.py --select SIM105 --no-cache --fix

file content(at least simple cpython script shows that this is valid python file):

def write_models(directory, Models):
        try:
            os.makedirs(model_dir);
        except OSError:
            pass;

error

/home/rafal/test/tmp_folder/9173.py:2:9: SIM105 Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass`
Found 1 error.

error: Autofix introduced a syntax error. Reverting all changes.

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

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

...quoting the contents of `/home/rafal/test/tmp_folder/9173.py`, the rule codes SIM105, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

python_compressed.zip

@MichaReiser MichaReiser added bug Something isn't working fuzzer Surfaced via fuzzing. labels Sep 4, 2023
@dhruvmanila
Copy link
Member

As the node doesn't contain the semicolon, that's the only thing which is remaining after the fix which creates an invalid syntax error:

import contextlib
def write_models(directory, Models):
        with contextlib.suppress(OSError):
            os.makedirs(model_dir);
;

@charliermarsh charliermarsh self-assigned this Sep 6, 2023
charliermarsh added a commit that referenced this issue Sep 6, 2023
…7191)

I may revisit this and fix it "properly", but so rare that it's worth
disabling for now: #7123.
zanieb pushed a commit that referenced this issue Sep 6, 2023
…7191)

I may revisit this and fix it "properly", but so rare that it's worth
disabling for now: #7123.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.
Projects
None yet
Development

No branches or pull requests

4 participants