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:
Charlie Marsh 2023-09-29 14:10:32 -04:00 committed by GitHub
parent b42a8972bf
commit b5280061f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 2 deletions

View file

@ -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=}")

View file

@ -468,7 +468,7 @@ pub fn lint_fix<'a>(
&directives, &directives,
settings, settings,
noqa, noqa,
source_kind, &transformed,
source_type, source_type,
); );

View file

@ -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=}")
|

View file

@ -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,
); );