astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.46k stars 1.08k forks source link

duplicate return statements after pre-commit run #13310

Closed mpurusottamc closed 1 month ago

mpurusottamc commented 1 month ago

Some times, after running pre-commit, i notice duplicate return statements in the last function of the file.

Ex:

return api_response

return api_response

See screenshot here for reference. Screenshot 2024-09-10 at 9 14 35 AM

Here's the pre-commit command I run:

pre-commit run --all-files --show-diff-on-failure

Here's how my .pre-commit-config.yaml looks like:

  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: v0.6.4
    hooks:
      - id: ruff
        args:
          [--fix, --exit-non-zero-on-fix, "--line-length=120", "--ignore=E501"]
      - id: ruff-format

Sometimes, i have noticed, there are > 5 return statements. Depending on how many times pre-commit was run. I have not been able to reproduce repeatedly. Will share if I am able to find the steps.

Ruff Version: ruff 0.1.9

MichaReiser commented 1 month ago

Hmm, that sounds obscure.

I don't know if it is related but it seems that pre-commit uses Ruff 0.6.4 but you use Ruff 0.1.9 locally. Can you try upgrading your local ruff version?

mpurusottamc commented 1 month ago

I don't know if it is related but it seems that pre-commit uses Ruff 0.6.4 but you use Ruff 0.1.9 locally. Can you try upgrading your local ruff version?

@MichaReiser I have updated to the latest version for Ruff. I will keep an eye out to see if it happens again. Thanks for your quick response.

charliermarsh commented 1 month ago

Let's close for now, and we can always reopen if it comes up again. Thank you!