mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Use fixed source code for parser context (#7717)
## Summary The parser now uses the raw source code as global context and slices into it to parse debug text. It turns out we were always passing in the _old_ source code, so when code was fixed, we were making invalid accesses. This PR modifies the call to use the _fixed_ source code, which will always be consistent with the tokens. Closes https://github.com/astral-sh/ruff/issues/7711. ## Test Plan `cargo test`
This commit is contained in:
parent
b42a8972bf
commit
b5280061f8
4 changed files with 37 additions and 2 deletions
|
@ -158,3 +158,9 @@ class Foo:
|
||||||
@decorator()
|
@decorator()
|
||||||
def __init__(self: "Foo", foo: int):
|
def __init__(self: "Foo", foo: int):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7711
|
||||||
|
class Class:
|
||||||
|
def __init__(self):
|
||||||
|
print(f"{self.attr=}")
|
||||||
|
|
|
@ -468,7 +468,7 @@ pub fn lint_fix<'a>(
|
||||||
&directives,
|
&directives,
|
||||||
settings,
|
settings,
|
||||||
noqa,
|
noqa,
|
||||||
source_kind,
|
&transformed,
|
||||||
source_type,
|
source_type,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -259,5 +259,34 @@ annotation_presence.py:159:9: ANN204 [*] Missing return type annotation for spec
|
||||||
159 |- def __init__(self: "Foo", foo: int):
|
159 |- def __init__(self: "Foo", foo: int):
|
||||||
159 |+ def __init__(self: "Foo", foo: int) -> None:
|
159 |+ def __init__(self: "Foo", foo: int) -> None:
|
||||||
160 160 | ...
|
160 160 | ...
|
||||||
|
161 161 |
|
||||||
|
162 162 |
|
||||||
|
|
||||||
|
annotation_presence.py:165:9: ANN204 [*] Missing return type annotation for special method `__init__`
|
||||||
|
|
|
||||||
|
163 | # Regression test for: https://github.com/astral-sh/ruff/issues/7711
|
||||||
|
164 | class Class:
|
||||||
|
165 | def __init__(self):
|
||||||
|
| ^^^^^^^^ ANN204
|
||||||
|
166 | print(f"{self.attr=}")
|
||||||
|
|
|
||||||
|
= help: Add `None` return type
|
||||||
|
|
||||||
|
ℹ Suggested fix
|
||||||
|
162 162 |
|
||||||
|
163 163 | # Regression test for: https://github.com/astral-sh/ruff/issues/7711
|
||||||
|
164 164 | class Class:
|
||||||
|
165 |- def __init__(self):
|
||||||
|
165 |+ def __init__(self) -> None:
|
||||||
|
166 166 | print(f"{self.attr=}")
|
||||||
|
|
||||||
|
annotation_presence.py:165:18: ANN101 Missing type annotation for `self` in method
|
||||||
|
|
|
||||||
|
163 | # Regression test for: https://github.com/astral-sh/ruff/issues/7711
|
||||||
|
164 | class Class:
|
||||||
|
165 | def __init__(self):
|
||||||
|
| ^^^^ ANN101
|
||||||
|
166 | print(f"{self.attr=}")
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ pub(crate) fn test_contents<'a>(
|
||||||
&directives,
|
&directives,
|
||||||
settings,
|
settings,
|
||||||
flags::Noqa::Enabled,
|
flags::Noqa::Enabled,
|
||||||
source_kind,
|
&transformed,
|
||||||
source_type,
|
source_type,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue