Skip to content

Comments

Use more precise error ranges for names#1513

Merged
charliermarsh merged 1 commit intoastral-sh:mainfrom
harupy:identifier-error-ranges
Dec 31, 2022
Merged

Use more precise error ranges for names#1513
charliermarsh merged 1 commit intoastral-sh:mainfrom
harupy:identifier-error-ranges

Conversation

@harupy
Copy link
Contributor

@harupy harupy commented Dec 31, 2022

Improves error ranges for the following rules:

  • E741
  • PLW0602
  • PLE0117

Current

> cargo run -- --select PLW --no-cache --show-source resources/test/fixtures/pylint/global_variable_not_assigned.py --show-source
resources/test/fixtures/pylint/global_variable_not_assigned.py:5:5: PLW0602 Using global for `x` but no assignment is done
  |
5 |     global x
  |     ^^^^^^^^ PLW0602
  |

resources/test/fixtures/pylint/global_variable_not_assigned.py:9:5: PLW0602 Using global for `x` but no assignment is done
  |
9 |     global x
  |     ^^^^^^^^ PLW0602
  |

Found 2 error(s).

Fixed

> cargo run -- --select PLW --no-cache resources/test/fixtures/pylint/global_variable_not_assigned.py --show-source
resources/test/fixtures/pylint/global_variable_not_assigned.py:5:12: PLW0602 Using global for `x` but no assignment is done
  |
5 |     global x
  |            ^ PLW0602
  |

resources/test/fixtures/pylint/global_variable_not_assigned.py:9:12: PLW0602 Using global for `x` but no assignment is done
  |
9 |     global x
  |            ^ PLW0602
  |

Found 2 error(s).

@charliermarsh charliermarsh merged commit 960c5e2 into astral-sh:main Dec 31, 2022
renovate bot referenced this pull request in ixm-one/pytest-cmake-presets Dec 31, 2022
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.204` ->
`^0.0.205` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.205/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.205/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.205/compatibility-slim/0.0.204)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.205/confidence-slim/0.0.204)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.205`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.205)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.204...v0.0.205)

#### What's Changed

- Avoid flagging nested f-strings by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/charliermarsh/ruff/pull/1516](https://togithub.com/charliermarsh/ruff/pull/1516)
- Use more precise error ranges for names by
[@&#8203;harupy](https://togithub.com/harupy) in
[https://github.com/charliermarsh/ruff/pull/1513](https://togithub.com/charliermarsh/ruff/pull/1513)

**Full Changelog**:
astral-sh/ruff@v0.0.204...v0.0.205

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC43NC4yIiwidXBkYXRlZEluVmVyIjoiMzQuNzQuMiJ9-->

Signed-off-by: Renovate Bot <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@not-my-profile
Copy link
Contributor

What's the reasoning behind this range narrowing? The error is about using global, so I think including the global keyword in the range actually makes sense ... so I think I prefer the previous ranges.

@harupy
Copy link
Contributor Author

harupy commented Jan 1, 2023

@not-my-profile That makes sense. I'm happy to file a PR to revert the changes for PLW0602 and PLE0117.

@harupy
Copy link
Contributor Author

harupy commented Jan 1, 2023

The range narrowing might make sense in the following case:

def f():
    global x, y, z
    ^^^^^^^^^^^^^^
    x = y = 1

vs.

def f():
    global x, y, z
                 ^
    x = y = 1

@not-my-profile
Copy link
Contributor

not-my-profile commented Jan 1, 2023

Ah ok, yes that does make sense :) I assume ruff doesn't support multi-ranges?

def f():
    global x, y, z
    ^^^^^^       ^
    x = y = 1

Apparently src/printer.rs uses the annotate-snippets library ... but I don't know if that library supports such annotations.

@charliermarsh
Copy link
Member

We don’t support multi-ranges right now. It could be useful but I’d need to think on it. It’s tricky because it doesn’t map well to the LSP schema.

sharkdp added a commit that referenced this pull request Dec 10, 2025
sharkdp added a commit that referenced this pull request Dec 10, 2025
sharkdp added a commit that referenced this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants