Skip to content

Comments

Avoid caching files with unsupported syntax errors#16425

Merged
MichaReiser merged 3 commits intomainfrom
brent/fix-syntax-error-caching
Feb 28, 2025
Merged

Avoid caching files with unsupported syntax errors#16425
MichaReiser merged 3 commits intomainfrom
brent/fix-syntax-error-caching

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 27, 2025

Summary

This PR includes the new Parsed::unsupported_syntax_errors field when determining if a LinterResult has a syntax error. This prevents caching files with version-related syntax errors, which led to these errors only being reported on the first ruff run.

Fixes #16417 in combination with #16419, modulo the discussion split off into #16418.

Test Plan

New CLI test that reported no errors in the second case on main (see the first commit).

@ntBre ntBre added bug Something isn't working preview Related to preview mode features labels Feb 27, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

&directives,
),
has_syntax_error: !parsed.is_valid(),
has_syntax_error: !parsed.is_valid() || !parsed.unsupported_syntax_errors().is_empty(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have a separate version of is_valid method that checks both ParseError and UnsupportedSyntaxError which can then be used here. I'm not sure what to name the method though as both are syntax errors at the end 😅

@dhruvmanila dhruvmanila added the cache Related to Ruff cache label Feb 28, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I did a quick check that we aren't using the LintResult::has_syntax_errors for anything other than caching.

Can we update the documentation on LinterResult to make it explicit that this includes both syntax and unsupported syntax errors.

@MichaReiser MichaReiser merged commit 4a23756 into main Feb 28, 2025
21 checks passed
@MichaReiser MichaReiser deleted the brent/fix-syntax-error-caching branch February 28, 2025 08:58
dcreager added a commit that referenced this pull request Feb 28, 2025
* main:
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
dcreager added a commit that referenced this pull request Feb 28, 2025
* dcreager/alist-type:
  Remove unneeded shear override
  Update property test CI
  Move alist into red_knot_python_semantic
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
ntBre added a commit that referenced this pull request Feb 28, 2025
…ors`

Summary
--

This is a follow up addressing the comments on #16425. As @dhruvmanila pointed
out, the naming is a bit tricky. I went with `has_no_errors` to try to
differentiate it from `is_valid`. It actually ends up negated in most uses, so
it would be more convenient to have `has_any_errors` or `has_errors`, but I
thought it would sound too much like the opposite of `is_valid` in that case.
I'm definitely open to suggestions here.

Test Plan
--

Existing tests.
ntBre added a commit that referenced this pull request Feb 28, 2025
…ors`

Summary
--

This is a follow up addressing the comments on #16425. As @dhruvmanila pointed
out, the naming is a bit tricky. I went with `has_no_errors` to try to
differentiate it from `is_valid`. It actually ends up negated in most uses, so
it would be more convenient to have `has_any_errors` or `has_errors`, but I
thought it would sound too much like the opposite of `is_valid` in that case.
I'm definitely open to suggestions here.

Test Plan
--

Existing tests.
ntBre added a commit that referenced this pull request Mar 4, 2025
…tax_errors` (#16443)

Summary
--

This is a follow up addressing the comments on #16425. As @dhruvmanila
pointed out, the naming is a bit tricky. I went with `has_no_errors` to
try to differentiate it from `is_valid`. It actually ends up negated in
most uses, so it would be more convenient to have `has_any_errors` or
`has_errors`, but I thought it would sound too much like the opposite of
`is_valid` in that case. I'm definitely open to suggestions here.

Test Plan
--

Existing tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cache Related to Ruff cache preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff 0.9.8 raising error 'SyntaxError: Cannot use match statement on Python 3.9 (syntax was added in Python 3.10)' in Python 3.13

3 participants