-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Stop overriding locations for expressions within f-strings #1494
Conversation
What?!?!? Noooo way! |
How the heck did you do this? That looks like a really impressive change. |
What I did was the following:
|
@@ -53,7 +53,7 @@ pub fn native_literals( | |||
.slice_source_code_range(&Range::from_located(arg)); | |||
if lexer::make_tokenizer(&arg_code) | |||
.flatten() | |||
.filter(|(_, tok, _)| matches!(tok, Tok::String { .. } | Tok::Bytes { .. })) | |||
.filter(|(_, tok, _)| matches!(tok, Tok::String { .. })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tok::Bytes
has been removed. The new lexer only uses Tok::String
.
Old lexer:
# Implicitly concatenated string
b"" "" # Tok::Bytes, Tok::String
New lexer:
b"" "" # Tok::String (with kind=Bytes), Tok::String (kind=String)
- kind: DuplicateArgumentName | ||
location: | ||
row: 1 | ||
column: 24 | ||
end_location: | ||
row: 1 | ||
column: 30 | ||
fix: ~ | ||
parent: ~ | ||
- kind: DuplicateArgumentName | ||
location: | ||
row: 5 | ||
column: 27 | ||
end_location: | ||
row: 5 | ||
column: 33 | ||
fix: ~ | ||
parent: ~ | ||
- kind: DuplicateArgumentName | ||
location: | ||
row: 9 | ||
column: 26 | ||
end_location: | ||
row: 9 | ||
column: 32 | ||
fix: ~ | ||
parent: ~ | ||
[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate function arguments like def f(a, a): pass
now yield SyntaxError
( RustPython/RustPython#4380).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should remove F831 because it's never raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we can just keep it as it's not harmful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, we can remove in a separate PR.
(Is this true in all Python versions 3.7+? If you know.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> docker run python:3.7 python -c "def f(a, a): pass"
File "<string>", line 1
SyntaxError: duplicate argument 'a' in function definition
> docker run python:3.8 python -c "def f(a, a): pass"
File "<string>", line 1
SyntaxError: duplicate argument 'a' in function definition
> docker run python:3.9 python -c "def f(a, a): pass"
File "<string>", line 1
SyntaxError: duplicate argument 'a' in function definition
> docker run python:3.10 python -c "def f(a, a): pass"
File "<string>", line 1
SyntaxError: duplicate argument 'a' in function definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems to be a little bit faster... |
Honestly this makes me so happy. This is great. Thank you. |
[![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.203` -> `^0.0.204` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.204/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.204/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.204/compatibility-slim/0.0.203)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.204/confidence-slim/0.0.203)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.204`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.204) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.203...v0.0.204) #### What's Changed - Trim CLI help during generation by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/1492](https://togithub.com/charliermarsh/ruff/pull/1492) - Escape strings when formatting check messages by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/1493](https://togithub.com/charliermarsh/ruff/pull/1493) - Add a "fix message" to every autofix-able check by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/1489](https://togithub.com/charliermarsh/ruff/pull/1489) - Stop overriding locations for expressions within f-strings by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1494](https://togithub.com/charliermarsh/ruff/pull/1494) - Remove F831 by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1495](https://togithub.com/charliermarsh/ruff/pull/1495) - Fix detection of changed imports in isort plugin by [@​squiddy](https://togithub.com/squiddy) in [https://github.com/charliermarsh/ruff/pull/1504](https://togithub.com/charliermarsh/ruff/pull/1504) - Remove unused snapshots by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1497](https://togithub.com/charliermarsh/ruff/pull/1497) - Improve `T20X` ranges by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1502](https://togithub.com/charliermarsh/ruff/pull/1502) - Improve F811 range for function and class definitions by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1499](https://togithub.com/charliermarsh/ruff/pull/1499) - Improve PLW0120 range by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1500](https://togithub.com/charliermarsh/ruff/pull/1500) - Fix N818 range by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1503](https://togithub.com/charliermarsh/ruff/pull/1503) - Include fix commit message when showing violations together with source by [@​squiddy](https://togithub.com/squiddy) in [https://github.com/charliermarsh/ruff/pull/1505](https://togithub.com/charliermarsh/ruff/pull/1505) - Fix E722 and F707 ranges by [@​harupy](https://togithub.com/harupy) in [https://github.com/charliermarsh/ruff/pull/1508](https://togithub.com/charliermarsh/ruff/pull/1508) - Adjust `test_path` helper to detect round-trip autofix issues by [@​squiddy](https://togithub.com/squiddy) in [https://github.com/charliermarsh/ruff/pull/1501](https://togithub.com/charliermarsh/ruff/pull/1501) - Generate source code with detected line ending by [@​squiddy](https://togithub.com/squiddy) in [https://github.com/charliermarsh/ruff/pull/1487](https://togithub.com/charliermarsh/ruff/pull/1487) - Check for Unsupported Files and Display Errors and Warnings by [@​saadmk11](https://togithub.com/saadmk11) in [https://github.com/charliermarsh/ruff/pull/1509](https://togithub.com/charliermarsh/ruff/pull/1509) **Full Changelog**: astral-sh/ruff@v0.0.203...v0.0.204 </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 <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
RustPython/RustPython#4384 fixed the location of
FormattedValue
. Now, expressions within f-strings should have the correct locations. Here's a quick demo.Screen.Recording.2022-12-31.at.13.03.53.mov