diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/async_comprehension_outside_async_function.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/async_comprehension_outside_async_function.py new file mode 100644 index 0000000000..f91d8f0396 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/async_comprehension_outside_async_function.py @@ -0,0 +1,12 @@ +async def f(): return [[x async for x in foo(n)] for n in range(3)] + +async def test(): return [[x async for x in elements(n)] async for n in range(3)] + +async def f(): [x for x in foo()] and [x async for x in foo()] + +async def f(): + def g(): ... + [x async for x in foo()] + +[x async for x in y] + diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_class_attribute.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_class_attribute.py new file mode 100644 index 0000000000..fa0fd34504 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_class_attribute.py @@ -0,0 +1,3 @@ +match x: + case Point(x=1, x=2): + pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_key.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_key.py new file mode 100644 index 0000000000..e0fd8ea854 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_match_key.py @@ -0,0 +1,3 @@ +match x: + case {'key': 1, 'key': 2}: + pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_type_parameter.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_type_parameter.py new file mode 100644 index 0000000000..4f881e96e2 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/duplicate_type_parameter.py @@ -0,0 +1 @@ +class C[T, T]: pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/global_parameter.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/global_parameter.py new file mode 100644 index 0000000000..65394d9cb4 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/global_parameter.py @@ -0,0 +1,29 @@ +def f(a): + global a + +def g(a): + if True: + global a + +def h(a): + def inner(): + global a + +def i(a): + try: + global a + except Exception: + pass + +def f(a): + a = 1 + global a + +def f(a): + a = 1 + a = 2 + global a + +def f(a): + class Inner: + global a # ok \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_expression.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_expression.py new file mode 100644 index 0000000000..d8fd5608b3 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_expression.py @@ -0,0 +1,8 @@ +type X[T: (yield 1)] = int + +type Y = (yield 1) + +def f[T](x: int) -> (y := 3): return x + +class C[T]((yield from [object])): + pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_star_expression.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_star_expression.py new file mode 100644 index 0000000000..03c083ce91 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/invalid_star_expression.py @@ -0,0 +1,8 @@ +def func(): + return *x + +for *x in range(10): + pass + +def func(): + yield *x \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/irrefutable_case_pattern.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/irrefutable_case_pattern.py new file mode 100644 index 0000000000..dd0dde5f89 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/irrefutable_case_pattern.py @@ -0,0 +1,11 @@ +match value: + case _: + pass + case 1: + pass + +match value: + case irrefutable: + pass + case 1: + pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/multiple_case_assignment.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/multiple_case_assignment.py new file mode 100644 index 0000000000..04d00ba676 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/multiple_case_assignment.py @@ -0,0 +1,5 @@ +match x: + case [a, a]: + pass + case _: + pass \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/rebound_comprehension.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/rebound_comprehension.py new file mode 100644 index 0000000000..3e316dc360 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/rebound_comprehension.py @@ -0,0 +1 @@ +[x:= 2 for x in range(2)] \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/single_starred_assignment.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/single_starred_assignment.py new file mode 100644 index 0000000000..32b0ea8738 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/single_starred_assignment.py @@ -0,0 +1 @@ +*a = [1, 2, 3, 4] \ No newline at end of file diff --git a/crates/ruff_linter/resources/test/fixtures/semantic_errors/write_to_debug.py b/crates/ruff_linter/resources/test/fixtures/semantic_errors/write_to_debug.py new file mode 100644 index 0000000000..ee998417c9 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/semantic_errors/write_to_debug.py @@ -0,0 +1,7 @@ +__debug__ = False + +def process(__debug__): + pass + +class Generic[__debug__]: + pass \ No newline at end of file diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index 3503a69c25..2e4f284bee 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -919,17 +919,6 @@ mod tests { Ok(()) } - /// Wrapper around `test_contents_syntax_errors` for testing a snippet of code instead of a - /// file. - fn test_snippet_syntax_errors(contents: &str, settings: &LinterSettings) -> Vec { - let contents = dedent(contents); - test_contents_syntax_errors( - &SourceKind::Python(contents.to_string()), - Path::new(""), - settings, - ) - } - /// A custom test runner that prints syntax errors in addition to other diagnostics. Adapted /// from `flakes` in pyflakes/mod.rs. fn test_contents_syntax_errors( @@ -972,245 +961,38 @@ mod tests { } #[test_case( - "async_in_sync_error_on_310", - "async def f(): return [[x async for x in foo(n)] for n in range(3)]", - PythonVersion::PY310, - "AsyncComprehensionOutsideAsyncFunction" + Path::new("async_comprehension_outside_async_function.py"), + PythonVersion::PY311 )] #[test_case( - "async_in_sync_okay_on_311", - "async def f(): return [[x async for x in foo(n)] for n in range(3)]", - PythonVersion::PY311, - "AsyncComprehensionOutsideAsyncFunction" + Path::new("async_comprehension_outside_async_function.py"), + PythonVersion::PY310 )] - #[test_case( - "async_in_sync_okay_on_310", - "async def test(): return [[x async for x in elements(n)] async for n in range(3)]", - PythonVersion::PY310, - "AsyncComprehensionOutsideAsyncFunction" - )] - #[test_case( - "deferred_function_body", - " - async def f(): [x for x in foo()] and [x async for x in foo()] - async def f(): - def g(): ... - [x async for x in foo()] - ", - PythonVersion::PY310, - "AsyncComprehensionOutsideAsyncFunction" - )] - #[test_case( - "async_in_sync_false_positive", - "[x async for x in y]", - PythonVersion::PY310, - "AsyncComprehensionOutsideAsyncFunction" - )] - #[test_case( - "rebound_comprehension", - "[x:= 2 for x in range(2)]", - PythonVersion::PY310, - "ReboundComprehensionVariable" - )] - #[test_case( - "duplicate_type_param", - "class C[T, T]: pass", - PythonVersion::PY312, - "DuplicateTypeParameter" - )] - #[test_case( - "multiple_case_assignment", - " - match x: - case [a, a]: - pass - case _: - pass - ", - PythonVersion::PY310, - "MultipleCaseAssignment" - )] - #[test_case( - "duplicate_match_key", - " - match x: - case {'key': 1, 'key': 2}: - pass - ", - PythonVersion::PY310, - "DuplicateMatchKey" - )] - #[test_case( - "global_parameter", - " - def f(a): - global a + #[test_case(Path::new("rebound_comprehension.py"), PythonVersion::PY310)] + #[test_case(Path::new("duplicate_type_parameter.py"), PythonVersion::PY312)] + #[test_case(Path::new("multiple_case_assignment.py"), PythonVersion::PY310)] + #[test_case(Path::new("duplicate_match_key.py"), PythonVersion::PY310)] + #[test_case(Path::new("duplicate_match_class_attribute.py"), PythonVersion::PY310)] + #[test_case(Path::new("invalid_star_expression.py"), PythonVersion::PY310)] + #[test_case(Path::new("irrefutable_case_pattern.py"), PythonVersion::PY310)] + #[test_case(Path::new("single_starred_assignment.py"), PythonVersion::PY310)] + #[test_case(Path::new("write_to_debug.py"), PythonVersion::PY312)] + #[test_case(Path::new("write_to_debug.py"), PythonVersion::PY310)] + #[test_case(Path::new("invalid_expression.py"), PythonVersion::PY312)] + #[test_case(Path::new("global_parameter.py"), PythonVersion::PY310)] + fn test_semantic_errors(path: &Path, python_version: PythonVersion) -> Result<()> { + let snapshot = format!( + "semantic_syntax_error_{}_{}", + path.to_string_lossy(), + python_version + ); + let path = Path::new("resources/test/fixtures/semantic_errors").join(path); + let contents = std::fs::read_to_string(&path)?; + let source_kind = SourceKind::Python(contents); - def g(a): - if True: - global a - - def h(a): - def inner(): - global a - - def i(a): - try: - global a - except Exception: - pass - - def f(a): - a = 1 - global a - - def f(a): - a = 1 - a = 2 - global a - - def f(a): - class Inner: - global a # ok - ", - PythonVersion::PY310, - "GlobalParameter" - )] - #[test_case( - "duplicate_match_class_attribute", - " - match x: - case Point(x=1, x=2): - pass - ", - PythonVersion::PY310, - "DuplicateMatchClassAttribute" - )] - #[test_case( - "invalid_star_expression", - " - def func(): - return *x - ", - PythonVersion::PY310, - "InvalidStarExpression" - )] - #[test_case( - "invalid_star_expression_for", - " - for *x in range(10): - pass - ", - PythonVersion::PY310, - "InvalidStarExpression" - )] - #[test_case( - "invalid_star_expression_yield", - " - def func(): - yield *x - ", - PythonVersion::PY310, - "InvalidStarExpression" - )] - #[test_case( - "irrefutable_case_pattern_wildcard", - " - match value: - case _: - pass - case 1: - pass - ", - PythonVersion::PY310, - "IrrefutableCasePattern" - )] - #[test_case( - "irrefutable_case_pattern_capture", - " - match value: - case irrefutable: - pass - case 1: - pass - ", - PythonVersion::PY310, - "IrrefutableCasePattern" - )] - #[test_case( - "single_starred_assignment", - "*a = [1, 2, 3, 4]", - PythonVersion::PY310, - "SingleStarredAssignment" - )] - #[test_case( - "write_to_debug", - " - __debug__ = False - ", - PythonVersion::PY310, - "WriteToDebug" - )] - #[test_case( - "write_to_debug_in_function_param", - " - def process(__debug__): - pass - ", - PythonVersion::PY310, - "WriteToDebug" - )] - #[test_case( - "write_to_debug_class_type_param", - " - class Generic[__debug__]: - pass - ", - PythonVersion::PY312, - "WriteToDebug" - )] - #[test_case( - "invalid_expression_yield_in_type_param", - " - type X[T: (yield 1)] = int - ", - PythonVersion::PY312, - "InvalidExpression" - )] - #[test_case( - "invalid_expression_yield_in_type_alias", - " - type Y = (yield 1) - ", - PythonVersion::PY312, - "InvalidExpression" - )] - #[test_case( - "invalid_expression_walrus_in_return_annotation", - " - def f[T](x: int) -> (y := 3): return x - ", - PythonVersion::PY312, - "InvalidExpression" - )] - #[test_case( - "invalid_expression_yield_from_in_base_class", - " - class C[T]((yield from [object])): - pass - ", - PythonVersion::PY312, - "InvalidExpression" - )] - fn test_semantic_errors( - name: &str, - contents: &str, - python_version: PythonVersion, - error_type: &str, - ) { - let snapshot = format!("semantic_syntax_error_{error_type}_{name}_{python_version}"); - let diagnostics = test_snippet_syntax_errors( - contents, + let diagnostics = test_contents_syntax_errors( + &source_kind, + &path, &LinterSettings { rules: settings::rule_table::RuleTable::empty(), unresolved_target_version: python_version.into(), @@ -1218,7 +1000,11 @@ mod tests { ..Default::default() }, ); - assert_diagnostics!(snapshot, diagnostics); + insta::with_settings!({filters => vec![(r"\\", "/")]}, { + assert_diagnostics!(format!("{snapshot}"), diagnostics); + }); + + Ok(()) } #[test_case(PythonVersion::PY310)] diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_310_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_310_3.10.snap deleted file mode 100644 index 4ba33c756c..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_310_3.10.snap +++ /dev/null @@ -1,4 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- - diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_311_3.11.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_311_3.11.snap deleted file mode 100644 index 4ba33c756c..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_okay_on_311_3.11.snap +++ /dev/null @@ -1,4 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- - diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_deferred_function_body_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_deferred_function_body_3.10.snap deleted file mode 100644 index 4ba33c756c..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_deferred_function_body_3.10.snap +++ /dev/null @@ -1,4 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- - diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchClassAttribute_duplicate_match_class_attribute_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchClassAttribute_duplicate_match_class_attribute_3.10.snap deleted file mode 100644 index 5c8dcb3dea..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchClassAttribute_duplicate_match_class_attribute_3.10.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: attribute name `x` repeated in class pattern - --> :3:21 - | -2 | match x: -3 | case Point(x=1, x=2): - | ^ -4 | pass - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_GlobalParameter_global_parameter_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_GlobalParameter_global_parameter_3.10.snap deleted file mode 100644 index c1c7fbd378..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_GlobalParameter_global_parameter_3.10.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: name `a` is parameter and global - --> :3:12 - | -2 | def f(a): -3 | global a - | ^ -4 | -5 | def g(a): - | - -invalid-syntax: name `a` is parameter and global - --> :7:16 - | -5 | def g(a): -6 | if True: -7 | global a - | ^ -8 | -9 | def h(a): - | - -invalid-syntax: name `a` is parameter and global - --> :15:16 - | -13 | def i(a): -14 | try: -15 | global a - | ^ -16 | except Exception: -17 | pass - | - -invalid-syntax: name `a` is parameter and global - --> :21:12 - | -19 | def f(a): -20 | a = 1 -21 | global a - | ^ -22 | -23 | def f(a): - | - -invalid-syntax: name `a` is parameter and global - --> :26:12 - | -24 | a = 1 -25 | a = 2 -26 | global a - | ^ -27 | -28 | def f(a): - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_walrus_in_return_annotation_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_walrus_in_return_annotation_3.12.snap deleted file mode 100644 index 8993d2acbe..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_walrus_in_return_annotation_3.12.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: named expression cannot be used within a generic definition - --> :2:22 - | -2 | def f[T](x: int) -> (y := 3): return x - | ^^^^^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_from_in_base_class_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_from_in_base_class_3.12.snap deleted file mode 100644 index aa0b77de19..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_from_in_base_class_3.12.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: yield expression cannot be used within a generic definition - --> :2:13 - | -2 | class C[T]((yield from [object])): - | ^^^^^^^^^^^^^^^^^^^ -3 | pass - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_alias_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_alias_3.12.snap deleted file mode 100644 index 5c1135bdb3..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_alias_3.12.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: yield expression cannot be used within a type alias - --> :2:11 - | -2 | type Y = (yield 1) - | ^^^^^^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_param_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_param_3.12.snap deleted file mode 100644 index 97171b88c3..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidExpression_invalid_expression_yield_in_type_param_3.12.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: yield expression cannot be used within a TypeVar bound - --> :2:12 - | -2 | type X[T: (yield 1)] = int - | ^^^^^^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_3.10.snap deleted file mode 100644 index 0e454a7167..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_3.10.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: Starred expression cannot be used here - --> :3:12 - | -2 | def func(): -3 | return *x - | ^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_for_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_for_3.10.snap deleted file mode 100644 index d6ea25739b..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_for_3.10.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: Starred expression cannot be used here - --> :2:5 - | -2 | for *x in range(10): - | ^^ -3 | pass - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_yield_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_yield_3.10.snap deleted file mode 100644 index a471ef94fd..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_InvalidStarExpression_invalid_star_expression_yield_3.10.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: Starred expression cannot be used here - --> :3:11 - | -2 | def func(): -3 | yield *x - | ^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_capture_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_capture_3.10.snap deleted file mode 100644 index 44ce08366d..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_capture_3.10.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: name capture `irrefutable` makes remaining patterns unreachable - --> :3:10 - | -2 | match value: -3 | case irrefutable: - | ^^^^^^^^^^^ -4 | pass -5 | case 1: - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_wildcard_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_wildcard_3.10.snap deleted file mode 100644 index 74006baae1..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_IrrefutableCasePattern_irrefutable_case_pattern_wildcard_3.10.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: wildcard makes remaining patterns unreachable - --> :3:10 - | -2 | match value: -3 | case _: - | ^ -4 | pass -5 | case 1: - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_MultipleCaseAssignment_multiple_case_assignment_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_MultipleCaseAssignment_multiple_case_assignment_3.10.snap deleted file mode 100644 index 64e8b8e863..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_MultipleCaseAssignment_multiple_case_assignment_3.10.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: multiple assignments to name `a` in pattern - --> :3:14 - | -2 | match x: -3 | case [a, a]: - | ^ -4 | pass -5 | case _: - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_3.10.snap deleted file mode 100644 index 52841dbfab..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_3.10.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: cannot assign to `__debug__` - --> :2:1 - | -2 | __debug__ = False - | ^^^^^^^^^ - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_class_type_param_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_class_type_param_3.12.snap deleted file mode 100644 index 80b922ffa3..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_class_type_param_3.12.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: cannot assign to `__debug__` - --> :2:15 - | -2 | class Generic[__debug__]: - | ^^^^^^^^^ -3 | pass - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_in_function_param_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_in_function_param_3.10.snap deleted file mode 100644 index 0c0b86534c..0000000000 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_WriteToDebug_write_to_debug_in_function_param_3.10.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/ruff_linter/src/linter.rs ---- -invalid-syntax: cannot assign to `__debug__` - --> :2:13 - | -2 | def process(__debug__): - | ^^^^^^^^^ -3 | pass - | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_error_on_310_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_async_comprehension_outside_async_function.py_3.10.snap similarity index 63% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_error_on_310_3.10.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_async_comprehension_outside_async_function.py_3.10.snap index 24eeb50a9a..08822c21f2 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_error_on_310_3.10.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_async_comprehension_outside_async_function.py_3.10.snap @@ -2,8 +2,10 @@ source: crates/ruff_linter/src/linter.rs --- invalid-syntax: cannot use an asynchronous comprehension inside of a synchronous comprehension on Python 3.10 (syntax was added in 3.11) - --> :1:27 + --> resources/test/fixtures/semantic_errors/async_comprehension_outside_async_function.py:1:27 | 1 | async def f(): return [[x async for x in foo(n)] for n in range(3)] | ^^^^^^^^^^^^^^^^^^^^^ +2 | +3 | async def test(): return [[x async for x in elements(n)] async for n in range(3)] | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_false_positive_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_async_comprehension_outside_async_function.py_3.11.snap similarity index 100% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_AsyncComprehensionOutsideAsyncFunction_async_in_sync_false_positive_3.10.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_async_comprehension_outside_async_function.py_3.11.snap diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_class_attribute.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_class_attribute.py_3.10.snap new file mode 100644 index 0000000000..f384495839 --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_class_attribute.py_3.10.snap @@ -0,0 +1,11 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: attribute name `x` repeated in class pattern + --> resources/test/fixtures/semantic_errors/duplicate_match_class_attribute.py:2:21 + | +1 | match x: +2 | case Point(x=1, x=2): + | ^ +3 | pass + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchKey_duplicate_match_key_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_key.py_3.10.snap similarity index 51% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchKey_duplicate_match_key_3.10.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_key.py_3.10.snap index 5f4a0040a8..9ab24be2ea 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateMatchKey_duplicate_match_key_3.10.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_match_key.py_3.10.snap @@ -2,10 +2,10 @@ source: crates/ruff_linter/src/linter.rs --- invalid-syntax: mapping pattern checks duplicate key `'key'` - --> :3:21 + --> resources/test/fixtures/semantic_errors/duplicate_match_key.py:2:21 | -2 | match x: -3 | case {'key': 1, 'key': 2}: +1 | match x: +2 | case {'key': 1, 'key': 2}: | ^^^^^ -4 | pass +3 | pass | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateTypeParameter_duplicate_type_param_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_type_parameter.py_3.12.snap similarity index 64% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateTypeParameter_duplicate_type_param_3.12.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_type_parameter.py_3.12.snap index bfd85698f6..9b3d052471 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_DuplicateTypeParameter_duplicate_type_param_3.12.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_duplicate_type_parameter.py_3.12.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/linter.rs --- invalid-syntax: duplicate type parameter - --> :1:12 + --> resources/test/fixtures/semantic_errors/duplicate_type_parameter.py:1:12 | 1 | class C[T, T]: pass | ^ diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_global_parameter.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_global_parameter.py_3.10.snap new file mode 100644 index 0000000000..e183fb0e88 --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_global_parameter.py_3.10.snap @@ -0,0 +1,56 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: name `a` is parameter and global + --> resources/test/fixtures/semantic_errors/global_parameter.py:2:12 + | +1 | def f(a): +2 | global a + | ^ +3 | +4 | def g(a): + | + +invalid-syntax: name `a` is parameter and global + --> resources/test/fixtures/semantic_errors/global_parameter.py:6:16 + | +4 | def g(a): +5 | if True: +6 | global a + | ^ +7 | +8 | def h(a): + | + +invalid-syntax: name `a` is parameter and global + --> resources/test/fixtures/semantic_errors/global_parameter.py:14:16 + | +12 | def i(a): +13 | try: +14 | global a + | ^ +15 | except Exception: +16 | pass + | + +invalid-syntax: name `a` is parameter and global + --> resources/test/fixtures/semantic_errors/global_parameter.py:20:12 + | +18 | def f(a): +19 | a = 1 +20 | global a + | ^ +21 | +22 | def f(a): + | + +invalid-syntax: name `a` is parameter and global + --> resources/test/fixtures/semantic_errors/global_parameter.py:25:12 + | +23 | a = 1 +24 | a = 2 +25 | global a + | ^ +26 | +27 | def f(a): + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_expression.py_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_expression.py_3.12.snap new file mode 100644 index 0000000000..a33a0c9ce9 --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_expression.py_3.12.snap @@ -0,0 +1,43 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: yield expression cannot be used within a TypeVar bound + --> resources/test/fixtures/semantic_errors/invalid_expression.py:1:12 + | +1 | type X[T: (yield 1)] = int + | ^^^^^^^ +2 | +3 | type Y = (yield 1) + | + +invalid-syntax: yield expression cannot be used within a type alias + --> resources/test/fixtures/semantic_errors/invalid_expression.py:3:11 + | +1 | type X[T: (yield 1)] = int +2 | +3 | type Y = (yield 1) + | ^^^^^^^ +4 | +5 | def f[T](x: int) -> (y := 3): return x + | + +invalid-syntax: named expression cannot be used within a generic definition + --> resources/test/fixtures/semantic_errors/invalid_expression.py:5:22 + | +3 | type Y = (yield 1) +4 | +5 | def f[T](x: int) -> (y := 3): return x + | ^^^^^^ +6 | +7 | class C[T]((yield from [object])): + | + +invalid-syntax: yield expression cannot be used within a generic definition + --> resources/test/fixtures/semantic_errors/invalid_expression.py:7:13 + | +5 | def f[T](x: int) -> (y := 3): return x +6 | +7 | class C[T]((yield from [object])): + | ^^^^^^^^^^^^^^^^^^^ +8 | pass + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_star_expression.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_star_expression.py_3.10.snap new file mode 100644 index 0000000000..f26a2d73a7 --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_invalid_star_expression.py_3.10.snap @@ -0,0 +1,30 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: Starred expression cannot be used here + --> resources/test/fixtures/semantic_errors/invalid_star_expression.py:2:12 + | +1 | def func(): +2 | return *x + | ^^ +3 | +4 | for *x in range(10): + | + +invalid-syntax: Starred expression cannot be used here + --> resources/test/fixtures/semantic_errors/invalid_star_expression.py:4:5 + | +2 | return *x +3 | +4 | for *x in range(10): + | ^^ +5 | pass + | + +invalid-syntax: Starred expression cannot be used here + --> resources/test/fixtures/semantic_errors/invalid_star_expression.py:8:11 + | +7 | def func(): +8 | yield *x + | ^^ + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_irrefutable_case_pattern.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_irrefutable_case_pattern.py_3.10.snap new file mode 100644 index 0000000000..afeb965ebb --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_irrefutable_case_pattern.py_3.10.snap @@ -0,0 +1,22 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: wildcard makes remaining patterns unreachable + --> resources/test/fixtures/semantic_errors/irrefutable_case_pattern.py:2:10 + | +1 | match value: +2 | case _: + | ^ +3 | pass +4 | case 1: + | + +invalid-syntax: name capture `irrefutable` makes remaining patterns unreachable + --> resources/test/fixtures/semantic_errors/irrefutable_case_pattern.py:8:10 + | + 7 | match value: + 8 | case irrefutable: + | ^^^^^^^^^^^ + 9 | pass +10 | case 1: + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_multiple_case_assignment.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_multiple_case_assignment.py_3.10.snap new file mode 100644 index 0000000000..2d88f93cad --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_multiple_case_assignment.py_3.10.snap @@ -0,0 +1,12 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: multiple assignments to name `a` in pattern + --> resources/test/fixtures/semantic_errors/multiple_case_assignment.py:2:14 + | +1 | match x: +2 | case [a, a]: + | ^ +3 | pass +4 | case _: + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_ReboundComprehensionVariable_rebound_comprehension_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_rebound_comprehension.py_3.10.snap similarity index 69% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_ReboundComprehensionVariable_rebound_comprehension_3.10.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_rebound_comprehension.py_3.10.snap index 5f7b81b610..e08f2e9e17 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_ReboundComprehensionVariable_rebound_comprehension_3.10.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_rebound_comprehension.py_3.10.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/linter.rs --- invalid-syntax: assignment expression cannot rebind comprehension variable - --> :1:2 + --> resources/test/fixtures/semantic_errors/rebound_comprehension.py:1:2 | 1 | [x:= 2 for x in range(2)] | ^ diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_SingleStarredAssignment_single_starred_assignment_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_single_starred_assignment.py_3.10.snap similarity index 66% rename from crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_SingleStarredAssignment_single_starred_assignment_3.10.snap rename to crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_single_starred_assignment.py_3.10.snap index e4955a4574..7c3cc3916b 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_SingleStarredAssignment_single_starred_assignment_3.10.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_single_starred_assignment.py_3.10.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/linter.rs --- invalid-syntax: starred assignment target must be in a list or tuple - --> :1:1 + --> resources/test/fixtures/semantic_errors/single_starred_assignment.py:1:1 | 1 | *a = [1, 2, 3, 4] | ^^ diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.10.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.10.snap new file mode 100644 index 0000000000..798c6b21ae --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.10.snap @@ -0,0 +1,41 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:1:1 + | +1 | __debug__ = False + | ^^^^^^^^^ +2 | +3 | def process(__debug__): + | + +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:3:13 + | +1 | __debug__ = False +2 | +3 | def process(__debug__): + | ^^^^^^^^^ +4 | pass + | + +invalid-syntax: Cannot use type parameter lists on Python 3.10 (syntax was added in Python 3.12) + --> resources/test/fixtures/semantic_errors/write_to_debug.py:6:14 + | +4 | pass +5 | +6 | class Generic[__debug__]: + | ^^^^^^^^^^^ +7 | pass + | + +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:6:15 + | +4 | pass +5 | +6 | class Generic[__debug__]: + | ^^^^^^^^^ +7 | pass + | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.12.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.12.snap new file mode 100644 index 0000000000..5e5e7f789a --- /dev/null +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__semantic_syntax_error_write_to_debug.py_3.12.snap @@ -0,0 +1,31 @@ +--- +source: crates/ruff_linter/src/linter.rs +--- +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:1:1 + | +1 | __debug__ = False + | ^^^^^^^^^ +2 | +3 | def process(__debug__): + | + +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:3:13 + | +1 | __debug__ = False +2 | +3 | def process(__debug__): + | ^^^^^^^^^ +4 | pass + | + +invalid-syntax: cannot assign to `__debug__` + --> resources/test/fixtures/semantic_errors/write_to_debug.py:6:15 + | +4 | pass +5 | +6 | class Generic[__debug__]: + | ^^^^^^^^^ +7 | pass + |