From 678f8732e479c7f04787e5e3efc9e88be94e898c Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sun, 21 Jul 2024 18:47:02 +0200 Subject: [PATCH] Reuse Arena in lexer --- crates/ruff_benchmark/benches/lexer.rs | 4 +- crates/ruff_python_ast/src/comparable.rs | 16 +- crates/ruff_python_ast/src/expression.rs | 8 +- crates/ruff_python_ast/src/int.rs | 58 +- crates/ruff_python_ast/src/node.rs | 15 +- crates/ruff_python_ast/src/nodes.rs | 16 +- crates/ruff_python_parser/src/lexer.rs | 443 +- .../src/parser/expression.rs | 12 +- crates/ruff_python_parser/src/parser/mod.rs | 14 +- ...er__tests__expr_mode_valid_syntax.snap.new | 12 - ...r__tests__ipython_escape_commands.snap.new | 400 - ...r__parser__tests__unicode_aliases.snap.new | 39 - .../src/parser/statement.rs | 6 +- ...__dont_panic_on_8_in_octal_escape.snap.new | 39 - ...ng__tests__fstring_constant_range.snap.new | 81 - ..._tests__fstring_escaped_character.snap.new | 54 - ...g__tests__fstring_escaped_newline.snap.new | 54 - ..._tests__fstring_line_continuation.snap.new | 56 - ...tring_parse_self_documenting_base.snap.new | 53 - ..._parse_self_documenting_base_more.snap.new | 85 - ...ing_parse_self_documenting_format.snap.new | 65 - ..._tests__fstring_unescaped_newline.snap.new | 54 - ...ser__string__tests__parse_fstring.snap.new | 69 - ..._nested_concatenation_string_spec.snap.new | 94 - ..._tests__parse_fstring_nested_spec.snap.new | 69 - ..._parse_fstring_nested_string_spec.snap.new | 80 - ...ts__parse_fstring_not_nested_spec.snap.new | 60 - ...parse_fstring_self_doc_prec_space.snap.new | 53 - ...e_fstring_self_doc_trailing_space.snap.new | 53 - ...arser__string__tests__raw_fstring.snap.new | 50 - ..._tests__triple_quoted_raw_fstring.snap.new | 50 - crates/ruff_python_parser/src/token.rs | 13 +- crates/ruff_python_parser/src/token_source.rs | 28 +- ...assign_stmt_invalid_annotation.py.snap.new | 201 - ...ann_assign_stmt_invalid_target.py.snap.new | 509 -- ...@ann_assign_stmt_invalid_value.py.snap.new | 223 - ...ax@ann_assign_stmt_missing_rhs.py.snap.new | 43 - ...ign_stmt_type_alias_annotation.py.snap.new | 111 - ...nvalid_syntax@assert_empty_msg.py.snap.new | 35 - ...valid_syntax@assert_empty_test.py.snap.new | 35 - ...syntax@assert_invalid_msg_expr.py.snap.new | 161 - ...yntax@assert_invalid_test_expr.py.snap.new | 149 - ...tax@assign_stmt_invalid_target.py.snap.new | 259 - ...assign_stmt_invalid_value_expr.py.snap.new | 257 - ...tax@assign_stmt_keyword_target.py.snap.new | 146 - ...syntax@assign_stmt_missing_rhs.py.snap.new | 203 - ..._syntax@async_unexpected_token.py.snap.new | 203 - ...aug_assign_stmt_invalid_target.py.snap.new | 233 - ...@aug_assign_stmt_invalid_value.py.snap.new | 252 - ...ax@aug_assign_stmt_missing_rhs.py.snap.new | 137 - ...tax@case_expect_indented_block.py.snap.new | 85 - ...id_syntax@class_def_empty_body.py.snap.new | 86 - ..._syntax@class_def_missing_name.py.snap.new | 141 - ...s_def_unclosed_type_param_list.py.snap.new | 113 - ...@comma_separated_missing_comma.py.snap.new | 71 - ...eparated_missing_first_element.py.snap.new | 53 - ...ension_missing_for_after_async.py.snap.new | 81 - ...x@decorator_invalid_expression.py.snap.new | 176 - ...x@decorator_missing_expression.py.snap.new | 190 - ...ntax@decorator_missing_newline.py.snap.new | 163 - ...tax@decorator_unexpected_token.py.snap.new | 86 - ...d_syntax@del_incomplete_target.py.snap.new | 125 - ...ntax@dotted_name_multiple_dots.py.snap.new | 89 - ...except_stmt_invalid_expression.py.snap.new | 126 - ...ax@except_stmt_missing_as_name.py.snap.new | 96 - ...@except_stmt_missing_exception.py.snap.new | 156 - ...ept_stmt_unparenthesized_tuple.py.snap.new | 251 - ...ons__arguments__double_starred.py.snap.new | 222 - ...s__duplicate_keyword_arguments.py.snap.new | 136 - ..._arguments__invalid_expression.py.snap.new | 200 - ...ts__invalid_keyword_expression.py.snap.new | 230 - ...ions__arguments__invalid_order.py.snap.new | 305 - ...s__arguments__missing_argument.py.snap.new | 59 - ...ions__arguments__missing_comma.py.snap.new | 59 - ..._arguments__missing_expression.py.snap.new | 167 - ...xpressions__arguments__starred.py.snap.new | 187 - ...essions__arguments__unclosed_0.py.snap.new | 75 - ...essions__arguments__unclosed_1.py.snap.new | 83 - ...essions__arguments__unclosed_2.py.snap.new | 83 - ...ons__attribute__invalid_member.py.snap.new | 147 - ...ions__attribute__multiple_dots.py.snap.new | 154 - ...ressions__attribute__no_member.py.snap.new | 89 - ...ssions__await__no_expression_0.py.snap.new | 67 - ...ssions__await__no_expression_1.py.snap.new | 71 - ...ax@expressions__await__recover.py.snap.new | 328 - ...bin_op__invalid_rhs_expression.py.snap.new | 117 - ...pressions__bin_op__missing_lhs.py.snap.new | 63 - ...essions__bin_op__missing_rhs_0.py.snap.new | 77 - ...essions__bin_op__missing_rhs_1.py.snap.new | 105 - ...ressions__bin_op__multiple_ops.py.snap.new | 150 - ...ions__bin_op__named_expression.py.snap.new | 123 - ...ns__bin_op__starred_expression.py.snap.new | 92 - ...ool_op__invalid_rhs_expression.py.snap.new | 121 - ...ressions__bool_op__missing_lhs.py.snap.new | 34 - ...ressions__bool_op__missing_rhs.py.snap.new | 78 - ...ons__bool_op__named_expression.py.snap.new | 108 - ...s__bool_op__starred_expression.py.snap.new | 96 - ...ssions__compare__invalid_order.py.snap.new | 169 - ...ompare__invalid_rhs_expression.py.snap.new | 125 - ...ressions__compare__missing_lhs.py.snap.new | 63 - ...ssions__compare__missing_rhs_0.py.snap.new | 80 - ...ssions__compare__missing_rhs_1.py.snap.new | 91 - ...ssions__compare__missing_rhs_2.py.snap.new | 80 - ...ions__compare__multiple_equals.py.snap.new | 124 - ...ons__compare__named_expression.py.snap.new | 131 - ...s__compare__starred_expression.py.snap.new | 188 - ...pressions__dict__comprehension.py.snap.new | 828 -- ...expressions__dict__double_star.py.snap.new | 576 -- ...ict__double_star_comprehension.py.snap.new | 159 - ..._dict__missing_closing_brace_0.py.snap.new | 106 - ..._dict__missing_closing_brace_1.py.snap.new | 69 - ..._dict__missing_closing_brace_2.py.snap.new | 84 - ...ions__dict__named_expression_0.py.snap.new | 141 - ...ions__dict__named_expression_1.py.snap.new | 167 - ...tax@expressions__dict__recover.py.snap.new | 518 -- ...expressions__emoji_identifiers.py.snap.new | 139 - ...ons__if__missing_orelse_expr_0.py.snap.new | 85 - ...ons__if__missing_orelse_expr_1.py.snap.new | 83 - ...sions__if__missing_test_expr_0.py.snap.new | 85 - ...sions__if__missing_test_expr_1.py.snap.new | 83 - ...yntax@expressions__if__recover.py.snap.new | 361 - ...ons__lambda_default_parameters.py.snap.new | 96 - ...s__lambda_duplicate_parameters.py.snap.new | 339 - ...pressions__list__comprehension.py.snap.new | 797 -- ...ist__missing_closing_bracket_0.py.snap.new | 44 - ...ist__missing_closing_bracket_1.py.snap.new | 57 - ...ist__missing_closing_bracket_2.py.snap.new | 65 - ...ist__missing_closing_bracket_3.py.snap.new | 84 - ...tax@expressions__list__recover.py.snap.new | 315 - ...st__star_expression_precedence.py.snap.new | 468 - ...essions__named__invalid_target.py.snap.new | 212 - ...s__named__missing_expression_0.py.snap.new | 44 - ...s__named__missing_expression_1.py.snap.new | 48 - ...s__named__missing_expression_2.py.snap.new | 103 - ...s__named__missing_expression_3.py.snap.new | 61 - ...s__named__missing_expression_4.py.snap.new | 75 - ...ions__parenthesized__generator.py.snap.new | 145 - ...sized__missing_closing_paren_0.py.snap.new | 36 - ...sized__missing_closing_paren_1.py.snap.new | 49 - ...sized__missing_closing_paren_2.py.snap.new | 66 - ...sized__missing_closing_paren_3.py.snap.new | 85 - ...__parenthesized__parenthesized.py.snap.new | 75 - ...ressions__parenthesized__tuple.py.snap.new | 391 - ...enthesized__tuple_starred_expr.py.snap.new | 1381 --- ...xpressions__set__comprehension.py.snap.new | 797 -- ..._missing_closing_curly_brace_0.py.snap.new | 43 - ..._missing_closing_curly_brace_1.py.snap.new | 56 - ..._missing_closing_curly_brace_2.py.snap.new | 64 - ..._missing_closing_curly_brace_3.py.snap.new | 83 - ...ntax@expressions__set__recover.py.snap.new | 303 - ...et__star_expression_precedence.py.snap.new | 460 - ...bscript__invalid_slice_element.py.snap.new | 304 - ...s__subscript__unclosed_slice_0.py.snap.new | 71 - ...s__subscript__unclosed_slice_1.py.snap.new | 113 - ...alid_syntax@expressions__unary.py.snap.new | 53 - ...sions__unary__named_expression.py.snap.new | 92 - ...ssions__unary__no_expression_0.py.snap.new | 67 - ...ssions__unary__no_expression_1.py.snap.new | 67 - ...sions__yield__named_expression.py.snap.new | 117 - ...ssions__yield__star_expression.py.snap.new | 114 - ...yield_from__starred_expression.py.snap.new | 94 - ...s__yield_from__unparenthesized.py.snap.new | 159 - ...ntax@f_string_empty_expression.py.snap.new | 112 - ...valid_conversion_flag_name_tok.py.snap.new | 63 - ...alid_conversion_flag_other_tok.py.snap.new | 112 - ...@f_string_invalid_starred_expr.py.snap.new | 205 - ...ing_lambda_without_parentheses.py.snap.new | 115 - ...yntax@f_string_unclosed_lbrace.py.snap.new | 351 - ...unclosed_lbrace_in_format_spec.py.snap.new | 141 - ...tax@for_stmt_invalid_iter_expr.py.snap.new | 184 - ...syntax@for_stmt_invalid_target.py.snap.new | 464 - ...tmt_invalid_target_binary_expr.py.snap.new | 342 - ...stmt_invalid_target_in_keyword.py.snap.new | 443 - ...ax@for_stmt_missing_in_keyword.py.snap.new | 96 - ...d_syntax@for_stmt_missing_iter.py.snap.new | 68 - ...syntax@for_stmt_missing_target.py.snap.new | 61 - ...yntax@from_import_dotted_names.py.snap.new | 170 - ...syntax@from_import_empty_names.py.snap.new | 95 - ...tax@from_import_missing_module.py.snap.new | 55 - ...yntax@from_import_missing_rpar.py.snap.new | 148 - ...m_import_star_with_other_names.py.snap.new | 191 - ...unparenthesized_trailing_comma.py.snap.new | 119 - ...syntax@function_def_empty_body.py.snap.new | 106 - ...nction_def_invalid_return_expr.py.snap.new | 182 - ...unction_def_missing_identifier.py.snap.new | 104 - ...nction_def_missing_return_type.py.snap.new | 55 - ...on_def_unclosed_parameter_list.py.snap.new | 234 - ...n_def_unclosed_type_param_list.py.snap.new | 148 - ...f_unparenthesized_return_types.py.snap.new | 137 - ..._syntax@global_stmt_expression.py.snap.new | 52 - ...tax@global_stmt_trailing_comma.py.snap.new | 80 - ...tax@if_stmt_elif_missing_colon.py.snap.new | 78 - ...if_stmt_invalid_elif_test_expr.py.snap.new | 107 - ...ntax@if_stmt_invalid_test_expr.py.snap.new | 133 - ...d_syntax@if_stmt_missing_colon.py.snap.new | 99 - ...id_syntax@if_stmt_missing_test.py.snap.new | 47 - ...syntax@if_stmt_misspelled_elif.py.snap.new | 128 - ...ncatenated_unterminated_string.py.snap.new | 179 - ..._unterminated_string_multiline.py.snap.new | 244 - ...ax@import_alias_missing_asname.py.snap.new | 37 - ...mport_stmt_parenthesized_names.py.snap.new | 82 - ...syntax@import_stmt_star_import.py.snap.new | 124 - ...tax@import_stmt_trailing_comma.py.snap.new | 66 - ...alid_syntax@invalid_del_target.py.snap.new | 270 - ...@lambda_body_with_starred_expr.py.snap.new | 274 - ...ax@lambda_body_with_yield_expr.py.snap.new | 122 - ...ntax@match_classify_as_keyword.py.snap.new | 67 - ...ssify_as_keyword_or_identifier.py.snap.new | 66 - ...tch_stmt_expect_indented_block.py.snap.new | 66 - ...match_stmt_expected_case_block.py.snap.new | 135 - ...@match_stmt_invalid_guard_expr.py.snap.new | 212 - ...atch_stmt_invalid_subject_expr.py.snap.new | 204 - ...@match_stmt_missing_guard_expr.py.snap.new | 65 - ...tax@match_stmt_missing_pattern.py.snap.new | 65 - ...ch_stmt_no_newline_before_case.py.snap.new | 64 - ...ch_stmt_single_starred_subject.py.snap.new | 66 - ...@multiple_clauses_on_same_line.py.snap.new | 389 - ...id_syntax@node_range_with_gaps.py.snap.new | 123 - ...yntax@nonlocal_stmt_expression.py.snap.new | 52 - ...x@nonlocal_stmt_trailing_comma.py.snap.new | 80 - ...yntax@param_missing_annotation.py.snap.new | 122 - ...d_syntax@param_missing_default.py.snap.new | 130 - ...@param_with_invalid_annotation.py.snap.new | 227 - ...tax@param_with_invalid_default.py.snap.new | 221 - ...m_with_invalid_star_annotation.py.snap.new | 311 - ..._syntax@params_duplicate_names.py.snap.new | 164 - ..._expected_after_star_separator.py.snap.new | 260 - ...ams_kwarg_after_star_separator.py.snap.new | 64 - ..._syntax@params_multiple_kwargs.py.snap.new | 77 - ...arams_multiple_slash_separator.py.snap.new | 160 - ...params_multiple_star_separator.py.snap.new | 160 - ...syntax@params_multiple_varargs.py.snap.new | 257 - ...tax@params_no_arg_before_slash.py.snap.new | 109 - ...rams_non_default_after_default.py.snap.new | 115 - ...syntax@params_star_after_slash.py.snap.new | 302 - ...tar_separator_after_star_param.py.snap.new | 178 - ...arams_var_keyword_with_default.py.snap.new | 167 - ...ms_var_positional_with_default.py.snap.new | 125 - ...yntax@raise_stmt_invalid_cause.py.snap.new | 135 - ..._syntax@raise_stmt_invalid_exc.py.snap.new | 111 - ...mt_unparenthesized_tuple_cause.py.snap.new | 101 - ...stmt_unparenthesized_tuple_exc.py.snap.new | 134 - ...id_syntax@re_lex_logical_token.py.snap.new | 839 -- ...x@re_lex_logical_token_mac_eol.py.snap.new | 105 - ..._lex_logical_token_windows_eol.py.snap.new | 108 - ..._lexing__fstring_format_spec_1.py.snap.new | 424 - ...re_lexing__line_continuation_1.py.snap.new | 106 - ..._line_continuation_windows_eol.py.snap.new | 91 - ...exing__triple_quoted_fstring_1.py.snap.new | 97 - ...exing__triple_quoted_fstring_2.py.snap.new | 76 - ...exing__triple_quoted_fstring_3.py.snap.new | 111 - ...yntax@return_stmt_invalid_expr.py.snap.new | 183 - ...and_compound_stmt_on_same_line.py.snap.new | 66 - ...ntax@simple_stmts_on_same_line.py.snap.new | 147 - ...ents__function_type_parameters.py.snap.new | 404 - ...ax@statements__if_extra_indent.py.snap.new | 105 - ...ts__invalid_assignment_targets.py.snap.new | 1693 ---- ...id_augmented_assignment_target.py.snap.new | 1558 ---- ...tatements__match__as_pattern_0.py.snap.new | 93 - ...tatements__match__as_pattern_1.py.snap.new | 78 - ...tatements__match__as_pattern_2.py.snap.new | 127 - ...tatements__match__as_pattern_3.py.snap.new | 155 - ...tatements__match__as_pattern_4.py.snap.new | 117 - ...__match__invalid_class_pattern.py.snap.new | 384 - ...ch__invalid_lhs_or_rhs_pattern.py.snap.new | 1101 --- ...match__invalid_mapping_pattern.py.snap.new | 581 -- ...nts__match__star_pattern_usage.py.snap.new | 547 -- ...ements__match__unary_add_usage.py.snap.new | 399 - ...ith__ambiguous_lpar_with_items.py.snap.new | 1675 ---- ...ements__with__empty_with_items.py.snap.new | 70 - ..._with__unclosed_ambiguous_lpar.py.snap.new | 78 - ...h__unclosed_ambiguous_lpar_eof.py.snap.new | 42 - ...th__unparenthesized_with_items.py.snap.new | 362 - ...tax@try_stmt_misspelled_except.py.snap.new | 273 - ...tax@type_alias_incomplete_stmt.py.snap.new | 88 - ...@type_alias_invalid_value_expr.py.snap.new | 161 - ...@type_param_invalid_bound_expr.py.snap.new | 259 - ...yntax@type_param_missing_bound.py.snap.new | 115 - ...ax@type_param_param_spec_bound.py.snap.new | 94 - ...aram_spec_invalid_default_expr.py.snap.new | 315 - ...ram_param_spec_missing_default.py.snap.new | 113 - ..._type_var_invalid_default_expr.py.snap.new | 380 - ...param_type_var_missing_default.py.snap.new | 170 - ...ype_param_type_var_tuple_bound.py.snap.new | 94 - ...var_tuple_invalid_default_expr.py.snap.new | 322 - ...type_var_tuple_missing_default.py.snap.new | 113 - ...valid_syntax@type_params_empty.py.snap.new | 103 - ...nated_fstring_newline_recovery.py.snap.new | 361 - ...x@while_stmt_invalid_test_expr.py.snap.new | 192 - ...yntax@while_stmt_missing_colon.py.snap.new | 63 - ...syntax@while_stmt_missing_test.py.snap.new | 94 - ...ms_parenthesized_missing_colon.py.snap.new | 61 - ...ms_parenthesized_missing_comma.py.snap.new | 335 - ...us_lpar_with_items_binary_expr.py.snap.new | 373 - ...iguous_lpar_with_items_if_expr.py.snap.new | 280 - ...@ann_assign_stmt_simple_target.py.snap.new | 124 - ...ntax@assign_targets_terminator.py.snap.new | 144 - ...lid_syntax@async_for_statement.py.snap.new | 49 - ...ntax@async_function_definition.py.snap.new | 49 - ...id_syntax@async_with_statement.py.snap.new | 47 - ...lid_syntax@class_def_arguments.py.snap.new | 70 - ...yntax@decorator_async_function.py.snap.new | 60 - ..._syntax@del_targets_terminator.py.snap.new | 114 - ...@dotted_name_normalized_spaces.py.snap.new | 46 - ...cept_stmt_as_name_soft_keyword.py.snap.new | 134 - ..._syntax@expressions__arguments.py.snap.new | 1726 ---- ..._syntax@expressions__attribute.py.snap.new | 228 - ...alid_syntax@expressions__await.py.snap.new | 513 -- ...lid_syntax@expressions__bin_op.py.snap.new | 1047 --- ...id_syntax@expressions__bool_op.py.snap.new | 403 - ...valid_syntax@expressions__call.py.snap.new | 590 -- ...id_syntax@expressions__compare.py.snap.new | 698 -- ...syntax@expressions__dictionary.py.snap.new | 1231 --- ...ions__dictionary_comprehension.py.snap.new | 1000 --- ...d_syntax@expressions__f_string.py.snap.new | 2703 ------ ..._syntax@expressions__generator.py.snap.new | 698 -- .../valid_syntax@expressions__if.py.snap.new | 614 -- ...lid_syntax@expressions__lambda.py.snap.new | 1522 ---- ...valid_syntax@expressions__list.py.snap.new | 811 -- ...xpressions__list_comprehension.py.snap.new | 1291 --- ...valid_syntax@expressions__name.py.snap.new | 124 - ...alid_syntax@expressions__named.py.snap.new | 317 - ...ax@expressions__number_literal.py.snap.new | 1029 --- ...tax@expressions__parenthesized.py.snap.new | 235 - .../valid_syntax@expressions__set.py.snap.new | 621 -- ...expressions__set_comprehension.py.snap.new | 742 -- ...alid_syntax@expressions__slice.py.snap.new | 656 -- ...id_syntax@expressions__starred.py.snap.new | 355 - ..._syntax@expressions__subscript.py.snap.new | 784 -- ...alid_syntax@expressions__tuple.py.snap.new | 707 -- ...d_syntax@expressions__unary_op.py.snap.new | 507 -- ...alid_syntax@expressions__yield.py.snap.new | 527 -- ...syntax@expressions__yield_from.py.snap.new | 375 - ...yntax@for_in_target_valid_expr.py.snap.new | 203 - ...id_syntax@from_import_no_space.py.snap.new | 50 - ...mport_soft_keyword_module_name.py.snap.new | 104 - ...ax@from_import_stmt_terminator.py.snap.new | 220 - ...fstring_format_spec_terminator.py.snap.new | 139 - ...x@function_def_parameter_range.py.snap.new | 98 - ...def_parenthesized_return_types.py.snap.new | 123 - ...function_def_valid_return_expr.py.snap.new | 246 - .../valid_syntax@global_stmt.py.snap.new | 46 - ...ax@import_as_name_soft_keyword.py.snap.new | 76 - ..._syntax@import_stmt_terminator.py.snap.new | 113 - ..._syntax@lambda_with_valid_body.py.snap.new | 349 - .../valid_syntax@match_as_pattern.py.snap.new | 81 - ...@match_as_pattern_soft_keyword.py.snap.new | 114 - ...atch_attr_pattern_soft_keyword.py.snap.new | 232 - ...match_classify_as_identifier_1.py.snap.new | 45 - ...match_classify_as_identifier_2.py.snap.new | 320 - ...ax@match_classify_as_keyword_1.py.snap.new | 579 -- ...ax@match_classify_as_keyword_2.py.snap.new | 234 - ...ssify_as_keyword_or_identifier.py.snap.new | 292 - ...pattern_parentheses_terminator.py.snap.new | 124 - ...ch_sequence_pattern_terminator.py.snap.new | 196 - ...syntax@match_stmt_subject_expr.py.snap.new | 230 - ...ax@match_stmt_valid_guard_expr.py.snap.new | 282 - .../valid_syntax@nonlocal_stmt.py.snap.new | 46 - .../valid_syntax@other__decorator.py.snap.new | 671 -- ...d_syntax@param_with_annotation.py.snap.new | 279 - ...alid_syntax@param_with_default.py.snap.new | 292 - ...tax@param_with_star_annotation.py.snap.new | 156 - ...@params_non_default_after_star.py.snap.new | 227 - ..._keyword_only_param_after_star.py.snap.new | 135 - ...d_syntax@simple_stmts_in_block.py.snap.new | 124 - ...x@simple_stmts_with_semicolons.py.snap.new | 91 - ...ent__ambiguous_lpar_with_items.py.snap.new | 4032 --------- ...tatement__annotated_assignment.py.snap.new | 274 - ...valid_syntax@statement__assert.py.snap.new | 335 - ...d_syntax@statement__assignment.py.snap.new | 955 -- ...tatement__augmented_assignment.py.snap.new | 485 -- .../valid_syntax@statement__class.py.snap.new | 1243 --- ...valid_syntax@statement__delete.py.snap.new | 300 - .../valid_syntax@statement__for.py.snap.new | 834 -- ..._syntax@statement__from_import.py.snap.new | 238 - ...lid_syntax@statement__function.py.snap.new | 3242 ------- .../valid_syntax@statement__if.py.snap.new | 674 -- ...valid_syntax@statement__import.py.snap.new | 130 - .../valid_syntax@statement__match.py.snap.new | 7717 ----------------- .../valid_syntax@statement__raise.py.snap.new | 491 -- ...valid_syntax@statement__return.py.snap.new | 383 - ...valid_syntax@statement__simple.py.snap.new | 249 - .../valid_syntax@statement__try.py.snap.new | 1562 ---- .../valid_syntax@statement__type.py.snap.new | 2752 ------ .../valid_syntax@statement__while.py.snap.new | 462 - .../valid_syntax@statement__with.py.snap.new | 400 - ...d_syntax@type_param_param_spec.py.snap.new | 198 - ...lid_syntax@type_param_type_var.py.snap.new | 316 - ...ntax@type_param_type_var_tuple.py.snap.new | 248 - 389 files changed, 383 insertions(+), 108635 deletions(-) delete mode 100644 crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap.new delete mode 100644 crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap.new delete mode 100644 crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap.new delete mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap.new delete mode 100644 crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap.new diff --git a/crates/ruff_benchmark/benches/lexer.rs b/crates/ruff_benchmark/benches/lexer.rs index 6e8488a552..7fd280e65a 100644 --- a/crates/ruff_benchmark/benches/lexer.rs +++ b/crates/ruff_benchmark/benches/lexer.rs @@ -2,6 +2,7 @@ use codspeed_criterion_compat::{ criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput, }; +use ruff_allocator::Allocator; use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError}; use ruff_python_parser::{lexer, Mode, TokenKind}; @@ -48,7 +49,8 @@ fn benchmark_lexer(criterion: &mut Criterion) { &case, |b, case| { b.iter(|| { - let mut lexer = lexer::lex(case.code(), Mode::Module); + let allocator = Allocator::new(); + let mut lexer = lexer::lex(case.code(), Mode::Module, &allocator); loop { let token = lexer.next_token(); match token { diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index ef9feb9f51..5dd5d07ada 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -346,14 +346,14 @@ impl From<&ast::Singleton> for ComparableSingleton { } #[derive(Debug, PartialEq, Eq, Hash)] -pub enum ComparableNumber<'a> { - Int(&'a ast::Int), +pub enum ComparableNumber<'a, 'ast> { + Int(&'a ast::Int<'ast>), Float(u64), Complex { real: u64, imag: u64 }, } -impl<'a, 'ast> From<&'a ast::Number> for ComparableNumber<'a> { - fn from(number: &'a ast::Number) -> Self { +impl<'a, 'ast> From<&'a ast::Number<'ast>> for ComparableNumber<'a, 'ast> { + fn from(number: &'a ast::Number<'ast>) -> Self { match number { ast::Number::Int(value) => Self::Int(&value), ast::Number::Float(value) => Self::Float(value.to_bits()), @@ -581,7 +581,7 @@ pub enum ComparableLiteral<'a, 'ast> { Bool(bool), Str(Vec>), Bytes(Vec>), - Number(ComparableNumber<'a>), + Number(ComparableNumber<'a, 'ast>), } impl<'a, 'ast> From> for ComparableLiteral<'a, 'ast> { @@ -799,8 +799,8 @@ pub struct ExprBytesLiteral<'ast> { } #[derive(Debug, PartialEq, Eq, Hash)] -pub struct ExprNumberLiteral<'a> { - value: ComparableNumber<'a>, +pub struct ExprNumberLiteral<'a, 'ast> { + value: ComparableNumber<'a, 'ast>, } #[derive(Debug, PartialEq, Eq, Hash)] @@ -876,7 +876,7 @@ pub enum ComparableExpr<'a, 'ast> { FString(ExprFString<'a, 'ast>), StringLiteral(ExprStringLiteral<'ast>), BytesLiteral(ExprBytesLiteral<'ast>), - NumberLiteral(ExprNumberLiteral<'a>), + NumberLiteral(ExprNumberLiteral<'a, 'ast>), BoolLiteral(ExprBoolLiteral), NoneLiteral, EllipsisLiteral, diff --git a/crates/ruff_python_ast/src/expression.rs b/crates/ruff_python_ast/src/expression.rs index 0d5aacba03..1a86f0d88d 100644 --- a/crates/ruff_python_ast/src/expression.rs +++ b/crates/ruff_python_ast/src/expression.rs @@ -27,7 +27,7 @@ pub enum ExpressionRef<'a, 'ast> { FString(&'a ast::ExprFString<'ast>), StringLiteral(&'a ast::ExprStringLiteral<'ast>), BytesLiteral(&'a ast::ExprBytesLiteral<'ast>), - NumberLiteral(&'a ast::ExprNumberLiteral), + NumberLiteral(&'a ast::ExprNumberLiteral<'ast>), BooleanLiteral(&'a ast::ExprBooleanLiteral), NoneLiteral(&'a ast::ExprNoneLiteral), EllipsisLiteral(&'a ast::ExprEllipsisLiteral), @@ -186,8 +186,8 @@ impl<'a, 'ast> From<&'a ast::ExprBytesLiteral<'ast>> for ExpressionRef<'a, 'ast> Self::BytesLiteral(value) } } -impl<'a> From<&'a ast::ExprNumberLiteral> for ExpressionRef<'a, '_> { - fn from(value: &'a ast::ExprNumberLiteral) -> Self { +impl<'a, 'ast> From<&'a ast::ExprNumberLiteral<'ast>> for ExpressionRef<'a, 'ast> { + fn from(value: &'a ast::ExprNumberLiteral<'ast>) -> Self { Self::NumberLiteral(value) } } @@ -335,7 +335,7 @@ impl Ranged for ExpressionRef<'_, '_> { pub enum LiteralExpressionRef<'a, 'ast> { StringLiteral(&'a ast::ExprStringLiteral<'ast>), BytesLiteral(&'a ast::ExprBytesLiteral<'ast>), - NumberLiteral(&'a ast::ExprNumberLiteral), + NumberLiteral(&'a ast::ExprNumberLiteral<'ast>), BooleanLiteral(&'a ast::ExprBooleanLiteral), NoneLiteral(&'a ast::ExprNoneLiteral), EllipsisLiteral(&'a ast::ExprEllipsisLiteral), diff --git a/crates/ruff_python_ast/src/int.rs b/crates/ruff_python_ast/src/int.rs index 08f3d39119..a71516ed35 100644 --- a/crates/ruff_python_ast/src/int.rs +++ b/crates/ruff_python_ast/src/int.rs @@ -1,15 +1,12 @@ +use ruff_allocator::Allocator; use std::fmt::Debug; -use std::str::FromStr; /// A Python integer literal. Represents both small (fits in an `i64`) and large integers. #[derive(Clone, PartialEq, Eq, Hash)] -pub struct Int(Number); +pub struct Int<'ast>(Number<'ast>); -impl FromStr for Int { - type Err = std::num::ParseIntError; - - /// Parse an [`Int`] from a string. - fn from_str(s: &str) -> Result { +impl<'ast> Int<'ast> { + pub fn from_str(s: &str, allocator: &'ast Allocator) -> Result { match s.parse::() { Ok(value) => Ok(Int::small(value)), Err(err) => { @@ -17,7 +14,7 @@ impl FromStr for Int { err.kind(), std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow ) { - Ok(Int::big(s)) + Ok(Int::big(allocator.alloc_str(s))) } else { Err(err) } @@ -26,9 +23,9 @@ impl FromStr for Int { } } -impl Int { - pub const ZERO: Int = Int(Number::Small(0)); - pub const ONE: Int = Int(Number::Small(1)); +impl<'ast> Int<'ast> { + pub const ZERO: Int<'static> = Int(Number::Small(0)); + pub const ONE: Int<'static> = Int(Number::Small(1)); /// Create an [`Int`] to represent a value that can be represented as an `i64`. fn small(value: u64) -> Self { @@ -36,8 +33,8 @@ impl Int { } /// Create an [`Int`] to represent a value that cannot be represented as an `i64`. - fn big(value: impl Into>) -> Self { - Self(Number::Big(value.into())) + fn big(value: &'ast str) -> Self { + Self(Number::Big(value)) } /// Parse an [`Int`] from a string with a given radix, like `0x95D`. @@ -48,6 +45,7 @@ impl Int { number: &str, radix: u32, token: &str, + allocator: &'ast Allocator, ) -> Result { match u64::from_str_radix(number, radix) { Ok(value) => Ok(Int::small(value)), @@ -56,7 +54,7 @@ impl Int { err.kind(), std::num::IntErrorKind::PosOverflow | std::num::IntErrorKind::NegOverflow ) { - Ok(Int::big(token)) + Ok(Int::big(allocator.alloc_str(token))) } else { Err(err) } @@ -129,93 +127,93 @@ impl Int { } } -impl std::fmt::Display for Int { +impl std::fmt::Display for Int<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } -impl Debug for Int { +impl Debug for Int<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self, f) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &u8) -> bool { self.as_u8() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &u16) -> bool { self.as_u16() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &u32) -> bool { self.as_u32() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &i8) -> bool { self.as_i8() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &i16) -> bool { self.as_i16() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &i32) -> bool { self.as_i32() == Some(*other) } } -impl PartialEq for Int { +impl<'a> PartialEq for Int<'a> { fn eq(&self, other: &i64) -> bool { self.as_i64() == Some(*other) } } -impl From for Int { +impl From for Int<'static> { fn from(value: u8) -> Self { Self::small(u64::from(value)) } } -impl From for Int { +impl From for Int<'static> { fn from(value: u16) -> Self { Self::small(u64::from(value)) } } -impl From for Int { +impl From for Int<'static> { fn from(value: u32) -> Self { Self::small(u64::from(value)) } } -impl From for Int { +impl From for Int<'static> { fn from(value: u64) -> Self { Self::small(value) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -enum Number { +enum Number<'ast> { /// A "small" number that can be represented as an `u64`. Small(u64), /// A "large" number that cannot be represented as an `u64`. - Big(Box), + Big(&'ast str), } -impl std::fmt::Display for Number { +impl std::fmt::Display for Number<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Number::Small(value) => write!(f, "{value}"), diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index c72a5a89c5..0b885eba40 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -85,7 +85,7 @@ pub enum AnyNode<'ast> { ExprFString(ast::ExprFString<'ast>), ExprStringLiteral(ast::ExprStringLiteral<'ast>), ExprBytesLiteral(ast::ExprBytesLiteral<'ast>), - ExprNumberLiteral(ast::ExprNumberLiteral), + ExprNumberLiteral(ast::ExprNumberLiteral<'ast>), ExprBooleanLiteral(ast::ExprBooleanLiteral), ExprNoneLiteral(ast::ExprNoneLiteral), ExprEllipsisLiteral(ast::ExprEllipsisLiteral), @@ -3103,7 +3103,7 @@ impl<'ast> AstNode<'ast> for ast::ExprBytesLiteral<'ast> { } } } -impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral { +impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral<'ast> { type Ref<'a> = &'a Self where 'ast: 'a; fn cast(kind: AnyNode<'ast>) -> Option where @@ -3138,7 +3138,6 @@ impl<'ast> AstNode<'ast> for ast::ExprNumberLiteral { fn visit_source_order<'a, V>(&'a self, _visitor: &mut V) where - 'ast: 'a, V: SourceOrderVisitor<'a, 'ast> + ?Sized, { } @@ -5851,8 +5850,8 @@ impl<'ast> From> for AnyNode<'ast> { } } -impl<'ast> From for AnyNode<'ast> { - fn from(node: ast::ExprNumberLiteral) -> Self { +impl<'ast> From> for AnyNode<'ast> { + fn from(node: ast::ExprNumberLiteral<'ast>) -> Self { AnyNode::ExprNumberLiteral(node) } } @@ -6230,7 +6229,7 @@ pub enum AnyNodeRef<'a, 'ast> { ExprFString(&'a ast::ExprFString<'ast>), ExprStringLiteral(&'a ast::ExprStringLiteral<'ast>), ExprBytesLiteral(&'a ast::ExprBytesLiteral<'ast>), - ExprNumberLiteral(&'a ast::ExprNumberLiteral), + ExprNumberLiteral(&'a ast::ExprNumberLiteral<'ast>), ExprBooleanLiteral(&'a ast::ExprBooleanLiteral), ExprNoneLiteral(&'a ast::ExprNoneLiteral), ExprEllipsisLiteral(&'a ast::ExprEllipsisLiteral), @@ -7548,8 +7547,8 @@ impl<'a, 'ast> From<&'a ast::ExprBytesLiteral<'ast>> for AnyNodeRef<'a, 'ast> { } } -impl<'a, 'ast> From<&'a ast::ExprNumberLiteral> for AnyNodeRef<'a, 'ast> { - fn from(node: &'a ast::ExprNumberLiteral) -> Self { +impl<'a, 'ast> From<&'a ast::ExprNumberLiteral<'ast>> for AnyNodeRef<'a, 'ast> { + fn from(node: &'a ast::ExprNumberLiteral<'ast>) -> Self { AnyNodeRef::ExprNumberLiteral(node) } } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index a0985ddf20..2e5d4ff5f3 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -605,7 +605,7 @@ pub enum Expr<'ast> { #[is(name = "bytes_literal_expr")] BytesLiteral(ExprBytesLiteral<'ast>), #[is(name = "number_literal_expr")] - NumberLiteral(ExprNumberLiteral), + NumberLiteral(ExprNumberLiteral<'ast>), #[is(name = "boolean_literal_expr")] BooleanLiteral(ExprBooleanLiteral), #[is(name = "none_literal_expr")] @@ -2616,26 +2616,26 @@ impl From for AnyStringFlags { } #[derive(Clone, Debug, PartialEq)] -pub struct ExprNumberLiteral { +pub struct ExprNumberLiteral<'ast> { pub range: TextRange, - pub value: Number, + pub value: Number<'ast>, } -impl From for Expr<'_> { - fn from(payload: ExprNumberLiteral) -> Self { +impl<'ast> From> for Expr<'ast> { + fn from(payload: ExprNumberLiteral<'ast>) -> Self { Expr::NumberLiteral(payload) } } -impl Ranged for ExprNumberLiteral { +impl Ranged for ExprNumberLiteral<'_> { fn range(&self) -> TextRange { self.range } } #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Number { - Int(int::Int), +pub enum Number<'ast> { + Int(int::Int<'ast>), Float(f64), Complex { real: f64, imag: f64 }, } diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index d407ab357e..dbbe2acf74 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -9,13 +9,12 @@ use std::cmp::Ordering; use std::str::FromStr; -use unicode_ident::{is_xid_continue, is_xid_start}; -use unicode_normalization::UnicodeNormalization; - -use ruff_python_ast::name::Name; +use ruff_allocator::Allocator; use ruff_python_ast::{Int, IpyEscapeKind, StringFlags}; use ruff_python_trivia::is_python_whitespace; use ruff_text_size::{TextLen, TextRange, TextSize}; +use unicode_ident::{is_xid_continue, is_xid_start}; +use unicode_normalization::UnicodeNormalization; use crate::error::{FStringErrorType, LexicalError, LexicalErrorType}; use crate::lexer::cursor::{Cursor, EOF_CHAR}; @@ -32,10 +31,12 @@ const BOM: char = '\u{feff}'; /// A lexer for Python source code. #[derive(Debug)] -pub struct Lexer<'src> { +pub struct Lexer<'src, 'ast> { /// Source code to be lexed. source: &'src str, + allocator: &'ast Allocator, + /// A pointer to the current character of the source code which is being lexed. cursor: Cursor<'src>, @@ -46,7 +47,7 @@ pub struct Lexer<'src> { current_range: TextRange, /// The value of the current token. - current_value: TokenValue, + current_value: TokenValue<'ast>, /// Flags for the current token. current_flags: TokenFlags, @@ -72,13 +73,18 @@ pub struct Lexer<'src> { errors: Vec, } -impl<'src> Lexer<'src> { +impl<'src, 'ast> Lexer<'src, 'ast> { /// Create a new lexer for the given input source which starts at the given offset. /// /// If the start offset is greater than 0, the cursor is moved ahead that many bytes. /// This means that the input source should be the complete source code and not the /// sliced version. - pub(crate) fn new(source: &'src str, mode: Mode, start_offset: TextSize) -> Self { + pub(crate) fn new( + source: &'src str, + mode: Mode, + start_offset: TextSize, + allocator: &'ast Allocator, + ) -> Self { assert!( u32::try_from(source.len()).is_ok(), "Lexer only supports files with a size up to 4GB" @@ -87,6 +93,7 @@ impl<'src> Lexer<'src> { let mut lexer = Lexer { source, cursor: Cursor::new(source), + allocator, state: State::AfterNewline, current_kind: TokenKind::EndOfFile, current_range: TextRange::empty(start_offset), @@ -130,7 +137,7 @@ impl<'src> Lexer<'src> { /// /// All the subsequent call to this method without moving the lexer would always return the /// default value which is [`TokenValue::None`]. - pub(crate) fn take_value(&mut self) -> TokenValue { + pub(crate) fn take_value(&mut self) -> TokenValue<'ast> { std::mem::take(&mut self.current_value) } @@ -644,7 +651,9 @@ impl<'src> Lexer<'src> { let text = self.token_text(); if !is_ascii { - self.current_value = TokenValue::Name(text.nfkc().collect::()); + let mut name = ruff_allocator::String::new_in(self.allocator); + name.extend(self.allocator.alloc(text.nfkc())); + self.current_value = TokenValue::Name(name.into_bump_str()); return TokenKind::Name; } @@ -688,7 +697,7 @@ impl<'src> Lexer<'src> { "with" => TokenKind::With, "yield" => TokenKind::Yield, _ => { - self.current_value = TokenValue::Name(Name::new(text)); + self.current_value = TokenValue::Name(self.allocator.alloc_str(text)); TokenKind::Name } } @@ -874,13 +883,13 @@ impl<'src> Lexer<'src> { } let value = if normalized.is_empty() { - self.source[range].to_string() + self.allocator.alloc_str(&self.source[range]) } else { normalized.push_str(&self.source[TextRange::new(last_offset, self.offset())]); - normalized + self.allocator.alloc_str(&normalized) }; - self.current_value = TokenValue::FStringMiddle(value.into_boxed_str()); + self.current_value = TokenValue::FStringMiddle(value); self.current_flags = fstring.flags(); Some(TokenKind::FStringMiddle) @@ -994,9 +1003,8 @@ impl<'src> Lexer<'src> { }; self.current_value = TokenValue::String( - self.source[TextRange::new(value_start, value_end)] - .to_string() - .into_boxed_str(), + self.allocator + .alloc_str(&self.source[TextRange::new(value_start, value_end)]), ); TokenKind::String @@ -1032,17 +1040,18 @@ impl<'src> Lexer<'src> { self.radix_run(&mut number, radix); // Extract the entire number, including the base prefix (e.g., `0x9D5`). - let token = &self.source[self.token_range()]; + let token = self.allocator.alloc_str(&self.source[self.token_range()]); - let value = match Int::from_str_radix(number.as_str(), radix.as_u32(), token) { - Ok(int) => int, - Err(err) => { - return self.push_error(LexicalError::new( - LexicalErrorType::OtherError(format!("{err:?}").into_boxed_str()), - self.token_range(), - )); - } - }; + let value = + match Int::from_str_radix(number.as_str(), radix.as_u32(), token, self.allocator) { + Ok(int) => int, + Err(err) => { + return self.push_error(LexicalError::new( + LexicalErrorType::OtherError(format!("{err:?}").into_boxed_str()), + self.token_range(), + )); + } + }; self.current_value = TokenValue::Int(value); TokenKind::Int } @@ -1121,7 +1130,7 @@ impl<'src> Lexer<'src> { self.current_value = TokenValue::Complex { real: 0.0, imag }; TokenKind::Complex } else { - let value = match Int::from_str(number.as_str()) { + let value = match Int::from_str(number.as_str(), self.allocator) { Ok(value) => { if start_is_zero && value.as_u8() != Some(0) { // Leading zeros in decimal integer literals are not permitted. @@ -1277,7 +1286,7 @@ impl<'src> Lexer<'src> { self.current_value = TokenValue::IpyEscapeCommand { kind, - value: value.into_boxed_str(), + value: self.allocator.alloc_str(&value), }; return TokenKind::IpyEscapeCommand; @@ -1285,7 +1294,7 @@ impl<'src> Lexer<'src> { '\n' | '\r' | EOF_CHAR => { self.current_value = TokenValue::IpyEscapeCommand { kind: escape_kind, - value: value.into_boxed_str(), + value: self.allocator.alloc_str(&value), }; return TokenKind::IpyEscapeCommand; @@ -1451,7 +1460,7 @@ impl<'src> Lexer<'src> { } /// Creates a checkpoint to which the lexer can later return to using [`Self::rewind`]. - pub(crate) fn checkpoint(&self) -> LexerCheckpoint { + pub(crate) fn checkpoint(&self) -> LexerCheckpoint<'ast> { LexerCheckpoint { value: self.current_value.clone(), current_kind: self.current_kind, @@ -1468,7 +1477,7 @@ impl<'src> Lexer<'src> { } /// Restore the lexer to the given checkpoint. - pub(crate) fn rewind(&mut self, checkpoint: LexerCheckpoint) { + pub(crate) fn rewind(&mut self, checkpoint: LexerCheckpoint<'ast>) { let LexerCheckpoint { value, current_kind, @@ -1505,8 +1514,8 @@ impl<'src> Lexer<'src> { } } -pub(crate) struct LexerCheckpoint { - value: TokenValue, +pub(crate) struct LexerCheckpoint<'ast> { + value: TokenValue<'ast>, current_kind: TokenKind, current_range: TextRange, current_flags: TokenFlags, @@ -1651,8 +1660,12 @@ impl<'a> LexedText<'a> { } /// Create a new [`Lexer`] for the given source code and [`Mode`]. -pub fn lex(source: &str, mode: Mode) -> Lexer { - Lexer::new(source, mode, TextSize::default()) +pub fn lex<'source, 'ast>( + source: &'source str, + mode: Mode, + allocator: &'ast Allocator, +) -> Lexer<'source, 'ast> { + Lexer::new(source, mode, TextSize::default(), allocator) } #[cfg(test)] @@ -1668,14 +1681,14 @@ mod tests { const UNIX_EOL: &str = "\n"; /// Same as [`Token`] except that this includes the [`TokenValue`] as well. - struct TestToken { + struct TestToken<'ast> { kind: TokenKind, - value: TokenValue, + value: TokenValue<'ast>, range: TextRange, flags: TokenFlags, } - impl std::fmt::Debug for TestToken { + impl std::fmt::Debug for TestToken<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut tuple = f.debug_tuple(""); let mut tuple = if matches!(self.value, TokenValue::None) { @@ -1692,12 +1705,12 @@ mod tests { } } - struct LexerOutput { - tokens: Vec, + struct LexerOutput<'ast> { + tokens: Vec>, errors: Vec, } - impl std::fmt::Display for LexerOutput { + impl std::fmt::Display for LexerOutput<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "## Tokens")?; writeln!(f, "```\n{:#?}\n```", self.tokens)?; @@ -1709,8 +1722,13 @@ mod tests { } } - fn lex(source: &str, mode: Mode, start_offset: TextSize) -> LexerOutput { - let mut lexer = Lexer::new(source, mode, start_offset); + fn lex<'source, 'ast>( + source: &'source str, + mode: Mode, + start_offset: TextSize, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { + let mut lexer = Lexer::new(source, mode, start_offset, allocator); let mut tokens = Vec::new(); loop { let kind = lexer.next_token(); @@ -1730,8 +1748,13 @@ mod tests { } } - fn lex_valid(source: &str, mode: Mode, start_offset: TextSize) -> LexerOutput { - let output = lex(source, mode, start_offset); + fn lex_valid<'ast>( + source: &str, + mode: Mode, + start_offset: TextSize, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { + let output = lex(source, mode, start_offset, allocator); if !output.errors.is_empty() { let mut message = "Unexpected lexical errors for a valid source:\n".to_string(); @@ -1745,8 +1768,12 @@ mod tests { output } - fn lex_invalid(source: &str, mode: Mode) -> LexerOutput { - let output = lex(source, mode, TextSize::default()); + fn lex_invalid<'ast>( + source: &str, + mode: Mode, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { + let output = lex(source, mode, TextSize::default(), allocator); assert!( !output.errors.is_empty(), @@ -1756,28 +1783,34 @@ mod tests { output } - fn lex_source(source: &str) -> LexerOutput { - lex_valid(source, Mode::Module, TextSize::default()) + fn lex_source<'ast>(source: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { + lex_valid(source, Mode::Module, TextSize::default(), allocator) } - fn lex_source_with_offset(source: &str, start_offset: TextSize) -> LexerOutput { - lex_valid(source, Mode::Module, start_offset) + fn lex_source_with_offset<'ast>( + source: &str, + start_offset: TextSize, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { + lex_valid(source, Mode::Module, start_offset, allocator) } - fn lex_jupyter_source(source: &str) -> LexerOutput { - lex_valid(source, Mode::Ipython, TextSize::default()) + fn lex_jupyter_source<'ast>(source: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { + lex_valid(source, Mode::Ipython, TextSize::default(), allocator) } #[test] fn bom() { + let allocator = Allocator::new(); let source = "\u{feff}x = 1"; - assert_snapshot!(lex_source(source)); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn bom_with_offset() { + let allocator = Allocator::new(); let source = "\u{feff}x + y + z"; - assert_snapshot!(lex_source_with_offset(source, TextSize::new(7))); + assert_snapshot!(lex_source_with_offset(source, TextSize::new(7), &allocator)); } #[test] @@ -1785,59 +1818,85 @@ mod tests { // BOM offsets the first token by 3, so make sure that lexing from offset 11 (variable z) // doesn't panic. Refer https://github.com/astral-sh/ruff/issues/11731 let source = "\u{feff}x + y + z"; - assert_snapshot!(lex_source_with_offset(source, TextSize::new(11))); + let allocator = Allocator::new(); + assert_snapshot!(lex_source_with_offset( + source, + TextSize::new(11), + &allocator + )); } - fn ipython_escape_command_line_continuation_eol(eol: &str) -> LexerOutput { + fn ipython_escape_command_line_continuation_eol<'ast>( + eol: &str, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { let source = format!("%matplotlib \\{eol} --inline"); - lex_jupyter_source(&source) + lex_jupyter_source(&source, &allocator) } #[test] fn test_ipython_escape_command_line_continuation_unix_eol() { - assert_snapshot!(ipython_escape_command_line_continuation_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(ipython_escape_command_line_continuation_eol( + UNIX_EOL, &allocator + )); } #[test] fn test_ipython_escape_command_line_continuation_mac_eol() { - assert_snapshot!(ipython_escape_command_line_continuation_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(ipython_escape_command_line_continuation_eol( + MAC_EOL, &allocator + )); } #[test] fn test_ipython_escape_command_line_continuation_windows_eol() { - assert_snapshot!(ipython_escape_command_line_continuation_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(ipython_escape_command_line_continuation_eol( + WINDOWS_EOL, + &allocator + )); } - fn ipython_escape_command_line_continuation_with_eol_and_eof(eol: &str) -> LexerOutput { + fn ipython_escape_command_line_continuation_with_eol_and_eof<'ast>( + eol: &str, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { let source = format!("%matplotlib \\{eol}"); - lex_jupyter_source(&source) + lex_jupyter_source(&source, &allocator) } #[test] fn test_ipython_escape_command_line_continuation_with_unix_eol_and_eof() { + let allocator = Allocator::new(); assert_snapshot!(ipython_escape_command_line_continuation_with_eol_and_eof( - UNIX_EOL + UNIX_EOL, &allocator )); } #[test] fn test_ipython_escape_command_line_continuation_with_mac_eol_and_eof() { + let allocator = Allocator::new(); assert_snapshot!(ipython_escape_command_line_continuation_with_eol_and_eof( - MAC_EOL + MAC_EOL, &allocator )); } #[test] fn test_ipython_escape_command_line_continuation_with_windows_eol_and_eof() { + let allocator = Allocator::new(); assert_snapshot!(ipython_escape_command_line_continuation_with_eol_and_eof( - WINDOWS_EOL + WINDOWS_EOL, + &allocator )); } #[test] fn test_empty_ipython_escape_command() { let source = "%\n%%\n!\n!!\n?\n??\n/\n,\n;"; - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } #[test] @@ -1858,7 +1917,8 @@ mod tests { !ls " .trim(); - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } #[test] @@ -1883,7 +1943,8 @@ mod tests { %%foo??? !pwd?" .trim(); - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } #[test] @@ -1893,7 +1954,8 @@ if True: %matplotlib \ --inline" .trim(); - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } #[test] @@ -1905,7 +1967,8 @@ bar = %timeit a % 3 baz = %matplotlib \ inline" .trim(); - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } fn assert_no_ipython_escape_command(tokens: &[TestToken]) { @@ -1929,7 +1992,8 @@ foo = ,func def f(arg=%timeit a = b): pass" .trim(); - let output = lex(source, Mode::Ipython, TextSize::default()); + let allocator = Allocator::new(); + let output = lex(source, Mode::Ipython, TextSize::default(), &allocator); assert!(output.errors.is_empty()); assert_no_ipython_escape_command(&output.tokens); } @@ -1938,130 +2002,153 @@ def f(arg=%timeit a = b): fn test_numbers() { let source = "0x2f 0o12 0b1101 0 123 123_45_67_890 0.2 1e+2 2.1e3 2j 2.2j 000 0x995DC9BBDF1939FA 0x995DC9BBDF1939FA995DC9BBDF1939FA"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_invalid_leading_zero_small() { let source = "025"; - assert_snapshot!(lex_invalid(source, Mode::Module)); + let allocator = Allocator::new(); + assert_snapshot!(lex_invalid(source, Mode::Module, &allocator)); } #[test] fn test_invalid_leading_zero_big() { let source = "0252222222222222522222222222225222222222222252222222222222522222222222225222222222222"; - assert_snapshot!(lex_invalid(source, Mode::Module)); + let allocator = Allocator::new(); + assert_snapshot!(lex_invalid(source, Mode::Module, &allocator)); } #[test] fn test_line_comment_long() { let source = "99232 # foo".to_string(); - assert_snapshot!(lex_source(&source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(&source, &allocator)); } #[test] fn test_line_comment_whitespace() { let source = "99232 # ".to_string(); - assert_snapshot!(lex_source(&source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(&source, &allocator)); } #[test] fn test_line_comment_single_whitespace() { let source = "99232 # ".to_string(); - assert_snapshot!(lex_source(&source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(&source, &allocator)); } #[test] fn test_line_comment_empty() { let source = "99232 #".to_string(); - assert_snapshot!(lex_source(&source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(&source, &allocator)); } - fn comment_until_eol(eol: &str) -> LexerOutput { + fn comment_until_eol<'ast>(eol: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { let source = format!("123 # Foo{eol}456"); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_comment_until_unix_eol() { - assert_snapshot!(comment_until_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(comment_until_eol(UNIX_EOL, &allocator)); } #[test] fn test_comment_until_mac_eol() { - assert_snapshot!(comment_until_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(comment_until_eol(MAC_EOL, &allocator)); } #[test] fn test_comment_until_windows_eol() { - assert_snapshot!(comment_until_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(comment_until_eol(WINDOWS_EOL, &allocator)); } #[test] fn test_assignment() { let source = r"a_variable = 99 + 2-0"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } - fn indentation_with_eol(eol: &str) -> LexerOutput { + fn indentation_with_eol<'ast>(eol: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { let source = format!("def foo():{eol} return 99{eol}{eol}"); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_indentation_with_unix_eol() { - assert_snapshot!(indentation_with_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(indentation_with_eol(UNIX_EOL, &allocator)); } #[test] fn test_indentation_with_mac_eol() { - assert_snapshot!(indentation_with_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(indentation_with_eol(MAC_EOL, &allocator)); } #[test] fn test_indentation_with_windows_eol() { - assert_snapshot!(indentation_with_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(indentation_with_eol(WINDOWS_EOL, &allocator)); } - fn double_dedent_with_eol(eol: &str) -> LexerOutput { + fn double_dedent_with_eol<'ast>(eol: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { let source = format!("def foo():{eol} if x:{eol}{eol} return 99{eol}{eol}"); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_double_dedent_with_unix_eol() { - assert_snapshot!(double_dedent_with_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_eol(UNIX_EOL, &allocator)); } #[test] fn test_double_dedent_with_mac_eol() { - assert_snapshot!(double_dedent_with_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_eol(MAC_EOL, &allocator)); } #[test] fn test_double_dedent_with_windows_eol() { - assert_snapshot!(double_dedent_with_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_eol(WINDOWS_EOL, &allocator)); } - fn double_dedent_with_tabs_eol(eol: &str) -> LexerOutput { + fn double_dedent_with_tabs_eol<'ast>( + eol: &str, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { let source = format!("def foo():{eol}\tif x:{eol}{eol}\t\t return 99{eol}{eol}"); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_double_dedent_with_tabs_unix_eol() { - assert_snapshot!(double_dedent_with_tabs_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_tabs_eol(UNIX_EOL, &allocator)); } #[test] fn test_double_dedent_with_tabs_mac_eol() { - assert_snapshot!(double_dedent_with_tabs_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_tabs_eol(MAC_EOL, &allocator)); } #[test] fn test_double_dedent_with_tabs_windows_eol() { - assert_snapshot!(double_dedent_with_tabs_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(double_dedent_with_tabs_eol(WINDOWS_EOL, &allocator)); } #[test] @@ -2072,10 +2159,11 @@ if first: pass foo "; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } - fn newline_in_brackets_eol(eol: &str) -> LexerOutput { + fn newline_in_brackets_eol<'ast>(eol: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { let source = r"x = [ 1,2 @@ -2087,22 +2175,25 @@ if first: 7}] " .replace('\n', eol); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_newline_in_brackets_unix_eol() { - assert_snapshot!(newline_in_brackets_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(newline_in_brackets_eol(UNIX_EOL, &allocator)); } #[test] fn test_newline_in_brackets_mac_eol() { - assert_snapshot!(newline_in_brackets_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(newline_in_brackets_eol(MAC_EOL, &allocator)); } #[test] fn test_newline_in_brackets_windows_eol() { - assert_snapshot!(newline_in_brackets_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(newline_in_brackets_eol(WINDOWS_EOL, &allocator)); } #[test] @@ -2114,55 +2205,67 @@ if first: 'c' \ 'd' )"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_logical_newline_line_comment() { let source = "#Hello\n#World\n"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_operators() { let source = "//////=/ /"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_string() { let source = r#""double" 'single' 'can\'t' "\\\"" '\t\r\n' '\g' r'raw\'' '\420' '\200\0a'"#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } - fn string_continuation_with_eol(eol: &str) -> LexerOutput { + fn string_continuation_with_eol<'ast>( + eol: &str, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { let source = format!("\"abc\\{eol}def\""); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_string_continuation_with_unix_eol() { - assert_snapshot!(string_continuation_with_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(string_continuation_with_eol(UNIX_EOL, &allocator)); } #[test] fn test_string_continuation_with_mac_eol() { - assert_snapshot!(string_continuation_with_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(string_continuation_with_eol(MAC_EOL, &allocator)); } #[test] fn test_string_continuation_with_windows_eol() { - assert_snapshot!(string_continuation_with_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(string_continuation_with_eol(WINDOWS_EOL, &allocator)); } #[test] fn test_escape_unicode_name() { let source = r#""\N{EN SPACE}""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } fn get_tokens_only(source: &str) -> Vec { - let output = lex(source, Mode::Module, TextSize::default()); + let allocator = Allocator::new(); + let output = lex(source, Mode::Module, TextSize::default(), &allocator); assert!(output.errors.is_empty()); output.tokens.into_iter().map(|token| token.kind).collect() } @@ -2174,24 +2277,27 @@ if first: assert_eq!(get_tokens_only(source1), get_tokens_only(source2)); } - fn triple_quoted_eol(eol: &str) -> LexerOutput { + fn triple_quoted_eol<'ast>(eol: &str, allocator: &'ast Allocator) -> LexerOutput<'ast> { let source = format!("\"\"\"{eol} test string{eol} \"\"\""); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_triple_quoted_unix_eol() { - assert_snapshot!(triple_quoted_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(triple_quoted_eol(UNIX_EOL, &allocator)); } #[test] fn test_triple_quoted_mac_eol() { - assert_snapshot!(triple_quoted_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(triple_quoted_eol(MAC_EOL, &allocator)); } #[test] fn test_triple_quoted_windows_eol() { - assert_snapshot!(triple_quoted_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(triple_quoted_eol(WINDOWS_EOL, &allocator)); } // This test case is to just make sure that the lexer doesn't go into @@ -2199,14 +2305,16 @@ if first: #[test] fn test_infinite_loop() { let source = "[1"; - lex_invalid(source, Mode::Module); + let allocator = Allocator::new(); + lex_invalid(source, Mode::Module, &allocator); } /// Emoji identifiers are a non-standard python feature and are not supported by our lexer. #[test] fn test_emoji_identifier() { let source = "🐦"; - assert_snapshot!(lex_invalid(source, Mode::Module)); + let allocator = Allocator::new(); + assert_snapshot!(lex_invalid(source, Mode::Module, &allocator)); } #[test] @@ -2214,95 +2322,113 @@ if first: let source = "if True: pass pass"; - assert_snapshot!(lex_invalid(source, Mode::Module)); + let allocator = Allocator::new(); + assert_snapshot!(lex_invalid(source, Mode::Module, &allocator)); } #[test] fn test_empty_fstrings() { let source = r#"f"" "" F"" f'' '' f"""""" f''''''"#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_prefix() { let source = r#"f"" F"" rf"" rF"" Rf"" RF"" fr"" Fr"" fR"" FR"""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring() { let source = r#"f"normal {foo} {{another}} {bar} {{{three}}}""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_parentheses() { let source = r#"f"{}" f"{{}}" f" {}" f"{{{}}}" f"{{{{}}}}" f" {} {{}} {{{}}} {{{{}}}} ""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } - fn fstring_single_quote_escape_eol(eol: &str) -> LexerOutput { + fn fstring_single_quote_escape_eol<'ast>( + eol: &str, + allocator: &'ast Allocator, + ) -> LexerOutput<'ast> { let source = format!(r"f'text \{eol} more text'"); - lex_source(&source) + lex_source(&source, &allocator) } #[test] fn test_fstring_single_quote_escape_unix_eol() { - assert_snapshot!(fstring_single_quote_escape_eol(UNIX_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(fstring_single_quote_escape_eol(UNIX_EOL, &allocator)); } #[test] fn test_fstring_single_quote_escape_mac_eol() { - assert_snapshot!(fstring_single_quote_escape_eol(MAC_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(fstring_single_quote_escape_eol(MAC_EOL, &allocator)); } #[test] fn test_fstring_single_quote_escape_windows_eol() { - assert_snapshot!(fstring_single_quote_escape_eol(WINDOWS_EOL)); + let allocator = Allocator::new(); + assert_snapshot!(fstring_single_quote_escape_eol(WINDOWS_EOL, &allocator)); } #[test] fn test_fstring_escape() { let source = r#"f"\{x:\"\{x}} \"\"\ end""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_escape_braces() { let source = r"f'\{foo}' f'\\{foo}' f'\{{foo}}' f'\\{{foo}}'"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_escape_raw() { let source = r#"rf"\{x:\"\{x}} \"\"\ end""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_named_unicode() { let source = r#"f"\N{BULLET} normal \Nope \N""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_named_unicode_raw() { let source = r#"rf"\N{BULLET} normal""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_with_named_expression() { let source = r#"f"{x:=10} {(x:=10)} {x,{y:=10}} {[x:=10]}""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_with_format_spec() { let source = r#"f"{foo:} {x=!s:.3f} {x:.{y}f} {'':*^{1:{1}}} {x:{{1}.pop()}}""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2325,19 +2451,22 @@ f'__{ b }__' "; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_conversion() { let source = r#"f"{x!s} {x=!r} {x:.3f!r} {{x!r}}""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_nested() { let source = r#"f"foo {f"bar {x + f"{wow}"}"} baz" f'foo {f'bar'} some {f"another"}'"#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2347,7 +2476,8 @@ f'__{ * y } second""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2360,7 +2490,8 @@ hello hello ''' f"some {f"""multiline allowed {x}"""} string""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2370,13 +2501,15 @@ allowed {x}"""} string""#; x } # not a comment """"#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_with_ipy_escape_command() { let source = r#"f"foo {!pwd} bar""#; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2386,13 +2519,15 @@ f"{lambda x:{x}}" f"{(lambda x:{x})}" "# .trim(); - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] fn test_fstring_with_nul_char() { let source = r"f'\0'"; - assert_snapshot!(lex_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_source(source, &allocator)); } #[test] @@ -2400,11 +2535,13 @@ f"{(lambda x:{x})}" let source = r"match foo: case bar: pass"; - assert_snapshot!(lex_jupyter_source(source)); + let allocator = Allocator::new(); + assert_snapshot!(lex_jupyter_source(source, &allocator)); } fn lex_fstring_error(source: &str) -> FStringErrorType { - let output = lex(source, Mode::Module, TextSize::default()); + let allocator = Allocator::new(); + let output = lex(source, Mode::Module, TextSize::default(), &allocator); match output .errors .into_iter() diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index 056d42a121..757b026b0a 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -4,7 +4,6 @@ use std::ops::Deref; use bitflags::bitflags; use rustc_hash::{FxBuildHasher, FxHashSet}; -use ruff_python_ast::name::Name; use ruff_python_ast::{ self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements, IpyEscapeKind, Number, Operator, UnaryOp, @@ -478,17 +477,14 @@ impl<'src, 'ast> Parser<'src, 'ast> { let TokenValue::Name(name) = self.bump_value(TokenKind::Name) else { unreachable!(); }; - return ast::Identifier { - id: self.allocator.alloc_str(&name), - range, - }; + return ast::Identifier { id: name, range }; } if self.current_token_kind().is_soft_keyword() { - let id = Name::new(self.src_text(range)); + let id = self.src_text(range); self.bump_soft_keyword_as_name(); return ast::Identifier { - id: self.allocator.alloc_str(&id), + id: self.alloc_str(id), range, }; } @@ -2287,7 +2283,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { let command = ast::ExprIpyEscapeCommand { range: self.node_range(start), kind, - value: self.alloc_str(&value), + value, }; if self.mode != Mode::Ipython { diff --git a/crates/ruff_python_parser/src/parser/mod.rs b/crates/ruff_python_parser/src/parser/mod.rs index 318a4f3f9f..dd4ec57ed5 100644 --- a/crates/ruff_python_parser/src/parser/mod.rs +++ b/crates/ruff_python_parser/src/parser/mod.rs @@ -27,7 +27,7 @@ pub(crate) struct Parser<'src, 'ast> { source: &'src str, /// Token source for the parser that skips over any non-trivia token. - tokens: TokenSource<'src>, + tokens: TokenSource<'src, 'ast>, /// Stores all the syntax errors found during the parsing. errors: Vec, @@ -64,7 +64,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { start_offset: TextSize, allocator: &'ast Allocator, ) -> Self { - let tokens = TokenSource::from_source(source, mode, start_offset); + let tokens = TokenSource::from_source(source, mode, start_offset, allocator); Parser { mode, @@ -355,7 +355,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { /// # Panics /// /// If the current token is not of the given kind. - fn bump_value(&mut self, kind: TokenKind) -> TokenValue { + fn bump_value(&mut self, kind: TokenKind) -> TokenValue<'ast> { let value = self.tokens.take_value(); self.bump(kind); value @@ -668,7 +668,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { } /// Creates a checkpoint to which the parser can later return to using [`Self::rewind`]. - fn checkpoint(&self) -> ParserCheckpoint { + fn checkpoint(&self) -> ParserCheckpoint<'ast> { ParserCheckpoint { tokens: self.tokens.checkpoint(), errors_position: self.errors.len(), @@ -679,7 +679,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { } /// Restore the parser to the given checkpoint. - fn rewind(&mut self, checkpoint: ParserCheckpoint) { + fn rewind(&mut self, checkpoint: ParserCheckpoint<'ast>) { let ParserCheckpoint { tokens, errors_position, @@ -696,8 +696,8 @@ impl<'src, 'ast> Parser<'src, 'ast> { } } -struct ParserCheckpoint { - tokens: TokenSourceCheckpoint, +struct ParserCheckpoint<'ast> { + tokens: TokenSourceCheckpoint<'ast>, errors_position: usize, current_token_id: TokenId, prev_token_end: TextSize, diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap.new b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap.new deleted file mode 100644 index 143d76db68..0000000000 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap.new +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests.rs -assertion_line: 56 -expression: parsed.expr() ---- -Name( - ExprName { - range: 0..5, - id: "first", - ctx: Load, - }, -) diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap.new b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap.new deleted file mode 100644 index ba1bb6f20e..0000000000 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap.new +++ /dev/null @@ -1,400 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests.rs -assertion_line: 144 -expression: parsed.syntax() ---- -Module( - ModModule { - range: 0..929, - body: [ - Expr( - StmtExpr { - range: 21..42, - value: BinOp( - ExprBinOp { - range: 27..40, - left: Name( - ExprName { - range: 27..28, - id: "a", - ctx: Load, - }, - ), - op: Mod, - right: Name( - ExprName { - range: 39..40, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 66..73, - kind: Help2, - value: "a.foo", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 74..80, - kind: Help, - value: "a.foo", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 81..88, - kind: Help, - value: "a.foo", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 89..100, - kind: Help2, - value: "a.foo()", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 115..128, - kind: Magic, - value: "timeit a = b", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 129..147, - kind: Magic, - value: "timeit foo(b) % 3", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 148..176, - kind: Magic, - value: "alias showPath pwd && ls -a", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 177..205, - kind: Magic, - value: "timeit a = foo(b); b = 2", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 206..226, - kind: Magic, - value: "matplotlib --inline", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 227..253, - kind: Magic, - value: "matplotlib --inline", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 277..309, - kind: Shell, - value: "pwd && ls -a | sed 's/^/\\ /'", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 310..347, - kind: Shell, - value: "pwd && ls -a | sed 's/^/\\\\ /'", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 348..393, - kind: ShCap, - value: "cd /Users/foo/Library/Application\\ Support/", - }, - ), - FunctionDef( - StmtFunctionDef { - range: 566..626, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 570..573, - }, - type_params: None, - parameters: Parameters { - range: 573..575, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Return( - StmtReturn { - range: 581..626, - value: Some( - Compare( - ExprCompare { - range: 598..620, - left: Name( - ExprName { - range: 598..599, - id: "a", - ctx: Load, - }, - ), - ops: [ - NotEq, - ], - comparators: [ - Name( - ExprName { - range: 619..620, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - ], - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 656..664, - kind: Paren, - value: "foo 1 2", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 665..673, - kind: Quote2, - value: "foo 1 2", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 674..682, - kind: Quote, - value: "foo 1 2", - }, - ), - For( - StmtFor { - range: 711..737, - is_async: false, - target: Name( - ExprName { - range: 715..716, - id: "a", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 720..728, - func: Name( - ExprName { - range: 720..725, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 725..728, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 726..727, - value: Int( - 5, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 734..737, - kind: Shell, - value: "ls", - }, - ), - ], - orelse: [], - }, - ), - Assign( - StmtAssign { - range: 739..748, - targets: [ - Name( - ExprName { - range: 739..741, - id: "p1", - ctx: Store, - }, - ), - ], - value: IpyEscapeCommand( - ExprIpyEscapeCommand { - range: 744..748, - kind: Shell, - value: "pwd", - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 749..763, - target: Name( - ExprName { - range: 749..751, - id: "p2", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 753..756, - id: "str", - ctx: Load, - }, - ), - value: Some( - IpyEscapeCommand( - ExprIpyEscapeCommand { - range: 759..763, - kind: Shell, - value: "pwd", - }, - ), - ), - simple: true, - }, - ), - Assign( - StmtAssign { - range: 764..784, - targets: [ - Name( - ExprName { - range: 764..767, - id: "foo", - ctx: Store, - }, - ), - ], - value: IpyEscapeCommand( - ExprIpyEscapeCommand { - range: 770..784, - kind: Magic, - value: "foo bar", - }, - ), - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 786..791, - kind: Magic, - value: " foo", - }, - ), - Assign( - StmtAssign { - range: 792..813, - targets: [ - Name( - ExprName { - range: 792..795, - id: "foo", - ctx: Store, - }, - ), - ], - value: IpyEscapeCommand( - ExprIpyEscapeCommand { - range: 798..813, - kind: Magic, - value: "foo # comment", - }, - ), - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 838..842, - kind: Help, - value: "foo", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 843..852, - kind: Help2, - value: "foo.bar", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 853..865, - kind: Help, - value: "foo.bar.baz", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 866..874, - kind: Help2, - value: "foo[0]", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 875..885, - kind: Help, - value: "foo[0][1]", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 886..905, - kind: Help2, - value: "foo.bar[0].baz[1]", - }, - ), - IpyEscapeCommand( - StmtIpyEscapeCommand { - range: 906..929, - kind: Help2, - value: "foo.bar[0].baz[2].egg", - }, - ), - ], - }, -) diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap.new b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap.new deleted file mode 100644 index 88a0bab7a3..0000000000 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap.new +++ /dev/null @@ -1,39 +0,0 @@ ---- -source: crates/ruff_python_parser/src/parser/tests.rs -assertion_line: 66 -expression: suite ---- -[ - Assign( - StmtAssign { - range: 0..37, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: StringLiteral( - ExprStringLiteral { - range: 4..37, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 4..37, - value: "\u{8}another cool trick", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/parser/statement.rs b/crates/ruff_python_parser/src/parser/statement.rs index 3e0678595b..af4fec9658 100644 --- a/crates/ruff_python_parser/src/parser/statement.rs +++ b/crates/ruff_python_parser/src/parser/statement.rs @@ -920,11 +920,7 @@ impl<'src, 'ast> Parser<'src, 'ast> { self.add_error(ParseErrorType::UnexpectedIpythonEscapeCommand, range); } - ast::StmtIpyEscapeCommand { - range, - kind, - value: self.alloc_str(&value), - } + ast::StmtIpyEscapeCommand { range, kind, value } } /// Parses an IPython help end escape command at the statement level. diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap.new deleted file mode 100644 index 393b0b355a..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap.new +++ /dev/null @@ -1,39 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 869 -expression: suite ---- -[ - Assign( - StmtAssign { - range: 0..16, - targets: [ - Name( - ExprName { - range: 0..4, - id: "bold", - ctx: Store, - }, - ), - ], - value: StringLiteral( - ExprStringLiteral { - range: 7..16, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 7..16, - value: "\u{3}8[1m", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap.new deleted file mode 100644 index a4a8bfc11f..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap.new +++ /dev/null @@ -1,81 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 802 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..22, - value: FString( - ExprFString { - range: 0..22, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..22, - elements: [ - Literal( - FStringLiteralElement { - range: 2..5, - value: "aaa", - }, - ), - Expression( - FStringExpressionElement { - range: 5..10, - expression: Name( - ExprName { - range: 6..9, - id: "bbb", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 10..13, - value: "ccc", - }, - ), - Expression( - FStringExpressionElement { - range: 13..18, - expression: Name( - ExprName { - range: 14..17, - id: "ddd", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 18..21, - value: "eee", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap.new deleted file mode 100644 index 6efd6fd15b..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap.new +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 819 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..8, - value: FString( - ExprFString { - range: 0..8, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..8, - elements: [ - Literal( - FStringLiteralElement { - range: 2..4, - value: "\\", - }, - ), - Expression( - FStringExpressionElement { - range: 4..7, - expression: Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap.new deleted file mode 100644 index cbff234971..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap.new +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 794 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..8, - value: FString( - ExprFString { - range: 0..8, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..8, - elements: [ - Literal( - FStringLiteralElement { - range: 2..4, - value: "\n", - }, - ), - Expression( - FStringExpressionElement { - range: 4..7, - expression: Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap.new deleted file mode 100644 index 5085b3cbc9..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap.new +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 844 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..9, - value: FString( - ExprFString { - range: 0..9, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..9, - elements: [ - Literal( - FStringLiteralElement { - range: 3..5, - value: "\\\n", - }, - ), - Expression( - FStringExpressionElement { - range: 5..8, - expression: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Raw { - uppercase_r: false, - }, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap.new deleted file mode 100644 index fc2c4eddf8..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap.new +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 569 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..10, - value: FString( - ExprFString { - range: 0..10, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..10, - elements: [ - Expression( - FStringExpressionElement { - range: 2..9, - expression: Name( - ExprName { - range: 3..7, - id: "user", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap.new deleted file mode 100644 index a5322a0e11..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap.new +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 577 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..38, - value: FString( - ExprFString { - range: 0..38, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..38, - elements: [ - Literal( - FStringLiteralElement { - range: 2..6, - value: "mix ", - }, - ), - Expression( - FStringExpressionElement { - range: 6..13, - expression: Name( - ExprName { - range: 7..11, - id: "user", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 13..28, - value: " with text and ", - }, - ), - Expression( - FStringExpressionElement { - range: 28..37, - expression: Name( - ExprName { - range: 29..35, - id: "second", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap.new deleted file mode 100644 index 7db3a82718..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap.new +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 585 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..14, - value: FString( - ExprFString { - range: 0..14, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..14, - elements: [ - Expression( - FStringExpressionElement { - range: 2..13, - expression: Name( - ExprName { - range: 3..7, - id: "user", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 9..12, - elements: [ - Literal( - FStringLiteralElement { - range: 9..12, - value: ">10", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap.new deleted file mode 100644 index d5170ea741..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap.new +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 811 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..11, - value: FString( - ExprFString { - range: 0..11, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..11, - elements: [ - Literal( - FStringLiteralElement { - range: 4..5, - value: "\n", - }, - ), - Expression( - FStringExpressionElement { - range: 5..8, - expression: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap.new deleted file mode 100644 index 40aecfea9f..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap.new +++ /dev/null @@ -1,69 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 537 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..18, - value: FString( - ExprFString { - range: 0..18, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..18, - elements: [ - Expression( - FStringExpressionElement { - range: 2..5, - expression: Name( - ExprName { - range: 3..4, - id: "a", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Expression( - FStringExpressionElement { - range: 5..10, - expression: Name( - ExprName { - range: 7..8, - id: "b", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 10..17, - value: "{foo}", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap.new deleted file mode 100644 index 0237a13e78..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap.new +++ /dev/null @@ -1,94 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 860 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..16, - value: FString( - ExprFString { - range: 0..16, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..16, - elements: [ - Expression( - FStringExpressionElement { - range: 2..15, - expression: Name( - ExprName { - range: 3..6, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 7..14, - elements: [ - Expression( - FStringExpressionElement { - range: 7..14, - expression: StringLiteral( - ExprStringLiteral { - range: 8..13, - value: StringLiteralValue { - inner: Concatenated( - ConcatenatedStringLiteral { - strings: [ - StringLiteral { - range: 8..10, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - StringLiteral { - range: 11..13, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ], - value: "", - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap.new deleted file mode 100644 index 5550aa56d4..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap.new +++ /dev/null @@ -1,69 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 545 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..15, - value: FString( - ExprFString { - range: 0..15, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..15, - elements: [ - Expression( - FStringExpressionElement { - range: 2..14, - expression: Name( - ExprName { - range: 3..6, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 7..13, - elements: [ - Expression( - FStringExpressionElement { - range: 7..13, - expression: Name( - ExprName { - range: 8..12, - id: "spec", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap.new deleted file mode 100644 index 2ca00d9792..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap.new +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 852 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..13, - value: FString( - ExprFString { - range: 0..13, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..13, - elements: [ - Expression( - FStringExpressionElement { - range: 2..12, - expression: Name( - ExprName { - range: 3..6, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 7..11, - elements: [ - Expression( - FStringExpressionElement { - range: 7..11, - expression: StringLiteral( - ExprStringLiteral { - range: 8..10, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 8..10, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap.new deleted file mode 100644 index b55bdb6580..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap.new +++ /dev/null @@ -1,60 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 553 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..13, - value: FString( - ExprFString { - range: 0..13, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..13, - elements: [ - Expression( - FStringExpressionElement { - range: 2..12, - expression: Name( - ExprName { - range: 3..6, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 7..11, - elements: [ - Literal( - FStringLiteralElement { - range: 7..11, - value: "spec", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap.new deleted file mode 100644 index 270b40d17a..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap.new +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 639 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..10, - value: FString( - ExprFString { - range: 0..10, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..10, - elements: [ - Expression( - FStringExpressionElement { - range: 2..9, - expression: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: " =", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap.new deleted file mode 100644 index 57f0a35148..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap.new +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 647 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..10, - value: FString( - ExprFString { - range: 0..10, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..10, - elements: [ - Expression( - FStringExpressionElement { - range: 2..9, - expression: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "= ", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap.new deleted file mode 100644 index 6ce128d78f..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap.new +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 827 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..7, - value: FString( - ExprFString { - range: 0..7, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..7, - elements: [ - Expression( - FStringExpressionElement { - range: 3..6, - expression: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Raw { - uppercase_r: false, - }, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap.new b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap.new deleted file mode 100644 index 0f7b97ae04..0000000000 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap.new +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/ruff_python_parser/src/string.rs -assertion_line: 835 -expression: suite ---- -[ - Expr( - StmtExpr { - range: 0..11, - value: FString( - ExprFString { - range: 0..11, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..11, - elements: [ - Expression( - FStringExpressionElement { - range: 5..8, - expression: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Raw { - uppercase_r: false, - }, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), -] diff --git a/crates/ruff_python_parser/src/token.rs b/crates/ruff_python_parser/src/token.rs index 9c240f4964..0c80473a4e 100644 --- a/crates/ruff_python_parser/src/token.rs +++ b/crates/ruff_python_parser/src/token.rs @@ -9,7 +9,6 @@ use std::fmt; use bitflags::bitflags; -use ruff_python_ast::name::Name; use ruff_python_ast::str::Quote; use ruff_python_ast::str_prefix::{ AnyStringPrefix, ByteStringPrefix, FStringPrefix, StringLiteralPrefix, @@ -774,16 +773,16 @@ impl TokenFlags { } #[derive(Clone, Debug, Default)] -pub(crate) enum TokenValue { +pub(crate) enum TokenValue<'ast> { #[default] None, /// Token value for a name, commonly known as an identifier. /// /// Unicode names are NFKC-normalized by the lexer, /// matching [the behaviour of Python's lexer](https://docs.python.org/3/reference/lexical_analysis.html#identifiers) - Name(Name), + Name(&'ast str), /// Token value for an integer. - Int(Int), + Int(Int<'ast>), /// Token value for a floating point number. Float(f64), /// Token value for a complex number. @@ -794,15 +793,15 @@ pub(crate) enum TokenValue { imag: f64, }, /// Token value for a string. - String(Box), + String(&'ast str), /// Token value that includes the portion of text inside the f-string that's not /// part of the expression part and isn't an opening or closing brace. - FStringMiddle(Box), + FStringMiddle(&'ast str), /// Token value for IPython escape commands. These are recognized by the lexer /// only when the mode is [`Mode::Ipython`]. IpyEscapeCommand { /// The magic command value. - value: Box, + value: &'ast str, /// The kind of magic command. kind: IpyEscapeKind, }, diff --git a/crates/ruff_python_parser/src/token_source.rs b/crates/ruff_python_parser/src/token_source.rs index 4851879c89..0607ae46a6 100644 --- a/crates/ruff_python_parser/src/token_source.rs +++ b/crates/ruff_python_parser/src/token_source.rs @@ -1,3 +1,4 @@ +use ruff_allocator::Allocator; use ruff_text_size::{Ranged, TextRange, TextSize}; use crate::error::LexicalError; @@ -7,9 +8,9 @@ use crate::Mode; /// Token source for the parser that skips over any trivia tokens. #[derive(Debug)] -pub(crate) struct TokenSource<'src> { +pub(crate) struct TokenSource<'src, 'ast> { /// The underlying source for the tokens. - lexer: Lexer<'src>, + lexer: Lexer<'src, 'ast>, /// A vector containing all the tokens emitted by the lexer. This is returned when the parser /// is finished consuming all the tokens. Note that unlike the emitted tokens, this vector @@ -17,9 +18,9 @@ pub(crate) struct TokenSource<'src> { tokens: Vec, } -impl<'src> TokenSource<'src> { +impl<'src, 'ast> TokenSource<'src, 'ast> { /// Create a new token source for the given lexer. - pub(crate) fn new(lexer: Lexer<'src>) -> Self { + pub(crate) fn new(lexer: Lexer<'src, 'ast>) -> Self { // TODO(dhruvmanila): Use `allocate_tokens_vec` TokenSource { lexer, @@ -28,8 +29,13 @@ impl<'src> TokenSource<'src> { } /// Create a new token source from the given source code which starts at the given offset. - pub(crate) fn from_source(source: &'src str, mode: Mode, start_offset: TextSize) -> Self { - let lexer = Lexer::new(source, mode, start_offset); + pub(crate) fn from_source( + source: &'src str, + mode: Mode, + start_offset: TextSize, + allocator: &'ast Allocator, + ) -> Self { + let lexer = Lexer::new(source, mode, start_offset, allocator); let mut source = TokenSource::new(lexer); // Initialize the token source so that the current token is set correctly. @@ -56,7 +62,7 @@ impl<'src> TokenSource<'src> { /// for more info. /// /// [`take_value`]: Lexer::take_value - pub(crate) fn take_value(&mut self) -> TokenValue { + pub(crate) fn take_value(&mut self) -> TokenValue<'ast> { self.lexer.take_value() } @@ -148,7 +154,7 @@ impl<'src> TokenSource<'src> { } /// Creates a checkpoint to which the token source can later return to using [`Self::rewind`]. - pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint { + pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint<'ast> { TokenSourceCheckpoint { lexer_checkpoint: self.lexer.checkpoint(), tokens_position: self.tokens.len(), @@ -156,7 +162,7 @@ impl<'src> TokenSource<'src> { } /// Restore the token source to the given checkpoint. - pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint) { + pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint<'ast>) { let TokenSourceCheckpoint { lexer_checkpoint, tokens_position, @@ -186,8 +192,8 @@ impl<'src> TokenSource<'src> { } } -pub(crate) struct TokenSourceCheckpoint { - lexer_checkpoint: LexerCheckpoint, +pub(crate) struct TokenSourceCheckpoint<'ast> { + lexer_checkpoint: LexerCheckpoint<'ast>, tokens_position: usize, } diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap.new deleted file mode 100644 index 3ddbcf9d04..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap.new +++ /dev/null @@ -1,201 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..63, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..11, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - annotation: Starred( - ExprStarred { - range: 3..7, - value: Name( - ExprName { - range: 4..7, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 12..26, - target: Name( - ExprName { - range: 12..13, - id: "x", - ctx: Store, - }, - ), - annotation: Yield( - ExprYield { - range: 15..22, - value: Some( - Name( - ExprName { - range: 21..22, - id: "a", - ctx: Load, - }, - ), - ), - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 27..46, - target: Name( - ExprName { - range: 27..28, - id: "x", - ctx: Store, - }, - ), - annotation: YieldFrom( - ExprYieldFrom { - range: 30..42, - value: Name( - ExprName { - range: 41..42, - id: "b", - ctx: Load, - }, - ), - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 45..46, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 47..51, - target: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 50..51, - id: "y", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - Assign( - StmtAssign { - range: 55..62, - targets: [ - Name( - ExprName { - range: 55..58, - id: "int", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 61..62, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x: *int = 1 - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | x: yield a = 1 -3 | x: yield from b = 1 - | - - - | -1 | x: *int = 1 -2 | x: yield a = 1 - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | x: yield from b = 1 -4 | x: y := int = 1 - | - - - | -1 | x: *int = 1 -2 | x: yield a = 1 -3 | x: yield from b = 1 - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | x: y := int = 1 - | - - - | -2 | x: yield a = 1 -3 | x: yield from b = 1 -4 | x: y := int = 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap.new deleted file mode 100644 index f7b07253a8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap.new +++ /dev/null @@ -1,509 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..170, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..18, - target: StringLiteral( - ExprStringLiteral { - range: 0..5, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 0..5, - value: "abc", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - annotation: Name( - ExprName { - range: 7..10, - id: "str", - ctx: Load, - }, - ), - value: Some( - StringLiteral( - ExprStringLiteral { - range: 13..18, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 13..18, - value: "def", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 19..37, - target: Call( - ExprCall { - range: 19..25, - func: Name( - ExprName { - range: 19..23, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 23..25, - args: [], - keywords: [], - }, - }, - ), - annotation: Name( - ExprName { - range: 27..30, - id: "str", - ctx: Load, - }, - ), - value: Some( - StringLiteral( - ExprStringLiteral { - range: 33..37, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 33..37, - value: "no", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 38..52, - target: Starred( - ExprStarred { - range: 38..40, - value: Name( - ExprName { - range: 39..40, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 42..45, - id: "int", - ctx: Load, - }, - ), - value: Some( - Tuple( - ExprTuple { - range: 48..52, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 48..49, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 72..83, - target: Tuple( - ExprTuple { - range: 72..74, - elts: [ - Name( - ExprName { - range: 72..73, - id: "x", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - annotation: Name( - ExprName { - range: 76..79, - id: "int", - ctx: Load, - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 1, - ), - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 84..100, - target: Tuple( - ExprTuple { - range: 84..88, - elts: [ - Name( - ExprName { - range: 84..85, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 87..88, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - annotation: Name( - ExprName { - range: 90..93, - id: "int", - ctx: Load, - }, - ), - value: Some( - Tuple( - ExprTuple { - range: 96..100, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 96..97, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 99..100, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 101..119, - target: Tuple( - ExprTuple { - range: 101..107, - elts: [ - Name( - ExprName { - range: 102..103, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 105..106, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - annotation: Name( - ExprName { - range: 109..112, - id: "int", - ctx: Load, - }, - ), - value: Some( - Tuple( - ExprTuple { - range: 115..119, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 115..116, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 138..150, - target: List( - ExprList { - range: 138..141, - elts: [ - Name( - ExprName { - range: 139..140, - id: "x", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 143..146, - id: "int", - ctx: Load, - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 149..150, - value: Int( - 1, - ), - }, - ), - ), - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 151..169, - target: List( - ExprList { - range: 151..157, - elts: [ - Name( - ExprName { - range: 152..153, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 155..156, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 159..162, - id: "int", - ctx: Load, - }, - ), - value: Some( - Tuple( - ExprTuple { - range: 165..169, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 165..166, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 168..169, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - simple: false, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | "abc": str = "def" - | ^^^^^ Syntax Error: Invalid annotated assignment target -2 | call(): str = "no" -3 | *x: int = 1, 2 - | - - - | -1 | "abc": str = "def" -2 | call(): str = "no" - | ^^^^^^ Syntax Error: Invalid annotated assignment target -3 | *x: int = 1, 2 -4 | # Tuple assignment - | - - - | -1 | "abc": str = "def" -2 | call(): str = "no" -3 | *x: int = 1, 2 - | ^^ Syntax Error: Invalid annotated assignment target -4 | # Tuple assignment -5 | x,: int = 1 - | - - - | -3 | *x: int = 1, 2 -4 | # Tuple assignment -5 | x,: int = 1 - | ^^ Syntax Error: Only single target (not tuple) can be annotated -6 | x, y: int = 1, 2 -7 | (x, y): int = 1, 2 - | - - - | -4 | # Tuple assignment -5 | x,: int = 1 -6 | x, y: int = 1, 2 - | ^^^^ Syntax Error: Only single target (not tuple) can be annotated -7 | (x, y): int = 1, 2 -8 | # List assignment - | - - - | -5 | x,: int = 1 -6 | x, y: int = 1, 2 -7 | (x, y): int = 1, 2 - | ^^^^^^ Syntax Error: Only single target (not tuple) can be annotated -8 | # List assignment -9 | [x]: int = 1 - | - - - | - 7 | (x, y): int = 1, 2 - 8 | # List assignment - 9 | [x]: int = 1 - | ^^^ Syntax Error: Only single target (not list) can be annotated -10 | [x, y]: int = 1, 2 - | - - - | - 8 | # List assignment - 9 | [x]: int = 1 -10 | [x, y]: int = 1, 2 - | ^^^^^^ Syntax Error: Only single target (not list) can be annotated - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap.new deleted file mode 100644 index 465db77ee4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap.new +++ /dev/null @@ -1,223 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_value.py ---- -## AST - -``` -Module( - ModModule { - range: 0..65, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..17, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 3..6, - id: "Any", - ctx: Load, - }, - ), - value: Some( - Starred( - ExprStarred { - range: 9..17, - value: BoolOp( - ExprBoolOp { - range: 10..17, - op: And, - values: [ - Name( - ExprName { - range: 10..11, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 16..17, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 18..28, - target: Name( - ExprName { - range: 18..19, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 21..24, - id: "Any", - ctx: Load, - }, - ), - value: Some( - Name( - ExprName { - range: 27..28, - id: "x", - ctx: Load, - }, - ), - ), - simple: true, - }, - ), - Expr( - StmtExpr { - range: 32..33, - value: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 1, - ), - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 34..64, - target: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 37..41, - id: "list", - ctx: Load, - }, - ), - value: Some( - List( - ExprList { - range: 44..64, - elts: [ - Name( - ExprName { - range: 45..46, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 48..54, - value: BinOp( - ExprBinOp { - range: 49..54, - left: Name( - ExprName { - range: 49..50, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 53..54, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 56..63, - value: BoolOp( - ExprBoolOp { - range: 57..63, - op: Or, - values: [ - Name( - ExprName { - range: 57..58, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 62..63, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ), - simple: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x: Any = *a and b - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -2 | x: Any = x := 1 -3 | x: list = [x, *a | b, *a or b] - | - - - | -1 | x: Any = *a and b -2 | x: Any = x := 1 - | ^^ Syntax Error: Expected a statement -3 | x: list = [x, *a | b, *a or b] - | - - - | -1 | x: Any = *a and b -2 | x: Any = x := 1 -3 | x: list = [x, *a | b, *a or b] - | ^^^^^^ Syntax Error: Boolean expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap.new deleted file mode 100644 index 869ded04eb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap.new +++ /dev/null @@ -1,43 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_missing_rhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..9, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..8, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 3..6, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x: int = - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap.new deleted file mode 100644 index a7f256d99c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap.new +++ /dev/null @@ -1,111 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_alias_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..37, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..7, - target: Name( - ExprName { - range: 0..1, - id: "a", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 3..7, - id: "type", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - Assign( - StmtAssign { - range: 8..15, - targets: [ - Name( - ExprName { - range: 8..9, - id: "X", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 12..15, - id: "int", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..28, - value: Lambda( - ExprLambda { - range: 16..28, - parameters: None, - body: Name( - ExprName { - range: 24..28, - id: "type", - ctx: Load, - }, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 29..36, - targets: [ - Name( - ExprName { - range: 29..30, - id: "X", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 33..36, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | a: type X = int - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons -2 | lambda: type X = int - | - - - | -1 | a: type X = int -2 | lambda: type X = int - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap.new deleted file mode 100644 index 325bd9d6a5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap.new +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_msg.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Assert( - StmtAssert { - range: 0..9, - test: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - msg: None, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | assert x, - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap.new deleted file mode 100644 index c9174fa079..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap.new +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_test.py ---- -## AST - -``` -Module( - ModModule { - range: 0..7, - body: [ - Assert( - StmtAssert { - range: 0..6, - test: Name( - ExprName { - range: 6..6, - id: "", - ctx: Invalid, - }, - ), - msg: None, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | assert - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap.new deleted file mode 100644 index 549a6d9600..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap.new +++ /dev/null @@ -1,161 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_msg_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..83, - body: [ - Assert( - StmtAssert { - range: 0..16, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 7..12, - value: false, - }, - ), - msg: Some( - Starred( - ExprStarred { - range: 14..16, - value: Name( - ExprName { - range: 15..16, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - Assert( - StmtAssert { - range: 17..30, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 24..29, - value: false, - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 31..39, - test: Name( - ExprName { - range: 38..39, - id: "x", - ctx: Load, - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 40..61, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 47..52, - value: false, - }, - ), - msg: Some( - Yield( - ExprYield { - range: 54..61, - value: Some( - Name( - ExprName { - range: 60..61, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - Assert( - StmtAssert { - range: 62..77, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 69..74, - value: false, - }, - ), - msg: Some( - Name( - ExprName { - range: 76..77, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - Expr( - StmtExpr { - range: 81..82, - value: NumberLiteral( - ExprNumberLiteral { - range: 81..82, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | assert False, *x - | ^^ Syntax Error: Starred expression cannot be used here -2 | assert False, assert x -3 | assert False, yield x - | - - - | -1 | assert False, *x -2 | assert False, assert x - | ^^^^^^ Syntax Error: Expected an expression -3 | assert False, yield x -4 | assert False, x := 1 - | - - - | -1 | assert False, *x -2 | assert False, assert x -3 | assert False, yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | assert False, x := 1 - | - - - | -2 | assert False, assert x -3 | assert False, yield x -4 | assert False, x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap.new deleted file mode 100644 index 78b1ae6043..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap.new +++ /dev/null @@ -1,149 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_test_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..55, - body: [ - Assert( - StmtAssert { - range: 0..9, - test: Starred( - ExprStarred { - range: 7..9, - value: Name( - ExprName { - range: 8..9, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 10..23, - test: Name( - ExprName { - range: 17..23, - id: "assert", - ctx: Load, - }, - ), - msg: None, - }, - ), - Expr( - StmtExpr { - range: 24..25, - value: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - }, - ), - Assert( - StmtAssert { - range: 26..40, - test: Yield( - ExprYield { - range: 33..40, - value: Some( - Name( - ExprName { - range: 39..40, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 41..49, - test: Name( - ExprName { - range: 48..49, - id: "x", - ctx: Load, - }, - ), - msg: None, - }, - ), - Expr( - StmtExpr { - range: 53..54, - value: NumberLiteral( - ExprNumberLiteral { - range: 53..54, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | assert *x - | ^^ Syntax Error: Starred expression cannot be used here -2 | assert assert x -3 | assert yield x - | - - - | -1 | assert *x -2 | assert assert x - | ^^^^^^ Syntax Error: Expected an identifier, but found a keyword 'assert' that cannot be used here -3 | assert yield x -4 | assert x := 1 - | - - - | -1 | assert *x -2 | assert assert x - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | assert yield x -4 | assert x := 1 - | - - - | -1 | assert *x -2 | assert assert x -3 | assert yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | assert x := 1 - | - - - | -2 | assert assert x -3 | assert yield x -4 | assert x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap.new deleted file mode 100644 index 9a89066d6b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap.new +++ /dev/null @@ -1,259 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..58, - body: [ - Assign( - StmtAssign { - range: 0..5, - targets: [ - NumberLiteral( - ExprNumberLiteral { - range: 0..1, - value: Int( - 1, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 6..15, - targets: [ - Name( - ExprName { - range: 6..7, - id: "x", - ctx: Store, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 1, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 14..15, - value: Int( - 2, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 16..33, - targets: [ - Name( - ExprName { - range: 16..17, - id: "x", - ctx: Store, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 1, - ), - }, - ), - Name( - ExprName { - range: 24..25, - id: "y", - ctx: Store, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 2, - ), - }, - ), - ], - value: Name( - ExprName { - range: 32..33, - id: "z", - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 34..57, - targets: [ - List( - ExprList { - range: 34..44, - elts: [ - StringLiteral( - ExprStringLiteral { - range: 35..38, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 35..38, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - StringLiteral( - ExprStringLiteral { - range: 40..43, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 40..43, - value: "b", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 47..57, - elts: [ - StringLiteral( - ExprStringLiteral { - range: 48..51, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 48..51, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - StringLiteral( - ExprStringLiteral { - range: 53..56, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 53..56, - value: "b", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | 1 = 1 - | ^ Syntax Error: Invalid assignment target -2 | x = 1 = 2 -3 | x = 1 = y = 2 = z - | - - - | -1 | 1 = 1 -2 | x = 1 = 2 - | ^ Syntax Error: Invalid assignment target -3 | x = 1 = y = 2 = z -4 | ["a", "b"] = ["a", "b"] - | - - - | -1 | 1 = 1 -2 | x = 1 = 2 -3 | x = 1 = y = 2 = z - | ^ Syntax Error: Invalid assignment target -4 | ["a", "b"] = ["a", "b"] - | - - - | -1 | 1 = 1 -2 | x = 1 = 2 -3 | x = 1 = y = 2 = z - | ^ Syntax Error: Invalid assignment target -4 | ["a", "b"] = ["a", "b"] - | - - - | -2 | x = 1 = 2 -3 | x = 1 = y = 2 = z -4 | ["a", "b"] = ["a", "b"] - | ^^^ Syntax Error: Invalid assignment target - | - - - | -2 | x = 1 = 2 -3 | x = 1 = y = 2 = z -4 | ["a", "b"] = ["a", "b"] - | ^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap.new deleted file mode 100644 index a5f9d28b95..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap.new +++ /dev/null @@ -1,257 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_value_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..72, - body: [ - Assign( - StmtAssign { - range: 0..12, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: Starred( - ExprStarred { - range: 4..12, - value: BoolOp( - ExprBoolOp { - range: 5..12, - op: And, - values: [ - Name( - ExprName { - range: 5..6, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 11..12, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 13..25, - targets: [ - Name( - ExprName { - range: 13..14, - id: "x", - ctx: Store, - }, - ), - ], - value: Starred( - ExprStarred { - range: 17..25, - value: Yield( - ExprYield { - range: 18..25, - value: Some( - Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 26..43, - targets: [ - Name( - ExprName { - range: 26..27, - id: "x", - ctx: Store, - }, - ), - ], - value: Starred( - ExprStarred { - range: 30..43, - value: YieldFrom( - ExprYieldFrom { - range: 31..43, - value: Name( - ExprName { - range: 42..43, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 44..60, - targets: [ - Name( - ExprName { - range: 44..45, - id: "x", - ctx: Store, - }, - ), - ], - value: Starred( - ExprStarred { - range: 48..60, - value: Lambda( - ExprLambda { - range: 49..60, - parameters: Some( - Parameters { - range: 56..57, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 56..57, - parameter: Parameter { - range: 56..57, - name: Identifier { - id: "x", - range: 56..57, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 59..60, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 61..66, - targets: [ - Name( - ExprName { - range: 61..62, - id: "x", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 65..66, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 70..71, - value: NumberLiteral( - ExprNumberLiteral { - range: 70..71, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x = *a and b - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -2 | x = *yield x -3 | x = *yield from x - | - - - | -1 | x = *a and b -2 | x = *yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | x = *yield from x -4 | x = *lambda x: x - | - - - | -1 | x = *a and b -2 | x = *yield x -3 | x = *yield from x - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | x = *lambda x: x -5 | x = x := 1 - | - - - | -2 | x = *yield x -3 | x = *yield from x -4 | x = *lambda x: x - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -5 | x = x := 1 - | - - - | -3 | x = *yield from x -4 | x = *lambda x: x -5 | x = x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap.new deleted file mode 100644 index 32f2a8c662..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap.new +++ /dev/null @@ -1,146 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_keyword_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..42, - body: [ - Assign( - StmtAssign { - range: 0..12, - targets: [ - Name( - ExprName { - range: 0..1, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 4..8, - id: "pass", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 11..12, - id: "c", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..18, - value: BinOp( - ExprBinOp { - range: 13..18, - left: Name( - ExprName { - range: 13..14, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 17..18, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 19..35, - targets: [ - Name( - ExprName { - range: 19..20, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 23..24, - id: "b", - ctx: Store, - }, - ), - Name( - ExprName { - range: 27..31, - id: "pass", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 34..35, - id: "c", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 36..41, - value: BinOp( - ExprBinOp { - range: 36..41, - left: Name( - ExprName { - range: 36..37, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 40..41, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | a = pass = c - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here -2 | a + b -3 | a = b = pass = c - | - - - | -1 | a = pass = c -2 | a + b -3 | a = b = pass = c - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here -4 | a + b - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap.new deleted file mode 100644 index 84ee6df61f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap.new +++ /dev/null @@ -1,203 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_missing_rhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - Assign( - StmtAssign { - range: 0..3, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 4..9, - value: BinOp( - ExprBinOp { - range: 4..9, - left: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 10..17, - targets: [ - Name( - ExprName { - range: 10..11, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 14..15, - id: "y", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 17..17, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..23, - value: BinOp( - ExprBinOp { - range: 18..23, - left: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 22..23, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 24..31, - targets: [ - Name( - ExprName { - range: 24..25, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 27..27, - id: "", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 30..31, - id: "y", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 32..37, - value: BinOp( - ExprBinOp { - range: 32..37, - left: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 3, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 36..37, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x = - | ^ Syntax Error: Expected an expression -2 | 1 + 1 -3 | x = y = -4 | 2 + 2 - | - - - | -1 | x = -2 | 1 + 1 -3 | x = y = - | ^ Syntax Error: Expected an expression -4 | 2 + 2 -5 | x = = y -6 | 3 + 3 - | - - - | -3 | x = y = -4 | 2 + 2 -5 | x = = y - | ^ Syntax Error: Expected an expression -6 | 3 + 3 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap.new deleted file mode 100644 index bd10f4e301..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap.new +++ /dev/null @@ -1,203 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/async_unexpected_token.py ---- -## AST - -``` -Module( - ModModule { - range: 0..116, - body: [ - ClassDef( - StmtClassDef { - range: 6..20, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 12..15, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 17..20, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 17..20, - }, - ), - }, - ), - ], - }, - ), - While( - StmtWhile { - range: 27..42, - test: Name( - ExprName { - range: 33..37, - id: "test", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 39..42, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 39..42, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - Assign( - StmtAssign { - range: 49..54, - targets: [ - Name( - ExprName { - range: 49..50, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 53..54, - value: Int( - 1, - ), - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 61..81, - is_async: true, - decorator_list: [], - name: Identifier { - id: "foo", - range: 71..74, - }, - type_params: None, - parameters: Parameters { - range: 74..76, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 78..81, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 78..81, - }, - ), - }, - ), - ], - }, - ), - Match( - StmtMatch { - range: 88..115, - subject: Name( - ExprName { - range: 94..98, - id: "test", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 104..115, - pattern: MatchAs( - PatternMatchAs { - range: 109..110, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 112..115, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 112..115, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | async class Foo: ... - | ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'class' -2 | async while test: ... -3 | async x = 1 - | - - - | -1 | async class Foo: ... -2 | async while test: ... - | ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'while' -3 | async x = 1 -4 | async async def foo(): ... - | - - - | -1 | async class Foo: ... -2 | async while test: ... -3 | async x = 1 - | ^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found name -4 | async async def foo(): ... -5 | async match test: - | - - - | -2 | async while test: ... -3 | async x = 1 -4 | async async def foo(): ... - | ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'async' -5 | async match test: -6 | case _: ... - | - - - | -3 | async x = 1 -4 | async async def foo(): ... -5 | async match test: - | ^^^^^ Syntax Error: Expected 'def', 'with' or 'for' to follow 'async', found 'match' -6 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap.new deleted file mode 100644 index a8d62f8bcb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap.new +++ /dev/null @@ -1,233 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_invalid_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..59, - body: [ - AugAssign( - StmtAugAssign { - range: 0..6, - target: NumberLiteral( - ExprNumberLiteral { - range: 0..1, - value: Int( - 1, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 7..17, - target: StringLiteral( - ExprStringLiteral { - range: 7..10, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 7..10, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - op: Add, - value: StringLiteral( - ExprStringLiteral { - range: 14..17, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 14..17, - value: "b", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 18..25, - target: Starred( - ExprStarred { - range: 18..20, - value: Name( - ExprName { - range: 19..20, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 24..25, - value: Int( - 1, - ), - }, - ), - }, - ), - Pass( - StmtPass { - range: 26..30, - }, - ), - Expr( - StmtExpr { - range: 34..35, - value: NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 36..45, - target: Name( - ExprName { - range: 36..37, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Name( - ExprName { - range: 41..45, - id: "pass", - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 46..58, - target: BinOp( - ExprBinOp { - range: 47..52, - left: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 51..52, - id: "y", - ctx: Load, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 57..58, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | 1 += 1 - | ^ Syntax Error: Invalid augmented assignment target -2 | "a" += "b" -3 | *x += 1 - | - - - | -1 | 1 += 1 -2 | "a" += "b" - | ^^^ Syntax Error: Invalid augmented assignment target -3 | *x += 1 -4 | pass += 1 - | - - - | -1 | 1 += 1 -2 | "a" += "b" -3 | *x += 1 - | ^^ Syntax Error: Invalid augmented assignment target -4 | pass += 1 -5 | x += pass - | - - - | -2 | "a" += "b" -3 | *x += 1 -4 | pass += 1 - | ^^ Syntax Error: Expected a statement -5 | x += pass -6 | (x + y) += 1 - | - - - | -3 | *x += 1 -4 | pass += 1 -5 | x += pass - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here -6 | (x + y) += 1 - | - - - | -4 | pass += 1 -5 | x += pass -6 | (x + y) += 1 - | ^^^^^ Syntax Error: Invalid augmented assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap.new deleted file mode 100644 index f3cddf98b8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap.new +++ /dev/null @@ -1,252 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_invalid_value.py ---- -## AST - -``` -Module( - ModModule { - range: 0..77, - body: [ - AugAssign( - StmtAugAssign { - range: 0..13, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Starred( - ExprStarred { - range: 5..13, - value: BoolOp( - ExprBoolOp { - range: 6..13, - op: And, - values: [ - Name( - ExprName { - range: 6..7, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 12..13, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 14..27, - target: Name( - ExprName { - range: 14..15, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Starred( - ExprStarred { - range: 19..27, - value: Yield( - ExprYield { - range: 20..27, - value: Some( - Name( - ExprName { - range: 26..27, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 28..46, - target: Name( - ExprName { - range: 28..29, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Starred( - ExprStarred { - range: 33..46, - value: YieldFrom( - ExprYieldFrom { - range: 34..46, - value: Name( - ExprName { - range: 45..46, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 47..64, - target: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Starred( - ExprStarred { - range: 52..64, - value: Lambda( - ExprLambda { - range: 53..64, - parameters: Some( - Parameters { - range: 60..61, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 60..61, - parameter: Parameter { - range: 60..61, - name: Identifier { - id: "x", - range: 60..61, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 63..64, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 65..71, - target: Name( - ExprName { - range: 65..66, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Name( - ExprName { - range: 70..71, - id: "y", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 75..76, - value: NumberLiteral( - ExprNumberLiteral { - range: 75..76, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x += *a and b - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -2 | x += *yield x -3 | x += *yield from x - | - - - | -1 | x += *a and b -2 | x += *yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | x += *yield from x -4 | x += *lambda x: x - | - - - | -1 | x += *a and b -2 | x += *yield x -3 | x += *yield from x - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | x += *lambda x: x -5 | x += y := 1 - | - - - | -2 | x += *yield x -3 | x += *yield from x -4 | x += *lambda x: x - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -5 | x += y := 1 - | - - - | -3 | x += *yield from x -4 | x += *lambda x: x -5 | x += y := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap.new deleted file mode 100644 index 46481509e3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap.new +++ /dev/null @@ -1,137 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_missing_rhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..27, - body: [ - AugAssign( - StmtAugAssign { - range: 0..4, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Name( - ExprName { - range: 4..4, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 11..17, - target: Name( - ExprName { - range: 11..12, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: Name( - ExprName { - range: 16..17, - id: "y", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..26, - value: BinOp( - ExprBinOp { - range: 21..26, - left: NumberLiteral( - ExprNumberLiteral { - range: 21..22, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x += - | ^ Syntax Error: Expected an expression -2 | 1 + 1 -3 | x += y += -4 | 2 + 2 - | - - - | -1 | x += -2 | 1 + 1 -3 | x += y += - | ^^ Syntax Error: Expected a statement -4 | 2 + 2 - | - - - | -1 | x += -2 | 1 + 1 -3 | x += y += - | ^ Syntax Error: Expected a statement -4 | 2 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap.new deleted file mode 100644 index d09ecc7e05..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap.new +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/case_expect_indented_block.py ---- -## AST - -``` -Module( - ModModule { - range: 0..43, - body: [ - Match( - StmtMatch { - range: 0..42, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 19..26, - pattern: MatchValue( - PatternMatchValue { - range: 24..25, - value: NumberLiteral( - ExprNumberLiteral { - range: 24..25, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [], - }, - MatchCase { - range: 31..42, - pattern: MatchValue( - PatternMatchValue { - range: 36..37, - value: NumberLiteral( - ExprNumberLiteral { - range: 36..37, - value: Int( - 2, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 39..42, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 39..42, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match subject: -2 | case 1: -3 | case 2: ... - | ^^^^ Syntax Error: Expected an indented block after `case` block - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap.new deleted file mode 100644 index 3d601527c6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap.new +++ /dev/null @@ -1,86 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/class_def_empty_body.py ---- -## AST - -``` -Module( - ModModule { - range: 0..31, - body: [ - ClassDef( - StmtClassDef { - range: 0..10, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 6..9, - }, - type_params: None, - arguments: None, - body: [], - }, - ), - ClassDef( - StmtClassDef { - range: 11..23, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 17..20, - }, - type_params: None, - arguments: Some( - Arguments { - range: 20..22, - args: [], - keywords: [], - }, - ), - body: [], - }, - ), - Assign( - StmtAssign { - range: 24..30, - targets: [ - Name( - ExprName { - range: 24..25, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 28..30, - value: Int( - 42, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | class Foo: -2 | class Foo(): - | ^^^^^ Syntax Error: Expected an indented block after `class` definition -3 | x = 42 - | - - - | -1 | class Foo: -2 | class Foo(): -3 | x = 42 - | ^ Syntax Error: Expected an indented block after `class` definition - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap.new deleted file mode 100644 index 23a31082d3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap.new +++ /dev/null @@ -1,141 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/class_def_missing_name.py ---- -## AST - -``` -Module( - ModModule { - range: 0..53, - body: [ - ClassDef( - StmtClassDef { - range: 0..11, - decorator_list: [], - name: Identifier { - id: "", - range: 5..5, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 8..11, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 8..11, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 12..25, - decorator_list: [], - name: Identifier { - id: "", - range: 17..17, - }, - type_params: None, - arguments: Some( - Arguments { - range: 18..20, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 22..25, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 22..25, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 26..52, - decorator_list: [], - name: Identifier { - id: "", - range: 31..31, - }, - type_params: None, - arguments: Some( - Arguments { - range: 32..47, - args: [], - keywords: [ - Keyword { - range: 33..46, - arg: Some( - Identifier { - id: "metaclass", - range: 33..42, - }, - ), - value: Name( - ExprName { - range: 43..46, - id: "ABC", - ctx: Load, - }, - ), - }, - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 49..52, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 49..52, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | class : ... - | ^ Syntax Error: Expected an identifier -2 | class (): ... -3 | class (metaclass=ABC): ... - | - - - | -1 | class : ... -2 | class (): ... - | ^ Syntax Error: Expected an identifier -3 | class (metaclass=ABC): ... - | - - - | -1 | class : ... -2 | class (): ... -3 | class (metaclass=ABC): ... - | ^ Syntax Error: Expected an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap.new deleted file mode 100644 index 745d18d95f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap.new +++ /dev/null @@ -1,113 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/class_def_unclosed_type_param_list.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - ClassDef( - StmtClassDef { - range: 0..33, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 6..9, - }, - type_params: Some( - TypeParams { - range: 9..17, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 10..12, - name: Identifier { - id: "T1", - range: 10..12, - }, - bound: None, - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 14..17, - name: Identifier { - id: "T2", - range: 15..17, - }, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 17..23, - args: [ - Name( - ExprName { - range: 18..19, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 21..22, - id: "b", - ctx: Load, - }, - ), - ], - keywords: [], - }, - ), - body: [ - Pass( - StmtPass { - range: 29..33, - }, - ), - ], - }, - ), - Assign( - StmtAssign { - range: 34..40, - targets: [ - Name( - ExprName { - range: 34..35, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 38..40, - value: Int( - 10, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | class Foo[T1, *T2(a, b): - | ^ Syntax Error: Expected ']', found '(' -2 | pass -3 | x = 10 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap.new deleted file mode 100644 index 3fd56eb850..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap.new +++ /dev/null @@ -1,71 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..15, - body: [ - Expr( - StmtExpr { - range: 0..14, - value: Call( - ExprCall { - range: 0..14, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..14, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 12..13, - value: Int( - 1, - ), - }, - ), - ], - keywords: [ - Keyword { - range: 5..8, - arg: None, - value: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(**x := 1) - | ^^ Syntax Error: Expected ',', found ':=' - | - - - | -1 | call(**x := 1) - | ^ Syntax Error: Positional argument cannot follow keyword argument unpacking - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap.new deleted file mode 100644 index 302c3ce449..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap.new +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missing_first_element.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..9, - value: Call( - ExprCall { - range: 0..9, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..9, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 7..8, - value: Int( - 1, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(= 1) - | ^ Syntax Error: Expected an expression or a ')' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap.new deleted file mode 100644 index 8c16e1e992..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap.new +++ /dev/null @@ -1,81 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/comprehension_missing_for_after_async.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: Name( - ExprName { - range: 1..6, - id: "async", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..27, - value: Generator( - ExprGenerator { - range: 8..27, - elt: Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 11..26, - target: Name( - ExprName { - range: 17..18, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 22..26, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: true, - }, - ], - parenthesized: true, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | (async) - | ^^^^^ Syntax Error: Expected an identifier, but found a keyword 'async' that cannot be used here -2 | (x async x in iter) - | - - - | -1 | (async) -2 | (x async x in iter) - | ^ Syntax Error: Expected 'for', found name - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap.new deleted file mode 100644 index e4bc0434c7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap.new +++ /dev/null @@ -1,176 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/decorator_invalid_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..56, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..55, - is_async: false, - decorator_list: [ - Decorator { - range: 0..3, - expression: Starred( - ExprStarred { - range: 1..3, - value: Name( - ExprName { - range: 2..3, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - Decorator { - range: 4..9, - expression: Starred( - ExprStarred { - range: 6..8, - value: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - Decorator { - range: 10..17, - expression: Starred( - ExprStarred { - range: 13..15, - value: Name( - ExprName { - range: 14..15, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - Decorator { - range: 18..26, - expression: Yield( - ExprYield { - range: 19..26, - value: Some( - Name( - ExprName { - range: 25..26, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - Decorator { - range: 27..40, - expression: YieldFrom( - ExprYieldFrom { - range: 28..40, - value: Name( - ExprName { - range: 39..40, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 45..48, - }, - type_params: None, - parameters: Parameters { - range: 48..50, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 52..55, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 52..55, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | @*x - | ^^ Syntax Error: Starred expression cannot be used here -2 | @(*x) -3 | @((*x)) - | - - - | -1 | @*x -2 | @(*x) - | ^^ Syntax Error: Starred expression cannot be used here -3 | @((*x)) -4 | @yield x - | - - - | -1 | @*x -2 | @(*x) -3 | @((*x)) - | ^^ Syntax Error: Starred expression cannot be used here -4 | @yield x -5 | @yield from x - | - - - | -2 | @(*x) -3 | @((*x)) -4 | @yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | @yield from x -6 | def foo(): ... - | - - - | -3 | @((*x)) -4 | @yield x -5 | @yield from x - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -6 | def foo(): ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap.new deleted file mode 100644 index bf4b099b11..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap.new +++ /dev/null @@ -1,190 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..51, - body: [ - AnnAssign( - StmtAnnAssign { - range: 5..15, - target: Call( - ExprCall { - range: 5..10, - func: Name( - ExprName { - range: 5..8, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 8..10, - args: [], - keywords: [], - }, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 12..15, - }, - ), - value: None, - simple: false, - }, - ), - FunctionDef( - StmtFunctionDef { - range: 16..32, - is_async: false, - decorator_list: [ - Decorator { - range: 16..17, - expression: Name( - ExprName { - range: 17..17, - id: "", - ctx: Invalid, - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 22..25, - }, - type_params: None, - parameters: Parameters { - range: 25..27, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 33..50, - is_async: false, - decorator_list: [ - Decorator { - range: 33..35, - expression: BinOp( - ExprBinOp { - range: 34..35, - left: Name( - ExprName { - range: 34..34, - id: "", - ctx: Invalid, - }, - ), - op: MatMult, - right: Name( - ExprName { - range: 35..35, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 40..43, - }, - type_params: None, - parameters: Parameters { - range: 43..45, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 47..50, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 47..50, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | @def foo(): ... - | ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here -2 | @ -3 | def foo(): ... - | - - - | -1 | @def foo(): ... - | ^^^ Syntax Error: Expected newline, found name -2 | @ -3 | def foo(): ... - | - - - | -1 | @def foo(): ... -2 | @ - | ^ Syntax Error: Expected an expression -3 | def foo(): ... -4 | @@ -5 | def foo(): ... - | - - - | -2 | @ -3 | def foo(): ... -4 | @@ - | ^ Syntax Error: Expected an expression -5 | def foo(): ... - | - - - | -2 | @ -3 | def foo(): ... -4 | @@ - | ^ Syntax Error: Expected an expression -5 | def foo(): ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap.new deleted file mode 100644 index a72e950cb6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap.new +++ /dev/null @@ -1,163 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_newline.py ---- -## AST - -``` -Module( - ModModule { - range: 0..60, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..17, - is_async: false, - decorator_list: [ - Decorator { - range: 0..2, - expression: Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 7..10, - }, - type_params: None, - parameters: Parameters { - range: 10..12, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 14..17, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 14..17, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 18..41, - is_async: true, - decorator_list: [ - Decorator { - range: 18..20, - expression: Name( - ExprName { - range: 19..20, - id: "x", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 31..34, - }, - type_params: None, - parameters: Parameters { - range: 34..36, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 38..41, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 38..41, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 42..59, - decorator_list: [ - Decorator { - range: 42..44, - expression: Name( - ExprName { - range: 43..44, - id: "x", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "Foo", - range: 51..54, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 56..59, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 56..59, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | @x def foo(): ... - | ^^^ Syntax Error: Expected newline, found 'def' -2 | @x async def foo(): ... -3 | @x class Foo: ... - | - - - | -1 | @x def foo(): ... -2 | @x async def foo(): ... - | ^^^^^ Syntax Error: Expected newline, found 'async' -3 | @x class Foo: ... - | - - - | -1 | @x def foo(): ... -2 | @x async def foo(): ... -3 | @x class Foo: ... - | ^^^^^ Syntax Error: Expected newline, found 'class' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap.new deleted file mode 100644 index 1d329e2332..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap.new +++ /dev/null @@ -1,86 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/decorator_unexpected_token.py ---- -## AST - -``` -Module( - ModModule { - range: 0..34, - body: [ - With( - StmtWith { - range: 5..22, - is_async: true, - items: [ - WithItem { - range: 16..17, - context_expr: Name( - ExprName { - range: 16..17, - id: "x", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ), - Assign( - StmtAssign { - range: 28..33, - targets: [ - Name( - ExprName { - range: 28..29, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | @foo -2 | async with x: ... - | ^^^^^ Syntax Error: Expected class, function definition or async function definition after decorator -3 | @foo -4 | x = 1 - | - - - | -2 | async with x: ... -3 | @foo -4 | x = 1 - | ^ Syntax Error: Expected class, function definition or async function definition after decorator - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap.new deleted file mode 100644 index 05a6d6f43a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap.new +++ /dev/null @@ -1,125 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/del_incomplete_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Delete( - StmtDelete { - range: 0..9, - targets: [ - Name( - ExprName { - range: 4..5, - id: "x", - ctx: Del, - }, - ), - Attribute( - ExprAttribute { - range: 7..9, - value: Name( - ExprName { - range: 7..8, - id: "y", - ctx: Load, - }, - ), - attr: Identifier { - id: "", - range: 9..9, - }, - ctx: Del, - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 10..11, - value: Name( - ExprName { - range: 10..11, - id: "z", - ctx: Load, - }, - ), - }, - ), - Delete( - StmtDelete { - range: 12..24, - targets: [ - Name( - ExprName { - range: 16..17, - id: "x", - ctx: Del, - }, - ), - Subscript( - ExprSubscript { - range: 19..23, - value: Name( - ExprName { - range: 19..20, - id: "y", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 22..23, - lower: Some( - Name( - ExprName { - range: 22..23, - id: "z", - ctx: Load, - }, - ), - ), - upper: Some( - Name( - ExprName { - range: 23..23, - id: "", - ctx: Invalid, - }, - ), - ), - step: None, - }, - ), - ctx: Del, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | del x, y. - | ^ Syntax Error: Expected an identifier -2 | z -3 | del x, y[ -4 | z - | - - - | -3 | del x, y[ -4 | z - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap.new deleted file mode 100644 index e5b2d546fe..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap.new +++ /dev/null @@ -1,89 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/dotted_name_multiple_dots.py ---- -## AST - -``` -Module( - ModModule { - range: 0..25, - body: [ - Import( - StmtImport { - range: 0..11, - names: [ - Alias { - range: 7..11, - name: Identifier { - id: "a..b", - range: 7..11, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 12..20, - names: [ - Alias { - range: 19..20, - name: Identifier { - id: "a", - range: 19..20, - }, - asname: None, - }, - ], - }, - ), - Expr( - StmtExpr { - range: 20..23, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 20..23, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 23..24, - value: Name( - ExprName { - range: 23..24, - id: "b", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | import a..b - | ^ Syntax Error: Expected an identifier -2 | import a...b - | - - - | -1 | import a..b -2 | import a...b - | ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -1 | import a..b -2 | import a...b - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap.new deleted file mode 100644 index fe6747f223..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap.new +++ /dev/null @@ -1,126 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_invalid_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..74, - body: [ - Try( - StmtTry { - range: 0..38, - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 14..38, - type_: Some( - Yield( - ExprYield { - range: 21..28, - value: Some( - Name( - ExprName { - range: 27..28, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 34..38, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 39..73, - body: [ - Pass( - StmtPass { - range: 48..52, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 53..73, - type_: Some( - Starred( - ExprStarred { - range: 61..63, - value: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 69..73, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | try: -2 | pass -3 | except yield x: - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | pass -5 | try: - | - - - | -5 | try: -6 | pass -7 | except* *x: - | ^^ Syntax Error: Starred expression cannot be used here -8 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap.new deleted file mode 100644 index 7273e97409..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap.new +++ /dev/null @@ -1,96 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_as_name.py ---- -## AST - -``` -Module( - ModModule { - range: 0..73, - body: [ - Try( - StmtTry { - range: 0..72, - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 14..43, - type_: Some( - Name( - ExprName { - range: 21..30, - id: "Exception", - ctx: Load, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 39..43, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 44..72, - type_: Some( - Name( - ExprName { - range: 51..60, - id: "Exception", - ctx: Load, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 68..72, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | try: -2 | pass -3 | except Exception as: - | ^ Syntax Error: Expected name after `as` -4 | pass -5 | except Exception as - | - - - | -3 | except Exception as: -4 | pass -5 | except Exception as - | ^ Syntax Error: Expected name after `as` -6 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap.new deleted file mode 100644 index 9a7a1289fb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap.new +++ /dev/null @@ -1,156 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_exception.py ---- -## AST - -``` -Module( - ModModule { - range: 0..166, - body: [ - Try( - StmtTry { - range: 0..37, - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 14..37, - type_: None, - name: Some( - Identifier { - id: "exc", - range: 24..27, - }, - ), - body: [ - Pass( - StmtPass { - range: 33..37, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 92..165, - body: [ - Pass( - StmtPass { - range: 101..105, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 106..123, - type_: None, - name: None, - body: [ - Pass( - StmtPass { - range: 119..123, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 124..140, - type_: None, - name: None, - body: [ - Pass( - StmtPass { - range: 136..140, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 141..165, - type_: None, - name: Some( - Identifier { - id: "exc", - range: 152..155, - }, - ), - body: [ - Pass( - StmtPass { - range: 161..165, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | try: -2 | pass -3 | except as exc: - | ^^ Syntax Error: Expected one or more exception types -4 | pass -5 | # If a '*' is present then exception type is required - | - - - | - 6 | try: - 7 | pass - 8 | except*: - | ^ Syntax Error: Expected one or more exception types - 9 | pass -10 | except* - | - - - | - 8 | except*: - 9 | pass -10 | except* - | ^ Syntax Error: Expected one or more exception types -11 | pass -12 | except* as exc: -13 | pass - | - - - | -10 | except* -11 | pass -12 | except* as exc: - | ^^ Syntax Error: Expected one or more exception types -13 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple.py.snap.new deleted file mode 100644 index d202c552ba..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple.py.snap.new +++ /dev/null @@ -1,251 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenthesized_tuple.py ---- -## AST - -``` -Module( - ModModule { - range: 0..131, - body: [ - Try( - StmtTry { - range: 0..64, - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 14..35, - type_: Some( - Tuple( - ExprTuple { - range: 21..25, - elts: [ - Name( - ExprName { - range: 21..22, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 24..25, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 31..35, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 36..64, - type_: Some( - Tuple( - ExprTuple { - range: 43..47, - elts: [ - Name( - ExprName { - range: 43..44, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 46..47, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - name: Some( - Identifier { - id: "exc", - range: 51..54, - }, - ), - body: [ - Pass( - StmtPass { - range: 60..64, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 65..130, - body: [ - Pass( - StmtPass { - range: 74..78, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 79..101, - type_: Some( - Tuple( - ExprTuple { - range: 87..91, - elts: [ - Name( - ExprName { - range: 87..88, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 90..91, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 97..101, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 102..130, - type_: Some( - Tuple( - ExprTuple { - range: 110..114, - elts: [ - Name( - ExprName { - range: 110..111, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 113..114, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - name: Some( - Identifier { - id: "eg", - range: 118..120, - }, - ), - body: [ - Pass( - StmtPass { - range: 126..130, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | try: -2 | pass -3 | except x, y: - | ^^^^ Syntax Error: Multiple exception types must be parenthesized -4 | pass -5 | except x, y as exc: - | - - - | -3 | except x, y: -4 | pass -5 | except x, y as exc: - | ^^^^ Syntax Error: Multiple exception types must be parenthesized -6 | pass -7 | try: - | - - - | - 7 | try: - 8 | pass - 9 | except* x, y: - | ^^^^ Syntax Error: Multiple exception types must be parenthesized -10 | pass -11 | except* x, y as eg: - | - - - | - 9 | except* x, y: -10 | pass -11 | except* x, y as eg: - | ^^^^ Syntax Error: Multiple exception types must be parenthesized -12 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap.new deleted file mode 100644 index e2926cf14d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap.new +++ /dev/null @@ -1,222 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/double_starred.py ---- -## AST - -``` -Module( - ModModule { - range: 0..55, - body: [ - Expr( - StmtExpr { - range: 0..15, - value: Call( - ExprCall { - range: 0..15, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..15, - args: [], - keywords: [ - Keyword { - range: 5..14, - arg: None, - value: Yield( - ExprYield { - range: 7..14, - value: Some( - Name( - ExprName { - range: 13..14, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..27, - value: Call( - ExprCall { - range: 16..27, - func: Name( - ExprName { - range: 16..20, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 20..27, - args: [], - keywords: [ - Keyword { - range: 21..26, - arg: None, - value: Starred( - ExprStarred { - range: 24..26, - value: Name( - ExprName { - range: 25..26, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..38, - value: Call( - ExprCall { - range: 28..38, - func: Name( - ExprName { - range: 28..32, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 32..38, - args: [], - keywords: [ - Keyword { - range: 33..37, - arg: None, - value: Starred( - ExprStarred { - range: 35..37, - value: Name( - ExprName { - range: 36..37, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 40..54, - value: Call( - ExprCall { - range: 40..54, - func: Name( - ExprName { - range: 40..44, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 44..54, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 52..53, - value: Int( - 1, - ), - }, - ), - ], - keywords: [ - Keyword { - range: 45..48, - arg: None, - value: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(**yield x) - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -2 | call(** *x) -3 | call(***x) - | - - - | -1 | call(**yield x) -2 | call(** *x) - | ^^ Syntax Error: Starred expression cannot be used here -3 | call(***x) - | - - - | -1 | call(**yield x) -2 | call(** *x) -3 | call(***x) - | ^^ Syntax Error: Starred expression cannot be used here -4 | -5 | call(**x := 1) - | - - - | -3 | call(***x) -4 | -5 | call(**x := 1) - | ^^ Syntax Error: Expected ',', found ':=' - | - - - | -3 | call(***x) -4 | -5 | call(**x := 1) - | ^ Syntax Error: Positional argument cannot follow keyword argument unpacking - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap.new deleted file mode 100644 index 724540963a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap.new +++ /dev/null @@ -1,136 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/duplicate_keyword_arguments.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Expr( - StmtExpr { - range: 0..28, - value: Call( - ExprCall { - range: 0..28, - func: Name( - ExprName { - range: 0..3, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3..28, - args: [], - keywords: [ - Keyword { - range: 4..7, - arg: Some( - Identifier { - id: "a", - range: 4..5, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 6..7, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 9..12, - arg: Some( - Identifier { - id: "b", - range: 9..10, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 2, - ), - }, - ), - }, - Keyword { - range: 14..17, - arg: Some( - Identifier { - id: "c", - range: 14..15, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 3, - ), - }, - ), - }, - Keyword { - range: 19..22, - arg: Some( - Identifier { - id: "b", - range: 19..20, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 21..22, - value: Int( - 4, - ), - }, - ), - }, - Keyword { - range: 24..27, - arg: Some( - Identifier { - id: "a", - range: 24..25, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 26..27, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | foo(a=1, b=2, c=3, b=4, a=5) - | ^^^ Syntax Error: Duplicate keyword argument "b" - | - - - | -1 | foo(a=1, b=2, c=3, b=4, a=5) - | ^^^ Syntax Error: Duplicate keyword argument "a" - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap.new deleted file mode 100644 index ce4db56e33..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap.new +++ /dev/null @@ -1,200 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - Expr( - StmtExpr { - range: 0..15, - value: Call( - ExprCall { - range: 0..15, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..15, - args: [], - keywords: [ - Keyword { - range: 5..14, - arg: Some( - Identifier { - id: "", - range: 5..10, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..32, - value: Call( - ExprCall { - range: 16..32, - func: Name( - ExprName { - range: 16..20, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 20..32, - args: [], - keywords: [ - Keyword { - range: 21..31, - arg: Some( - Identifier { - id: "", - range: 21..27, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 30..31, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 34..47, - value: Call( - ExprCall { - range: 34..47, - func: Name( - ExprName { - range: 34..38, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 38..47, - args: [ - Yield( - ExprYield { - range: 39..46, - value: Some( - Name( - ExprName { - range: 45..46, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 48..66, - value: Call( - ExprCall { - range: 48..66, - func: Name( - ExprName { - range: 48..52, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 52..66, - args: [ - YieldFrom( - ExprYieldFrom { - range: 53..65, - value: Name( - ExprName { - range: 64..65, - id: "x", - ctx: Load, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x + y = 1) - | ^^^^^ Syntax Error: Expected a parameter name -2 | call(x := 1 = 1) - | - - - | -1 | call(x + y = 1) -2 | call(x := 1 = 1) - | ^^^^^^ Syntax Error: Expected a parameter name -3 | -4 | call(yield x) - | - - - | -2 | call(x := 1 = 1) -3 | -4 | call(yield x) - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | call(yield from x) - | - - - | -4 | call(yield x) -5 | call(yield from x) - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap.new deleted file mode 100644 index 018f760327..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap.new +++ /dev/null @@ -1,230 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_keyword_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..69, - body: [ - Expr( - StmtExpr { - range: 0..17, - value: Call( - ExprCall { - range: 0..17, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..17, - args: [], - keywords: [ - Keyword { - range: 5..16, - arg: Some( - Identifier { - id: "x", - range: 5..6, - }, - ), - value: Yield( - ExprYield { - range: 9..16, - value: Some( - Name( - ExprName { - range: 15..16, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..40, - value: Call( - ExprCall { - range: 18..40, - func: Name( - ExprName { - range: 18..22, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 22..40, - args: [], - keywords: [ - Keyword { - range: 23..39, - arg: Some( - Identifier { - id: "x", - range: 23..24, - }, - ), - value: YieldFrom( - ExprYieldFrom { - range: 27..39, - value: Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 41..53, - value: Call( - ExprCall { - range: 41..53, - func: Name( - ExprName { - range: 41..45, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 45..53, - args: [], - keywords: [ - Keyword { - range: 46..52, - arg: Some( - Identifier { - id: "x", - range: 46..47, - }, - ), - value: Starred( - ExprStarred { - range: 50..52, - value: Name( - ExprName { - range: 51..52, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 54..68, - value: Call( - ExprCall { - range: 54..68, - func: Name( - ExprName { - range: 54..58, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 58..68, - args: [], - keywords: [ - Keyword { - range: 59..67, - arg: Some( - Identifier { - id: "x", - range: 59..60, - }, - ), - value: Starred( - ExprStarred { - range: 64..66, - value: Name( - ExprName { - range: 65..66, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x = yield y) - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -2 | call(x = yield from y) -3 | call(x = *y) - | - - - | -1 | call(x = yield y) -2 | call(x = yield from y) - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | call(x = *y) -4 | call(x = (*y)) - | - - - | -1 | call(x = yield y) -2 | call(x = yield from y) -3 | call(x = *y) - | ^^ Syntax Error: Starred expression cannot be used here -4 | call(x = (*y)) - | - - - | -2 | call(x = yield from y) -3 | call(x = *y) -4 | call(x = (*y)) - | ^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap.new deleted file mode 100644 index 2c32eb2136..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap.new +++ /dev/null @@ -1,305 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/invalid_order.py ---- -## AST - -``` -Module( - ModModule { - range: 0..100, - body: [ - Expr( - StmtExpr { - range: 0..17, - value: Call( - ExprCall { - range: 0..17, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..17, - args: [ - Name( - ExprName { - range: 15..16, - id: "x", - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 5..13, - arg: None, - value: Name( - ExprName { - range: 7..13, - id: "kwargs", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..30, - value: Call( - ExprCall { - range: 18..30, - func: Name( - ExprName { - range: 18..22, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 22..30, - args: [ - Name( - ExprName { - range: 28..29, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 23..26, - arg: Some( - Identifier { - id: "x", - range: 23..24, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 31..53, - value: Call( - ExprCall { - range: 31..53, - func: Name( - ExprName { - range: 31..35, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 35..53, - args: [ - Name( - ExprName { - range: 51..52, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 36..39, - arg: Some( - Identifier { - id: "x", - range: 36..37, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 38..39, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 41..49, - arg: None, - value: Name( - ExprName { - range: 43..49, - id: "kwargs", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 54..75, - value: Call( - ExprCall { - range: 54..75, - func: Name( - ExprName { - range: 54..58, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 58..75, - args: [ - Starred( - ExprStarred { - range: 69..74, - value: Name( - ExprName { - range: 70..74, - id: "args", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 59..67, - arg: None, - value: Name( - ExprName { - range: 61..67, - id: "kwargs", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 76..99, - value: Call( - ExprCall { - range: 76..99, - func: Name( - ExprName { - range: 76..80, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 80..99, - args: [ - Starred( - ExprStarred { - range: 92..97, - value: Name( - ExprName { - range: 93..97, - id: "args", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 81..89, - arg: None, - value: Name( - ExprName { - range: 83..89, - id: "kwargs", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(**kwargs, x) - | ^ Syntax Error: Positional argument cannot follow keyword argument unpacking -2 | call(x=1, y) -3 | call(x=1, **kwargs, y) - | - - - | -1 | call(**kwargs, x) -2 | call(x=1, y) - | ^ Syntax Error: Positional argument cannot follow keyword argument -3 | call(x=1, **kwargs, y) -4 | call(**kwargs, *args) - | - - - | -1 | call(**kwargs, x) -2 | call(x=1, y) -3 | call(x=1, **kwargs, y) - | ^ Syntax Error: Positional argument cannot follow keyword argument unpacking -4 | call(**kwargs, *args) -5 | call(**kwargs, (*args)) - | - - - | -2 | call(x=1, y) -3 | call(x=1, **kwargs, y) -4 | call(**kwargs, *args) - | ^^^^^ Syntax Error: Iterable argument unpacking cannot follow keyword argument unpacking -5 | call(**kwargs, (*args)) - | - - - | -3 | call(x=1, **kwargs, y) -4 | call(**kwargs, *args) -5 | call(**kwargs, (*args)) - | ^^^^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap.new deleted file mode 100644 index 1889fb72d4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap.new +++ /dev/null @@ -1,59 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_argument.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Call( - ExprCall { - range: 0..10, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..10, - args: [ - Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 8..9, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x,,y) - | ^ Syntax Error: Expected an expression or a ')' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap.new deleted file mode 100644 index 6578ebd69d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap.new +++ /dev/null @@ -1,59 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..9, - body: [ - Expr( - StmtExpr { - range: 0..9, - value: Call( - ExprCall { - range: 0..9, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..9, - args: [ - Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 7..8, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x y) - | ^ Syntax Error: Expected ',', found name - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap.new deleted file mode 100644 index a0f2d5d727..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap.new +++ /dev/null @@ -1,167 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/missing_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Call( - ExprCall { - range: 0..10, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..10, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 1, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..21, - value: Call( - ExprCall { - range: 11..21, - func: Name( - ExprName { - range: 11..15, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 15..21, - args: [], - keywords: [ - Keyword { - range: 16..19, - arg: Some( - Identifier { - id: "x", - range: 16..17, - }, - ), - value: Name( - ExprName { - range: 19..19, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..32, - value: Call( - ExprCall { - range: 22..32, - func: Name( - ExprName { - range: 22..26, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 26..32, - args: [ - Starred( - ExprStarred { - range: 27..28, - value: Name( - ExprName { - range: 28..28, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 30..31, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 34..37, - value: Name( - ExprName { - range: 34..37, - id: "foo", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call( = 1) - | ^ Syntax Error: Expected an expression or a ')' -2 | call(x = ) -3 | call(*, y) - | - - - | -1 | call( = 1) -2 | call(x = ) - | ^ Syntax Error: Expected an expression -3 | call(*, y) - | - - - | -1 | call( = 1) -2 | call(x = ) -3 | call(*, y) - | ^ Syntax Error: Expected an expression -4 | -5 | foo - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap.new deleted file mode 100644 index 6baaa53d95..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap.new +++ /dev/null @@ -1,187 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/starred.py ---- -## AST - -``` -Module( - ModModule { - range: 0..64, - body: [ - Expr( - StmtExpr { - range: 0..28, - value: Call( - ExprCall { - range: 0..28, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..28, - args: [ - Generator( - ExprGenerator { - range: 5..27, - elt: Starred( - ExprStarred { - range: 5..10, - value: Name( - ExprName { - range: 6..10, - id: "data", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 11..27, - target: Name( - ExprName { - range: 15..19, - id: "data", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 23..27, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 29..43, - value: Call( - ExprCall { - range: 29..43, - func: Name( - ExprName { - range: 29..33, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 33..43, - args: [ - Starred( - ExprStarred { - range: 34..42, - value: Yield( - ExprYield { - range: 35..42, - value: Some( - Name( - ExprName { - range: 41..42, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 44..63, - value: Call( - ExprCall { - range: 44..63, - func: Name( - ExprName { - range: 44..48, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 48..63, - args: [ - Starred( - ExprStarred { - range: 49..62, - value: YieldFrom( - ExprYieldFrom { - range: 50..62, - value: Name( - ExprName { - range: 61..62, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(*data for data in iter) - | ^^^^^ Syntax Error: Iterable unpacking cannot be used in a comprehension -2 | call(*yield x) -3 | call(*yield from x) - | - - - | -1 | call(*data for data in iter) -2 | call(*yield x) - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | call(*yield from x) - | - - - | -1 | call(*data for data in iter) -2 | call(*yield x) -3 | call(*yield from x) - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap.new deleted file mode 100644 index 9e82d2885c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap.new +++ /dev/null @@ -1,75 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..26, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: Call( - ExprCall { - range: 0..5, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..5, - args: [], - keywords: [], - }, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 7..26, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 11..14, - }, - type_params: None, - parameters: Parameters { - range: 14..16, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 22..26, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call( - | ^ Syntax Error: Expected ')', found newline -2 | -3 | def foo(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap.new deleted file mode 100644 index 800c4be1dc..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap.new +++ /dev/null @@ -1,83 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..27, - body: [ - Expr( - StmtExpr { - range: 0..6, - value: Call( - ExprCall { - range: 0..6, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..6, - args: [ - Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 8..27, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 12..15, - }, - type_params: None, - parameters: Parameters { - range: 15..17, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 23..27, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x - | ^ Syntax Error: Expected ')', found newline -2 | -3 | def foo(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap.new deleted file mode 100644 index 1e496038dd..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap.new +++ /dev/null @@ -1,83 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/unclosed_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: Call( - ExprCall { - range: 0..7, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..7, - args: [ - Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 9..28, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 13..16, - }, - type_params: None, - parameters: Parameters { - range: 16..18, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 24..28, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(x, - | ^ Syntax Error: Expected ')', found newline -2 | -3 | def foo(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap.new deleted file mode 100644 index 01b8a595d8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap.new +++ /dev/null @@ -1,147 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/invalid_member.py ---- -## AST - -``` -Module( - ModModule { - range: 0..16, - body: [ - Expr( - StmtExpr { - range: 0..1, - value: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1..3, - value: NumberLiteral( - ExprNumberLiteral { - range: 1..3, - value: Float( - 0.1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 4..5, - value: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..7, - value: NumberLiteral( - ExprNumberLiteral { - range: 5..7, - value: Float( - 0.1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 7..9, - value: NumberLiteral( - ExprNumberLiteral { - range: 7..9, - value: Float( - 0.0, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..15, - value: Subscript( - ExprSubscript { - range: 10..15, - value: Attribute( - ExprAttribute { - range: 10..12, - value: Name( - ExprName { - range: 10..11, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "", - range: 12..12, - }, - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x.1 - | ^^ Syntax Error: Simple statements must be separated by newlines or semicolons -2 | x.1.0 -3 | x.[0] - | - - - | -1 | x.1 -2 | x.1.0 - | ^^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | x.[0] - | - - - | -1 | x.1 -2 | x.1.0 - | ^^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | x.[0] - | - - - | -1 | x.1 -2 | x.1.0 -3 | x.[0] - | ^ Syntax Error: Expected an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap.new deleted file mode 100644 index 76b9792ca1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap.new +++ /dev/null @@ -1,154 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/multiple_dots.py ---- -## AST - -``` -Module( - ModModule { - range: 0..46, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Attribute( - ExprAttribute { - range: 0..10, - value: Attribute( - ExprAttribute { - range: 0..6, - value: Name( - ExprName { - range: 0..5, - id: "extra", - ctx: Load, - }, - ), - attr: Identifier { - id: "", - range: 6..6, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "dot", - range: 7..10, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..19, - value: Name( - ExprName { - range: 11..19, - id: "multiple", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 19..27, - value: Attribute( - ExprAttribute { - range: 19..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - attr: Identifier { - id: "dots", - range: 23..27, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..36, - value: Name( - ExprName { - range: 28..36, - id: "multiple", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 36..45, - value: Attribute( - ExprAttribute { - range: 36..45, - value: Attribute( - ExprAttribute { - range: 36..40, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 36..39, - }, - ), - attr: Identifier { - id: "", - range: 40..40, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "dots", - range: 41..45, - }, - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | extra..dot - | ^ Syntax Error: Expected an identifier -2 | multiple....dots -3 | multiple.....dots - | - - - | -1 | extra..dot -2 | multiple....dots - | ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | multiple.....dots - | - - - | -1 | extra..dot -2 | multiple....dots -3 | multiple.....dots - | ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -1 | extra..dot -2 | multiple....dots -3 | multiple.....dots - | ^ Syntax Error: Expected an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap.new deleted file mode 100644 index a6b01d10fc..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap.new +++ /dev/null @@ -1,89 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/no_member.py ---- -## AST - -``` -Module( - ModModule { - range: 0..141, - body: [ - Expr( - StmtExpr { - range: 87..93, - value: Attribute( - ExprAttribute { - range: 87..93, - value: Name( - ExprName { - range: 87..92, - id: "first", - ctx: Load, - }, - ), - attr: Identifier { - id: "", - range: 93..93, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 94..100, - value: Name( - ExprName { - range: 94..100, - id: "second", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 136..141, - value: Attribute( - ExprAttribute { - range: 136..141, - value: Name( - ExprName { - range: 136..140, - id: "last", - ctx: Load, - }, - ), - attr: Identifier { - id: "", - range: 141..141, - }, - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # The `second` is a variable on another line and not part of the attribute expression. -2 | first. - | ^ Syntax Error: Expected an identifier -3 | second -4 | -5 | # No member access after the dot. - | - - - | -5 | # No member access after the dot. -6 | last. - | Syntax Error: Expected an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap.new deleted file mode 100644 index e79611fb3c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap.new +++ /dev/null @@ -1,67 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_expression_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..73, - body: [ - Expr( - StmtExpr { - range: 61..66, - value: Await( - ExprAwait { - range: 61..66, - value: Name( - ExprName { - range: 66..66, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 68..73, - value: BinOp( - ExprBinOp { - range: 68..73, - left: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 72..73, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # No expression after `await`, an expression on another line -2 | await - | ^ Syntax Error: Expected an expression -3 | -4 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap.new deleted file mode 100644 index 37bd077bd6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap.new +++ /dev/null @@ -1,71 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_expression_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..85, - body: [ - Expr( - StmtExpr { - range: 59..64, - value: Await( - ExprAwait { - range: 59..64, - value: Name( - ExprName { - range: 64..64, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 66..85, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 70..73, - }, - type_params: None, - parameters: Parameters { - range: 73..75, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 81..85, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # No expression after `await`, a statement on another line -2 | await - | ^ Syntax Error: Expected an expression -3 | -4 | def foo(): -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap.new deleted file mode 100644 index 3acf38365f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap.new +++ /dev/null @@ -1,328 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/await/recover.py ---- -## AST - -``` -Module( - ModModule { - range: 0..284, - body: [ - Expr( - StmtExpr { - range: 117..130, - value: Await( - ExprAwait { - range: 117..130, - value: Await( - ExprAwait { - range: 123..130, - value: Name( - ExprName { - range: 129..130, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 154..162, - value: Await( - ExprAwait { - range: 154..162, - value: Starred( - ExprStarred { - range: 160..162, - value: Name( - ExprName { - range: 161..162, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 163..173, - value: Await( - ExprAwait { - range: 163..173, - value: Starred( - ExprStarred { - range: 170..172, - value: Name( - ExprName { - range: 171..172, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 214..227, - value: Await( - ExprAwait { - range: 214..227, - value: Yield( - ExprYield { - range: 220..227, - value: Some( - Name( - ExprName { - range: 226..227, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 228..245, - value: Await( - ExprAwait { - range: 228..245, - value: Lambda( - ExprLambda { - range: 234..245, - parameters: Some( - Parameters { - range: 241..242, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 241..242, - parameter: Parameter { - range: 241..242, - name: Identifier { - id: "x", - range: 241..242, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 244..245, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 246..254, - value: Await( - ExprAwait { - range: 246..254, - value: UnaryOp( - ExprUnaryOp { - range: 252..254, - op: UAdd, - operand: Name( - ExprName { - range: 253..254, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 255..263, - value: Await( - ExprAwait { - range: 255..263, - value: UnaryOp( - ExprUnaryOp { - range: 261..263, - op: USub, - operand: Name( - ExprName { - range: 262..263, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 264..272, - value: Await( - ExprAwait { - range: 264..272, - value: UnaryOp( - ExprUnaryOp { - range: 270..272, - op: Invert, - operand: Name( - ExprName { - range: 271..272, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 273..284, - value: Await( - ExprAwait { - range: 273..284, - value: UnaryOp( - ExprUnaryOp { - range: 279..284, - op: Not, - operand: Name( - ExprName { - range: 283..284, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | # Nested await -5 | await await x - | ^^^^^^^ Syntax Error: Await expression cannot be used here -6 | -7 | # Starred expressions - | - - - | -7 | # Starred expressions -8 | await *x - | ^^ Syntax Error: Starred expression cannot be used here -9 | await (*x) - | - - - | - 7 | # Starred expressions - 8 | await *x - 9 | await (*x) - | ^^ Syntax Error: Starred expression cannot be used here -10 | -11 | # Invalid expression as per precedence - | - - - | -11 | # Invalid expression as per precedence -12 | await yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -13 | await lambda x: x -14 | await +x - | - - - | -11 | # Invalid expression as per precedence -12 | await yield x -13 | await lambda x: x - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -14 | await +x -15 | await -x - | - - - | -12 | await yield x -13 | await lambda x: x -14 | await +x - | ^^ Syntax Error: Unary '+' expression cannot be used here -15 | await -x -16 | await ~x - | - - - | -13 | await lambda x: x -14 | await +x -15 | await -x - | ^^ Syntax Error: Unary '-' expression cannot be used here -16 | await ~x -17 | await not x - | - - - | -14 | await +x -15 | await -x -16 | await ~x - | ^^ Syntax Error: Unary '~' expression cannot be used here -17 | await not x - | - - - | -15 | await -x -16 | await ~x -17 | await not x - | ^^^^^ Syntax Error: Boolean 'not' expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap.new deleted file mode 100644 index 191ee32490..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap.new +++ /dev/null @@ -1,117 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/invalid_rhs_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Expr( - StmtExpr { - range: 0..15, - value: BinOp( - ExprBinOp { - range: 0..15, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Lambda( - ExprLambda { - range: 4..15, - parameters: Some( - Parameters { - range: 11..12, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 11..12, - parameter: Parameter { - range: 11..12, - name: Identifier { - id: "y", - range: 11..12, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 14..15, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 17..28, - value: BinOp( - ExprBinOp { - range: 17..28, - left: Name( - ExprName { - range: 17..18, - id: "x", - ctx: Load, - }, - ), - op: Sub, - right: Yield( - ExprYield { - range: 21..28, - value: Some( - Name( - ExprName { - range: 27..28, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x + lambda y: y - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -2 | -3 | x - yield y - | - - - | -1 | x + lambda y: y -2 | -3 | x - yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap.new deleted file mode 100644 index c21b758aa7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap.new +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_lhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 2..3, - value: Name( - ExprName { - range: 2..3, - id: "y", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | / y - | ^ Syntax Error: Expected a statement -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap.new deleted file mode 100644 index 639cd5e88a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap.new +++ /dev/null @@ -1,77 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_rhs_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..3, - value: BinOp( - ExprBinOp { - range: 0..3, - left: NumberLiteral( - ExprNumberLiteral { - range: 0..1, - value: Int( - 0, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | 0 + - | ^ Syntax Error: Expected an expression -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap.new deleted file mode 100644 index b0d0488be2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap.new +++ /dev/null @@ -1,105 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missing_rhs_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..18, - body: [ - Expr( - StmtExpr { - range: 0..11, - value: BinOp( - ExprBinOp { - range: 0..11, - left: BinOp( - ExprBinOp { - range: 0..5, - left: NumberLiteral( - ExprNumberLiteral { - range: 0..1, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 8..11, - left: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 3, - ), - }, - ), - op: Mult, - right: Name( - ExprName { - range: 11..11, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..18, - value: BinOp( - ExprBinOp { - range: 13..18, - left: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 4, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 17..18, - value: Int( - 5, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | 1 + 2 - 3 * - | ^ Syntax Error: Expected an expression -2 | -3 | 4 + 5 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap.new deleted file mode 100644 index ff531cca01..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap.new +++ /dev/null @@ -1,150 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/multiple_ops.py ---- -## AST - -``` -Module( - ModModule { - range: 0..19, - body: [ - Expr( - StmtExpr { - range: 0..3, - value: BinOp( - ExprBinOp { - range: 0..3, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: UnaryOp( - ExprUnaryOp { - range: 2..3, - op: UAdd, - operand: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 4..9, - value: BinOp( - ExprBinOp { - range: 4..9, - left: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..13, - value: BinOp( - ExprBinOp { - range: 10..13, - left: Name( - ExprName { - range: 10..11, - id: "x", - ctx: Load, - }, - ), - op: Sub, - right: UnaryOp( - ExprUnaryOp { - range: 12..13, - op: USub, - operand: Name( - ExprName { - range: 13..13, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 14..19, - value: BinOp( - ExprBinOp { - range: 14..19, - left: NumberLiteral( - ExprNumberLiteral { - range: 14..15, - value: Int( - 1, - ), - }, - ), - op: Sub, - right: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x++ - | ^ Syntax Error: Expected an expression -2 | 1 + 2 -3 | x-- -4 | 1 - 2 - | - - - | -1 | x++ -2 | 1 + 2 -3 | x-- - | ^ Syntax Error: Expected an expression -4 | 1 - 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap.new deleted file mode 100644 index 9c54a5157f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap.new +++ /dev/null @@ -1,123 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/named_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..26, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: BinOp( - ExprBinOp { - range: 0..5, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - op: Sub, - right: Name( - ExprName { - range: 4..5, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 9..15, - value: Tuple( - ExprTuple { - range: 9..15, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..21, - value: BinOp( - ExprBinOp { - range: 16..21, - left: Name( - ExprName { - range: 16..17, - id: "x", - ctx: Load, - }, - ), - op: Div, - right: Name( - ExprName { - range: 20..21, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 25..26, - value: NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x - y := (1, 2) - | ^^ Syntax Error: Expected a statement -2 | x / y := 2 - | - - - | -1 | x - y := (1, 2) -2 | x / y := 2 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap.new deleted file mode 100644 index a2bf66a886..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap.new +++ /dev/null @@ -1,92 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/starred_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..14, - body: [ - Expr( - StmtExpr { - range: 0..6, - value: BinOp( - ExprBinOp { - range: 0..6, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Starred( - ExprStarred { - range: 4..6, - value: Name( - ExprName { - range: 5..6, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 7..14, - value: BinOp( - ExprBinOp { - range: 7..14, - left: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - op: Pow, - right: Starred( - ExprStarred { - range: 12..14, - value: Name( - ExprName { - range: 13..14, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x + *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | x ** *y - | - - - | -1 | x + *y -2 | x ** *y - | ^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap.new deleted file mode 100644 index 8b958db8fd..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap.new +++ /dev/null @@ -1,121 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/invalid_rhs_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..31, - body: [ - Expr( - StmtExpr { - range: 0..17, - value: BoolOp( - ExprBoolOp { - range: 0..17, - op: And, - values: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - Lambda( - ExprLambda { - range: 6..17, - parameters: Some( - Parameters { - range: 13..14, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 13..14, - parameter: Parameter { - range: 13..14, - name: Identifier { - id: "y", - range: 13..14, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 16..17, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 19..31, - value: BoolOp( - ExprBoolOp { - range: 19..31, - op: Or, - values: [ - Name( - ExprName { - range: 19..20, - id: "x", - ctx: Load, - }, - ), - Yield( - ExprYield { - range: 24..31, - value: Some( - Name( - ExprName { - range: 30..31, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x and lambda y: y - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -2 | -3 | x or yield y - | - - - | -1 | x and lambda y: y -2 | -3 | x or yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap.new deleted file mode 100644 index c1c20dd520..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap.new +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/missing_lhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..5, - body: [ - Expr( - StmtExpr { - range: 4..5, - value: Name( - ExprName { - range: 4..5, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | and y - | ^^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap.new deleted file mode 100644 index c580c4df86..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap.new +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/missing_rhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..12, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: BoolOp( - ExprBoolOp { - range: 0..5, - op: And, - values: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 5..5, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 7..12, - value: BinOp( - ExprBinOp { - range: 7..12, - left: NumberLiteral( - ExprNumberLiteral { - range: 7..8, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x and - | ^ Syntax Error: Expected an expression -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap.new deleted file mode 100644 index 44a8ef65c3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap.new +++ /dev/null @@ -1,108 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/named_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: BoolOp( - ExprBoolOp { - range: 0..7, - op: And, - values: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 6..7, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..12, - value: Name( - ExprName { - range: 11..12, - id: "b", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..19, - value: BoolOp( - ExprBoolOp { - range: 13..19, - op: Or, - values: [ - Name( - ExprName { - range: 13..14, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 18..19, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 23..24, - value: Name( - ExprName { - range: 23..24, - id: "b", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x and a := b - | ^^ Syntax Error: Expected a statement -2 | x or a := b - | - - - | -1 | x and a := b -2 | x or a := b - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap.new deleted file mode 100644 index 072f3c2b77..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap.new +++ /dev/null @@ -1,96 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/starred_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..16, - body: [ - Expr( - StmtExpr { - range: 0..8, - value: BoolOp( - ExprBoolOp { - range: 0..8, - op: And, - values: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 6..8, - value: Name( - ExprName { - range: 7..8, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 9..16, - value: BoolOp( - ExprBoolOp { - range: 9..16, - op: Or, - values: [ - Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 14..16, - value: Name( - ExprName { - range: 15..16, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x and *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | x or *y - | - - - | -1 | x and *y -2 | x or *y - | ^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap.new deleted file mode 100644 index aae59a7df5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap.new +++ /dev/null @@ -1,169 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/invalid_order.py ---- -## AST - -``` -Module( - ModModule { - range: 0..131, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Compare( - ExprCompare { - range: 0..10, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - UnaryOp( - ExprUnaryOp { - range: 5..10, - op: Not, - operand: Name( - ExprName { - range: 9..10, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Assign( - StmtAssign { - range: 35..41, - targets: [ - Name( - ExprName { - range: 35..36, - id: "x", - ctx: Store, - }, - ), - ], - value: Compare( - ExprCompare { - range: 38..41, - left: Name( - ExprName { - range: 38..38, - id: "", - ctx: Invalid, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 40..41, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 120..121, - value: Name( - ExprName { - range: 120..121, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 122..128, - value: UnaryOp( - ExprUnaryOp { - range: 122..128, - op: Not, - operand: Name( - ExprName { - range: 126..128, - id: "is", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 129..130, - value: Name( - ExprName { - range: 129..130, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x in not y - | ^^^^^ Syntax Error: Boolean 'not' expression cannot be used here -2 | -3 | # `=>` instead of `>=` - | - - - | -3 | # `=>` instead of `>=` -4 | x => y - | ^ Syntax Error: Expected an expression -5 | -6 | # Same here as well, `not` without `in` is considered to be a unary operator - | - - - | -6 | # Same here as well, `not` without `in` is considered to be a unary operator -7 | x not is y - | ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -6 | # Same here as well, `not` without `in` is considered to be a unary operator -7 | x not is y - | ^^ Syntax Error: Expected an identifier, but found a keyword 'is' that cannot be used here - | - - - | -6 | # Same here as well, `not` without `in` is considered to be a unary operator -7 | x not is y - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap.new deleted file mode 100644 index 237cad295d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap.new +++ /dev/null @@ -1,125 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/invalid_rhs_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..34, - body: [ - Expr( - StmtExpr { - range: 0..20, - value: Compare( - ExprCompare { - range: 0..20, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Lambda( - ExprLambda { - range: 9..20, - parameters: Some( - Parameters { - range: 16..17, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 16..17, - parameter: Parameter { - range: 16..17, - name: Identifier { - id: "y", - range: 16..17, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 19..20, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..34, - value: Compare( - ExprCompare { - range: 22..34, - left: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Yield( - ExprYield { - range: 27..34, - value: Some( - Name( - ExprName { - range: 33..34, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x not in lambda y: y - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -2 | -3 | x == yield y - | - - - | -1 | x not in lambda y: y -2 | -3 | x == yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap.new deleted file mode 100644 index 96a2345a7f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap.new +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_lhs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 2..3, - value: Name( - ExprName { - range: 2..3, - id: "y", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | > y - | ^ Syntax Error: Expected a statement -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap.new deleted file mode 100644 index 048fa60fed..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap.new +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..3, - value: Compare( - ExprCompare { - range: 0..3, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x > - | ^ Syntax Error: Expected an expression -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap.new deleted file mode 100644 index 8c44bafe23..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap.new +++ /dev/null @@ -1,91 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..71, - body: [ - Expr( - StmtExpr { - range: 59..60, - value: Name( - ExprName { - range: 59..60, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 61..64, - value: UnaryOp( - ExprUnaryOp { - range: 61..64, - op: Not, - operand: Name( - ExprName { - range: 64..64, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 66..71, - value: BinOp( - ExprBinOp { - range: 66..71, - left: NumberLiteral( - ExprNumberLiteral { - range: 66..67, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 70..71, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Without the `in`, this is considered to be a unary `not` -2 | x not - | ^^^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | -4 | 1 + 2 - | - - - | -1 | # Without the `in`, this is considered to be a unary `not` -2 | x not - | ^ Syntax Error: Expected an expression -3 | -4 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap.new deleted file mode 100644 index e6b944c403..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap.new +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/missing_rhs_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..15, - body: [ - Expr( - StmtExpr { - range: 0..8, - value: Compare( - ExprCompare { - range: 0..8, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 8..8, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..15, - value: BinOp( - ExprBinOp { - range: 10..15, - left: NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 14..15, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x is not - | ^ Syntax Error: Expected an expression -2 | -3 | 1 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap.new deleted file mode 100644 index 00fcd44f56..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/multiple_equals.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - Assign( - StmtAssign { - range: 25..32, - targets: [ - Compare( - ExprCompare { - range: 25..29, - left: Name( - ExprName { - range: 25..26, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 29..29, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - ], - value: Name( - ExprName { - range: 31..32, - id: "y", - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 33..40, - targets: [ - Compare( - ExprCompare { - range: 33..37, - left: Name( - ExprName { - range: 33..34, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotEq, - ], - comparators: [ - Name( - ExprName { - range: 37..37, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - ], - value: Name( - ExprName { - range: 39..40, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # This is not JavaScript -2 | x === y - | ^ Syntax Error: Expected an expression -3 | x !== y - | - - - | -1 | # This is not JavaScript -2 | x === y - | ^^^^ Syntax Error: Invalid assignment target -3 | x !== y - | - - - | -1 | # This is not JavaScript -2 | x === y -3 | x !== y - | ^ Syntax Error: Expected an expression - | - - - | -1 | # This is not JavaScript -2 | x === y -3 | x !== y - | ^^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap.new deleted file mode 100644 index 57c8bf28ee..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap.new +++ /dev/null @@ -1,131 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/named_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..31, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Compare( - ExprCompare { - range: 0..10, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 9..10, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 14..20, - value: Tuple( - ExprTuple { - range: 14..20, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 15..16, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..26, - value: Compare( - ExprCompare { - range: 21..26, - left: Name( - ExprName { - range: 21..22, - id: "x", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 25..26, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 30..31, - value: NumberLiteral( - ExprNumberLiteral { - range: 30..31, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x not in y := (1, 2) - | ^^ Syntax Error: Expected a statement -2 | x > y := 2 - | - - - | -1 | x not in y := (1, 2) -2 | x > y := 2 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap.new deleted file mode 100644 index a78f9e7108..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap.new +++ /dev/null @@ -1,188 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/starred_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..39, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: Compare( - ExprCompare { - range: 0..7, - left: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - ops: [ - GtE, - ], - comparators: [ - Starred( - ExprStarred { - range: 5..7, - value: Name( - ExprName { - range: 6..7, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..19, - value: Compare( - ExprCompare { - range: 8..19, - left: Name( - ExprName { - range: 8..9, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Starred( - ExprStarred { - range: 17..19, - value: Name( - ExprName { - range: 18..19, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..27, - value: Starred( - ExprStarred { - range: 21..27, - value: Compare( - ExprCompare { - range: 22..27, - left: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - Name( - ExprName { - range: 26..27, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..39, - value: Starred( - ExprStarred { - range: 28..39, - value: Compare( - ExprCompare { - range: 29..39, - left: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x >= *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | x not in *y - | - - - | -1 | x >= *y -2 | x not in *y - | ^^ Syntax Error: Starred expression cannot be used here -3 | -4 | *x < y - | - - - | -2 | x not in *y -3 | -4 | *x < y - | ^^^^^ Syntax Error: Comparison expression cannot be used here -5 | *x is not y - | - - - | -4 | *x < y -5 | *x is not y - | ^^^^^^^^^^ Syntax Error: Comparison expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap.new deleted file mode 100644 index 1119e1fb4a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap.new +++ /dev/null @@ -1,828 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..362, - body: [ - Expr( - StmtExpr { - range: 17..34, - value: DictComp( - ExprDictComp { - range: 17..34, - key: Name( - ExprName { - range: 18..19, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 21..22, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 23..33, - target: NumberLiteral( - ExprNumberLiteral { - range: 27..28, - value: Int( - 1, - ), - }, - ), - iter: Name( - ExprName { - range: 32..33, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 35..54, - value: DictComp( - ExprDictComp { - range: 35..54, - key: Name( - ExprName { - range: 36..37, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 39..40, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 41..53, - target: StringLiteral( - ExprStringLiteral { - range: 45..48, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 45..48, - value: "a", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - iter: Name( - ExprName { - range: 52..53, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 55..77, - value: DictComp( - ExprDictComp { - range: 55..77, - key: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 59..60, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 61..76, - target: Call( - ExprCall { - range: 65..71, - func: Name( - ExprName { - range: 65..69, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 69..71, - args: [], - keywords: [], - }, - }, - ), - iter: Name( - ExprName { - range: 75..76, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 78..100, - value: DictComp( - ExprDictComp { - range: 78..100, - key: Name( - ExprName { - range: 79..80, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 82..83, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 84..99, - target: Set( - ExprSet { - range: 88..94, - elts: [ - Name( - ExprName { - range: 89..90, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 92..93, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 98..99, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 117..135, - value: DictComp( - ExprDictComp { - range: 117..135, - key: Name( - ExprName { - range: 118..119, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 121..122, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 123..134, - target: Name( - ExprName { - range: 127..128, - id: "x", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 132..134, - value: Name( - ExprName { - range: 133..134, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 136..159, - value: DictComp( - ExprDictComp { - range: 136..159, - key: Name( - ExprName { - range: 137..138, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 140..141, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 142..158, - target: Name( - ExprName { - range: 146..147, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 151..158, - value: Some( - Name( - ExprName { - range: 157..158, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 160..188, - value: DictComp( - ExprDictComp { - range: 160..188, - key: Name( - ExprName { - range: 161..162, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 164..165, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 166..187, - target: Name( - ExprName { - range: 170..171, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 175..187, - value: Name( - ExprName { - range: 186..187, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 189..216, - value: DictComp( - ExprDictComp { - range: 189..216, - key: Name( - ExprName { - range: 190..191, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 193..194, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 195..215, - target: Name( - ExprName { - range: 199..200, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 204..215, - parameters: Some( - Parameters { - range: 211..212, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 211..212, - parameter: Parameter { - range: 211..212, - name: Identifier { - id: "y", - range: 211..212, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 214..215, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 231..257, - value: DictComp( - ExprDictComp { - range: 231..257, - key: Name( - ExprName { - range: 232..233, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 235..236, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 237..256, - target: Name( - ExprName { - range: 241..242, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 246..250, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Starred( - ExprStarred { - range: 254..256, - value: Name( - ExprName { - range: 255..256, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 258..289, - value: DictComp( - ExprDictComp { - range: 258..289, - key: Name( - ExprName { - range: 259..260, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 262..263, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 264..288, - target: Name( - ExprName { - range: 268..269, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 273..277, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 281..288, - value: Some( - Name( - ExprName { - range: 287..288, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 290..326, - value: DictComp( - ExprDictComp { - range: 290..326, - key: Name( - ExprName { - range: 291..292, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 294..295, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 296..325, - target: Name( - ExprName { - range: 300..301, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 305..309, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 313..325, - value: Name( - ExprName { - range: 324..325, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 327..362, - value: DictComp( - ExprDictComp { - range: 327..362, - key: Name( - ExprName { - range: 328..329, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 331..332, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 333..361, - target: Name( - ExprName { - range: 337..338, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 342..346, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 350..361, - parameters: Some( - Parameters { - range: 357..358, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 357..358, - parameter: Parameter { - range: 357..358, - name: Identifier { - id: "y", - range: 357..358, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 360..361, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Invalid target -2 | {x: y for 1 in y} - | ^ Syntax Error: Invalid assignment target -3 | {x: y for 'a' in y} -4 | {x: y for call() in y} - | - - - | -1 | # Invalid target -2 | {x: y for 1 in y} -3 | {x: y for 'a' in y} - | ^^^ Syntax Error: Invalid assignment target -4 | {x: y for call() in y} -5 | {x: y for {a, b} in y} - | - - - | -2 | {x: y for 1 in y} -3 | {x: y for 'a' in y} -4 | {x: y for call() in y} - | ^^^^^^ Syntax Error: Invalid assignment target -5 | {x: y for {a, b} in y} - | - - - | -3 | {x: y for 'a' in y} -4 | {x: y for call() in y} -5 | {x: y for {a, b} in y} - | ^^^^^^ Syntax Error: Invalid assignment target -6 | -7 | # Invalid iter - | - - - | - 7 | # Invalid iter - 8 | {x: y for x in *y} - | ^^ Syntax Error: Starred expression cannot be used here - 9 | {x: y for x in yield y} -10 | {x: y for x in yield from y} - | - - - | - 7 | # Invalid iter - 8 | {x: y for x in *y} - 9 | {x: y for x in yield y} - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -10 | {x: y for x in yield from y} -11 | {x: y for x in lambda y: y} - | - - - | - 8 | {x: y for x in *y} - 9 | {x: y for x in yield y} -10 | {x: y for x in yield from y} - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -11 | {x: y for x in lambda y: y} - | - - - | - 9 | {x: y for x in yield y} -10 | {x: y for x in yield from y} -11 | {x: y for x in lambda y: y} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -12 | -13 | # Invalid if - | - - - | -13 | # Invalid if -14 | {x: y for x in data if *y} - | ^^ Syntax Error: Starred expression cannot be used here -15 | {x: y for x in data if yield y} -16 | {x: y for x in data if yield from y} - | - - - | -13 | # Invalid if -14 | {x: y for x in data if *y} -15 | {x: y for x in data if yield y} - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -16 | {x: y for x in data if yield from y} -17 | {x: y for x in data if lambda y: y} - | - - - | -14 | {x: y for x in data if *y} -15 | {x: y for x in data if yield y} -16 | {x: y for x in data if yield from y} - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -17 | {x: y for x in data if lambda y: y} - | - - - | -15 | {x: y for x in data if yield y} -16 | {x: y for x in data if yield from y} -17 | {x: y for x in data if lambda y: y} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap.new deleted file mode 100644 index fcf9674767..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap.new +++ /dev/null @@ -1,576 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_star.py ---- -## AST - -``` -Module( - ModModule { - range: 0..278, - body: [ - Expr( - StmtExpr { - range: 125..135, - value: Dict( - ExprDict { - range: 125..135, - items: [ - DictItem { - key: None, - value: Name( - ExprName { - range: 128..129, - id: "x", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 133..134, - value: Int( - 1, - ), - }, - ), - ), - value: Name( - ExprName { - range: 134..134, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 136..162, - value: Dict( - ExprDict { - range: 136..162, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 137..138, - id: "a", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 140..141, - value: Int( - 1, - ), - }, - ), - }, - DictItem { - key: None, - value: If( - ExprIf { - range: 145..161, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 150..154, - value: true, - }, - ), - body: Name( - ExprName { - range: 145..146, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 160..161, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 163..184, - value: Dict( - ExprDict { - range: 163..184, - items: [ - DictItem { - key: None, - value: Lambda( - ExprLambda { - range: 166..177, - parameters: Some( - Parameters { - range: 173..174, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 173..174, - parameter: Parameter { - range: 173..174, - name: Identifier { - id: "x", - range: 173..174, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 176..177, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 179..180, - id: "b", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 182..183, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 185..201, - value: Dict( - ExprDict { - range: 185..201, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 186..187, - id: "a", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 189..190, - value: Int( - 1, - ), - }, - ), - }, - DictItem { - key: None, - value: BoolOp( - ExprBoolOp { - range: 194..200, - op: Or, - values: [ - Name( - ExprName { - range: 194..195, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 199..200, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 202..219, - value: Dict( - ExprDict { - range: 202..219, - items: [ - DictItem { - key: None, - value: BoolOp( - ExprBoolOp { - range: 205..212, - op: And, - values: [ - Name( - ExprName { - range: 205..206, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 211..212, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 214..215, - id: "b", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 217..218, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 220..241, - value: Dict( - ExprDict { - range: 220..241, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 221..222, - id: "a", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 224..225, - value: Int( - 1, - ), - }, - ), - }, - DictItem { - key: None, - value: UnaryOp( - ExprUnaryOp { - range: 229..234, - op: Not, - operand: Name( - ExprName { - range: 233..234, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 236..237, - id: "b", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 239..240, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 242..252, - value: Dict( - ExprDict { - range: 242..252, - items: [ - DictItem { - key: None, - value: Compare( - ExprCompare { - range: 245..251, - left: Name( - ExprName { - range: 245..246, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 250..251, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 253..267, - value: Dict( - ExprDict { - range: 253..267, - items: [ - DictItem { - key: None, - value: Compare( - ExprCompare { - range: 256..266, - left: Name( - ExprName { - range: 256..257, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 265..266, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 268..277, - value: Dict( - ExprDict { - range: 268..277, - items: [ - DictItem { - key: None, - value: Compare( - ExprCompare { - range: 271..276, - left: Name( - ExprName { - range: 271..272, - id: "x", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - Name( - ExprName { - range: 275..276, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # the ones which are higher than that. -3 | -4 | {**x := 1} - | ^^ Syntax Error: Expected ',', found ':=' -5 | {a: 1, **x if True else y} -6 | {**lambda x: x, b: 2} - | - - - | -2 | # the ones which are higher than that. -3 | -4 | {**x := 1} - | ^ Syntax Error: Expected ':', found '}' -5 | {a: 1, **x if True else y} -6 | {**lambda x: x, b: 2} - | - - - | -4 | {**x := 1} -5 | {a: 1, **x if True else y} - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here -6 | {**lambda x: x, b: 2} -7 | {a: 1, **x or y} - | - - - | -4 | {**x := 1} -5 | {a: 1, **x if True else y} -6 | {**lambda x: x, b: 2} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -7 | {a: 1, **x or y} -8 | {**x and y, b: 2} - | - - - | -5 | {a: 1, **x if True else y} -6 | {**lambda x: x, b: 2} -7 | {a: 1, **x or y} - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -8 | {**x and y, b: 2} -9 | {a: 1, **not x, b: 2} - | - - - | - 6 | {**lambda x: x, b: 2} - 7 | {a: 1, **x or y} - 8 | {**x and y, b: 2} - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here - 9 | {a: 1, **not x, b: 2} -10 | {**x in y} - | - - - | - 7 | {a: 1, **x or y} - 8 | {**x and y, b: 2} - 9 | {a: 1, **not x, b: 2} - | ^^^^^ Syntax Error: Boolean expression cannot be used here -10 | {**x in y} -11 | {**x not in y} - | - - - | - 8 | {**x and y, b: 2} - 9 | {a: 1, **not x, b: 2} -10 | {**x in y} - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -11 | {**x not in y} -12 | {**x < y} - | - - - | - 9 | {a: 1, **not x, b: 2} -10 | {**x in y} -11 | {**x not in y} - | ^^^^^^^^^^ Syntax Error: Comparison expression cannot be used here -12 | {**x < y} - | - - - | -10 | {**x in y} -11 | {**x not in y} -12 | {**x < y} - | ^^^^^ Syntax Error: Comparison expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap.new deleted file mode 100644 index 37ce4468d3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap.new +++ /dev/null @@ -1,159 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_star_comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..358, - body: [ - Expr( - StmtExpr { - range: 122..147, - value: Dict( - ExprDict { - range: 122..147, - items: [ - DictItem { - key: None, - value: Name( - ExprName { - range: 125..126, - id: "x", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 128..129, - id: "y", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 130..133, - id: "for", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 134..135, - id: "x", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 135..135, - id: "", - ctx: Invalid, - }, - ), - }, - DictItem { - key: Some( - Compare( - ExprCompare { - range: 137..146, - left: Name( - ExprName { - range: 137..138, - id: "y", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 142..146, - id: "data", - ctx: Load, - }, - ), - ], - }, - ), - ), - value: Name( - ExprName { - range: 146..146, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # it's actually a comprehension. -3 | -4 | {**x: y for x, y in data} - | ^ Syntax Error: Expected an expression or a '}' -5 | -6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y` - | - - - | -2 | # it's actually a comprehension. -3 | -4 | {**x: y for x, y in data} - | ^^^ Syntax Error: Expected ':', found 'for' -5 | -6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y` - | - - - | -2 | # it's actually a comprehension. -3 | -4 | {**x: y for x, y in data} - | ^ Syntax Error: Expected ',', found name -5 | -6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y` - | - - - | -2 | # it's actually a comprehension. -3 | -4 | {**x: y for x, y in data} - | ^ Syntax Error: Expected ':', found ',' -5 | -6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y` - | - - - | -2 | # it's actually a comprehension. -3 | -4 | {**x: y for x, y in data} - | ^ Syntax Error: Expected ':', found '}' -5 | -6 | # TODO(dhruvmanila): This test case fails because there's no way to represent `**y` - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap.new deleted file mode 100644 index 7ce4ac564f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap.new +++ /dev/null @@ -1,106 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Expr( - StmtExpr { - range: 0..24, - value: Dict( - ExprDict { - range: 0..24, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 5..8, - id: "def", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Call( - ExprCall { - range: 9..14, - func: Name( - ExprName { - range: 9..12, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 12..14, - args: [], - keywords: [], - }, - }, - ), - ), - value: Name( - ExprName { - range: 20..24, - id: "pass", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | {x: -2 | -3 | def foo(): - | ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here -4 | pass - | - - - | -1 | {x: -2 | -3 | def foo(): - | ^^^ Syntax Error: Expected ',', found name -4 | pass - | - - - | -3 | def foo(): -4 | pass - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here - | - - - | -3 | def foo(): -4 | pass - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap.new deleted file mode 100644 index 0b9616167a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap.new +++ /dev/null @@ -1,69 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Dict( - ExprDict { - range: 0..10, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - ), - value: BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | {x: -2 | -3 | 1 + 2 - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap.new deleted file mode 100644 index 955207508e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap.new +++ /dev/null @@ -1,84 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing_closing_brace_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..27, - body: [ - Expr( - StmtExpr { - range: 0..6, - value: Dict( - ExprDict { - range: 0..6, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 8..27, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 12..15, - }, - type_params: None, - parameters: Parameters { - range: 15..17, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 23..27, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | {x: 1, - | ^ Syntax Error: Expected '}', found newline -2 | -3 | def foo(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap.new deleted file mode 100644 index 1ffa5fe711..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap.new +++ /dev/null @@ -1,141 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_expression_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..84, - body: [ - Expr( - StmtExpr { - range: 55..77, - value: Dict( - ExprDict { - range: 55..77, - items: [ - DictItem { - key: Some( - Named( - ExprNamed { - range: 56..62, - target: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 61..62, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - value: Name( - ExprName { - range: 64..65, - id: "y", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 67..68, - id: "z", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 68..68, - id: "", - ctx: Invalid, - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 72..73, - value: Int( - 2, - ), - }, - ), - ), - value: Name( - ExprName { - range: 75..76, - id: "a", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 79..84, - value: BinOp( - ExprBinOp { - range: 79..84, - left: Name( - ExprName { - range: 79..80, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 83..84, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Unparenthesized named expression not allowed in key -2 | -3 | {x := 1: y, z := 2: a} - | ^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here -4 | -5 | x + y - | - - - | -1 | # Unparenthesized named expression not allowed in key -2 | -3 | {x := 1: y, z := 2: a} - | ^^ Syntax Error: Expected ':', found ':=' -4 | -5 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap.new deleted file mode 100644 index b7efe2bd36..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap.new +++ /dev/null @@ -1,167 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_expression_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..86, - body: [ - Expr( - StmtExpr { - range: 57..79, - value: Dict( - ExprDict { - range: 57..79, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 58..59, - id: "x", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 61..62, - id: "y", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 66..67, - value: Int( - 1, - ), - }, - ), - ), - value: Name( - ExprName { - range: 67..67, - id: "", - ctx: Invalid, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 69..70, - id: "z", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 72..73, - id: "a", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 77..78, - value: Int( - 2, - ), - }, - ), - ), - value: Name( - ExprName { - range: 78..78, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 81..86, - value: BinOp( - ExprBinOp { - range: 81..86, - left: Name( - ExprName { - range: 81..82, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 85..86, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Unparenthesized named expression not allowed in value -2 | -3 | {x: y := 1, z: a := 2} - | ^^ Syntax Error: Expected ',', found ':=' -4 | -5 | x + y - | - - - | -1 | # Unparenthesized named expression not allowed in value -2 | -3 | {x: y := 1, z: a := 2} - | ^ Syntax Error: Expected ':', found ',' -4 | -5 | x + y - | - - - | -1 | # Unparenthesized named expression not allowed in value -2 | -3 | {x: y := 1, z: a := 2} - | ^^ Syntax Error: Expected ',', found ':=' -4 | -5 | x + y - | - - - | -1 | # Unparenthesized named expression not allowed in value -2 | -3 | {x: y := 1, z: a := 2} - | ^ Syntax Error: Expected ':', found '}' -4 | -5 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap.new deleted file mode 100644 index 7d844143e7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap.new +++ /dev/null @@ -1,518 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/recover.py ---- -## AST - -``` -Module( - ModModule { - range: 0..346, - body: [ - Expr( - StmtExpr { - range: 88..91, - value: Set( - ExprSet { - range: 88..91, - elts: [ - Name( - ExprName { - range: 89..89, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 93..105, - value: Dict( - ExprDict { - range: 93..105, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 94..95, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 100..101, - value: Int( - 3, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 103..104, - value: Int( - 4, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 107..115, - value: Dict( - ExprDict { - range: 107..115, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 108..109, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 111..112, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..144, - value: Dict( - ExprDict { - range: 133..144, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 134..135, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 137..138, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 139..140, - value: Int( - 3, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 142..143, - value: Int( - 4, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 157..162, - value: Dict( - ExprDict { - range: 157..162, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), - }, - ), - ), - value: Name( - ExprName { - range: 160..160, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 201..205, - value: Dict( - ExprDict { - range: 201..205, - items: [ - DictItem { - key: None, - value: Name( - ExprName { - range: 204..204, - id: "", - ctx: Invalid, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 206..222, - value: Dict( - ExprDict { - range: 206..222, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 207..208, - id: "x", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 210..211, - id: "y", - ctx: Load, - }, - ), - }, - DictItem { - key: None, - value: Name( - ExprName { - range: 215..215, - id: "", - ctx: Invalid, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 217..218, - id: "a", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 220..221, - id: "b", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 310..330, - value: Dict( - ExprDict { - range: 310..330, - items: [ - DictItem { - key: Some( - Starred( - ExprStarred { - range: 311..313, - value: Name( - ExprName { - range: 312..313, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 315..316, - id: "y", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 318..319, - id: "z", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 321..322, - id: "a", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Starred( - ExprStarred { - range: 324..326, - value: Name( - ExprName { - range: 325..326, - id: "b", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 328..329, - id: "c", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 331..345, - value: Dict( - ExprDict { - range: 331..345, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 332..333, - id: "x", - ctx: Load, - }, - ), - ), - value: Starred( - ExprStarred { - range: 335..337, - value: Name( - ExprName { - range: 336..337, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 339..340, - id: "z", - ctx: Load, - }, - ), - ), - value: Starred( - ExprStarred { - range: 342..344, - value: Name( - ExprName { - range: 343..344, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Test cases for dictionary expressions where the parser recovers from a syntax error. -2 | -3 | {,} - | ^ Syntax Error: Expected an expression -4 | -5 | {1: 2,,3: 4} - | - - - | -3 | {,} -4 | -5 | {1: 2,,3: 4} - | ^ Syntax Error: Expected an expression or a '}' -6 | -7 | {1: 2,,} - | - - - | -5 | {1: 2,,3: 4} -6 | -7 | {1: 2,,} - | ^ Syntax Error: Expected an expression or a '}' -8 | -9 | # Missing comma - | - - - | - 9 | # Missing comma -10 | {1: 2 3: 4} - | ^ Syntax Error: Expected ',', found int -11 | -12 | # No value - | - - - | -12 | # No value -13 | {1: } - | ^ Syntax Error: Expected an expression -14 | -15 | # No value for double star unpacking - | - - - | -15 | # No value for double star unpacking -16 | {**} - | ^ Syntax Error: Expected an expression -17 | {x: y, **, a: b} - | - - - | -15 | # No value for double star unpacking -16 | {**} -17 | {x: y, **, a: b} - | ^ Syntax Error: Expected an expression -18 | -19 | # This is not a double star unpacking - | - - - | -22 | # Star expression not allowed here -23 | {*x: y, z: a, *b: c} - | ^^ Syntax Error: Starred expression cannot be used here -24 | {x: *y, z: *a} - | - - - | -22 | # Star expression not allowed here -23 | {*x: y, z: a, *b: c} - | ^^ Syntax Error: Starred expression cannot be used here -24 | {x: *y, z: *a} - | - - - | -22 | # Star expression not allowed here -23 | {*x: y, z: a, *b: c} -24 | {x: *y, z: *a} - | ^^ Syntax Error: Starred expression cannot be used here - | - - - | -22 | # Star expression not allowed here -23 | {*x: y, z: a, *b: c} -24 | {x: *y, z: *a} - | ^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap.new deleted file mode 100644 index 67a101cdb3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap.new +++ /dev/null @@ -1,139 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/emoji_identifiers.py ---- -## AST - -``` -Module( - ModModule { - range: 0..64, - body: [ - Assign( - StmtAssign { - range: 0..5, - targets: [ - Name( - ExprName { - range: 0..1, - id: "a", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 5..5, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 32..37, - targets: [ - Name( - ExprName { - range: 32..33, - id: "a", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 37..37, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 42..43, - value: UnaryOp( - ExprUnaryOp { - range: 42..43, - op: UAdd, - operand: Name( - ExprName { - range: 43..43, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | a = (🐶 - | ^^ Syntax Error: Got unexpected token 🐶 -2 | # comment 🐶 -3 | ) - | - - - | -1 | a = (🐶 -2 | # comment 🐶 -3 | ) - | ^ Syntax Error: Expected a statement -4 | -5 | a = (🐶 + - | - - - | -1 | a = (🐶 -2 | # comment 🐶 -3 | ) - | ^ Syntax Error: Expected a statement -4 | -5 | a = (🐶 + -6 | # comment - | - - - | -3 | ) -4 | -5 | a = (🐶 + - | ^^ Syntax Error: Got unexpected token 🐶 -6 | # comment -7 | 🐶) - | - - - | -5 | a = (🐶 + -6 | # comment -7 | 🐶) - | ^^ Syntax Error: Got unexpected token 🐶 - | - - - | -5 | a = (🐶 + -6 | # comment -7 | 🐶) - | ^ Syntax Error: Expected a statement - | - - - | -5 | a = (🐶 + -6 | # comment -7 | 🐶) - | ^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap.new deleted file mode 100644 index adf2b1ba1d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap.new +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_orelse_expr_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..88, - body: [ - Expr( - StmtExpr { - range: 53..67, - value: If( - ExprIf { - range: 53..67, - test: Name( - ExprName { - range: 58..62, - id: "expr", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 53..54, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 67..67, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 69..88, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 73..76, - }, - type_params: None, - parameters: Parameters { - range: 76..78, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 84..88, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing orelse expression, followed by a statement -2 | x if expr else - | ^ Syntax Error: Expected an expression -3 | -4 | def foo(): -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap.new deleted file mode 100644 index 93d7d48d65..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap.new +++ /dev/null @@ -1,83 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_orelse_expr_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..76, - body: [ - Expr( - StmtExpr { - range: 55..69, - value: If( - ExprIf { - range: 55..69, - test: Name( - ExprName { - range: 60..64, - id: "expr", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 55..56, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 69..69, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 71..76, - value: BinOp( - ExprBinOp { - range: 71..76, - left: NumberLiteral( - ExprNumberLiteral { - range: 71..72, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 75..76, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing orelse expression, followed by an expression -2 | x if expr else - | ^ Syntax Error: Expected an expression -3 | -4 | 1 + 1 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap.new deleted file mode 100644 index b7f7c6fa82..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap.new +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_test_expr_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..76, - body: [ - Expr( - StmtExpr { - range: 51..55, - value: If( - ExprIf { - range: 51..55, - test: Name( - ExprName { - range: 55..55, - id: "", - ctx: Invalid, - }, - ), - body: Name( - ExprName { - range: 51..52, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 55..55, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 57..76, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 61..64, - }, - type_params: None, - parameters: Parameters { - range: 64..66, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 72..76, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing test expression, followed by a statement -2 | x if - | ^ Syntax Error: Expected an expression -3 | -4 | def foo(): -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap.new deleted file mode 100644 index 5e41946610..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap.new +++ /dev/null @@ -1,83 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_test_expr_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..64, - body: [ - Expr( - StmtExpr { - range: 53..57, - value: If( - ExprIf { - range: 53..57, - test: Name( - ExprName { - range: 57..57, - id: "", - ctx: Invalid, - }, - ), - body: Name( - ExprName { - range: 53..54, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 57..57, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 59..64, - value: BinOp( - ExprBinOp { - range: 59..64, - left: NumberLiteral( - ExprNumberLiteral { - range: 59..60, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 63..64, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing test expression, followed by an expression -2 | x if - | ^ Syntax Error: Expected an expression -3 | -4 | 1 + 1 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap.new deleted file mode 100644 index 0fe3e25873..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap.new +++ /dev/null @@ -1,361 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/if/recover.py ---- -## AST - -``` -Module( - ModModule { - range: 0..215, - body: [ - Expr( - StmtExpr { - range: 26..43, - value: If( - ExprIf { - range: 26..43, - test: Starred( - ExprStarred { - range: 31..36, - value: Name( - ExprName { - range: 32..36, - id: "expr", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 26..27, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 42..43, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 44..67, - value: If( - ExprIf { - range: 44..67, - test: Lambda( - ExprLambda { - range: 49..60, - parameters: Some( - Parameters { - range: 56..57, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 56..57, - parameter: Parameter { - range: 56..57, - name: Identifier { - id: "x", - range: 56..57, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 59..60, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: Name( - ExprName { - range: 44..45, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 66..67, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 68..87, - value: If( - ExprIf { - range: 68..87, - test: Yield( - ExprYield { - range: 73..80, - value: Some( - Name( - ExprName { - range: 79..80, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - body: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 86..87, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 88..112, - value: If( - ExprIf { - range: 88..112, - test: YieldFrom( - ExprYieldFrom { - range: 93..105, - value: Name( - ExprName { - range: 104..105, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: Name( - ExprName { - range: 88..89, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 111..112, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 142..164, - value: If( - ExprIf { - range: 142..164, - test: Name( - ExprName { - range: 147..151, - id: "expr", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 142..143, - id: "x", - ctx: Load, - }, - ), - orelse: Starred( - ExprStarred { - range: 157..164, - value: Name( - ExprName { - range: 158..164, - id: "orelse", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 165..187, - value: If( - ExprIf { - range: 165..187, - test: Name( - ExprName { - range: 170..174, - id: "expr", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 165..166, - id: "x", - ctx: Load, - }, - ), - orelse: Yield( - ExprYield { - range: 180..187, - value: Some( - Name( - ExprName { - range: 186..187, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 188..215, - value: If( - ExprIf { - range: 188..215, - test: Name( - ExprName { - range: 193..197, - id: "expr", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 188..189, - id: "x", - ctx: Load, - }, - ), - orelse: YieldFrom( - ExprYieldFrom { - range: 203..215, - value: Name( - ExprName { - range: 214..215, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Invalid test expression -2 | x if *expr else y - | ^^^^^ Syntax Error: Starred expression cannot be used here -3 | x if lambda x: x else y -4 | x if yield x else y - | - - - | -1 | # Invalid test expression -2 | x if *expr else y -3 | x if lambda x: x else y - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -4 | x if yield x else y -5 | x if yield from x else y - | - - - | -2 | x if *expr else y -3 | x if lambda x: x else y -4 | x if yield x else y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | x if yield from x else y - | - - - | -3 | x if lambda x: x else y -4 | x if yield x else y -5 | x if yield from x else y - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -6 | -7 | # Invalid orelse expression - | - - - | - 7 | # Invalid orelse expression - 8 | x if expr else *orelse - | ^^^^^^^ Syntax Error: Starred expression cannot be used here - 9 | x if expr else yield y -10 | x if expr else yield from y - | - - - | - 7 | # Invalid orelse expression - 8 | x if expr else *orelse - 9 | x if expr else yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -10 | x if expr else yield from y - | - - - | - 8 | x if expr else *orelse - 9 | x if expr else yield y -10 | x if expr else yield from y - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap.new deleted file mode 100644 index 593428af9d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap.new +++ /dev/null @@ -1,96 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_default_parameters.py ---- -## AST - -``` -Module( - ModModule { - range: 0..20, - body: [ - Expr( - StmtExpr { - range: 0..20, - value: Lambda( - ExprLambda { - range: 0..20, - parameters: Some( - Parameters { - range: 7..17, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 7..8, - parameter: Parameter { - range: 7..8, - name: Identifier { - id: "a", - range: 7..8, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 10..14, - parameter: Parameter { - range: 10..11, - name: Identifier { - id: "b", - range: 10..11, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 12..14, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 16..17, - parameter: Parameter { - range: 16..17, - name: Identifier { - id: "c", - range: 16..17, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | lambda a, b=20, c: 1 - | ^ Syntax Error: Parameter without a default cannot follow a parameter with a default - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap.new deleted file mode 100644 index 247eae4307..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap.new +++ /dev/null @@ -1,339 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_duplicate_parameters.py ---- -## AST - -``` -Module( - ModModule { - range: 0..91, - body: [ - Expr( - StmtExpr { - range: 0..14, - value: Lambda( - ExprLambda { - range: 0..14, - parameters: Some( - Parameters { - range: 7..11, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 7..8, - parameter: Parameter { - range: 7..8, - name: Identifier { - id: "a", - range: 7..8, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 10..11, - parameter: Parameter { - range: 10..11, - name: Identifier { - id: "a", - range: 10..11, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..33, - value: Lambda( - ExprLambda { - range: 16..33, - parameters: Some( - Parameters { - range: 23..30, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 23..24, - parameter: Parameter { - range: 23..24, - name: Identifier { - id: "a", - range: 23..24, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 29..30, - parameter: Parameter { - range: 29..30, - name: Identifier { - id: "a", - range: 29..30, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 35..52, - value: Lambda( - ExprLambda { - range: 35..52, - parameters: Some( - Parameters { - range: 42..49, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 42..43, - parameter: Parameter { - range: 42..43, - name: Identifier { - id: "a", - range: 42..43, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 45..49, - parameter: Parameter { - range: 45..46, - name: Identifier { - id: "a", - range: 45..46, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 47..49, - value: Int( - 20, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 54..69, - value: Lambda( - ExprLambda { - range: 54..69, - parameters: Some( - Parameters { - range: 61..66, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 61..62, - parameter: Parameter { - range: 61..62, - name: Identifier { - id: "a", - range: 61..62, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 64..66, - name: Identifier { - id: "a", - range: 65..66, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 68..69, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 71..90, - value: Lambda( - ExprLambda { - range: 71..90, - parameters: Some( - Parameters { - range: 78..87, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 78..79, - parameter: Parameter { - range: 78..79, - name: Identifier { - id: "a", - range: 78..79, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 84..87, - name: Identifier { - id: "a", - range: 86..87, - }, - annotation: None, - }, - ), - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | lambda a, a: 1 - | ^ Syntax Error: Duplicate parameter "a" -2 | -3 | lambda a, *, a: 1 - | - - - | -1 | lambda a, a: 1 -2 | -3 | lambda a, *, a: 1 - | ^ Syntax Error: Duplicate parameter "a" -4 | -5 | lambda a, a=20: 1 - | - - - | -3 | lambda a, *, a: 1 -4 | -5 | lambda a, a=20: 1 - | ^ Syntax Error: Duplicate parameter "a" -6 | -7 | lambda a, *a: 1 - | - - - | -5 | lambda a, a=20: 1 -6 | -7 | lambda a, *a: 1 - | ^ Syntax Error: Duplicate parameter "a" -8 | -9 | lambda a, *, **a: 1 - | - - - | -7 | lambda a, *a: 1 -8 | -9 | lambda a, *, **a: 1 - | ^^^ Syntax Error: Expected one or more keyword parameter after '*' separator - | - - - | -7 | lambda a, *a: 1 -8 | -9 | lambda a, *, **a: 1 - | ^ Syntax Error: Duplicate parameter "a" - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap.new deleted file mode 100644 index c045bdbe37..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap.new +++ /dev/null @@ -1,797 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..376, - body: [ - Expr( - StmtExpr { - range: 33..48, - value: ListComp( - ExprListComp { - range: 33..48, - elt: Starred( - ExprStarred { - range: 34..36, - value: Name( - ExprName { - range: 35..36, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 37..47, - target: Name( - ExprName { - range: 41..42, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 46..47, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 67..81, - value: ListComp( - ExprListComp { - range: 67..81, - elt: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 70..80, - target: NumberLiteral( - ExprNumberLiteral { - range: 74..75, - value: Int( - 1, - ), - }, - ), - iter: Name( - ExprName { - range: 79..80, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 82..98, - value: ListComp( - ExprListComp { - range: 82..98, - elt: Name( - ExprName { - range: 83..84, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 85..97, - target: StringLiteral( - ExprStringLiteral { - range: 89..92, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 89..92, - value: "a", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - iter: Name( - ExprName { - range: 96..97, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 99..118, - value: ListComp( - ExprListComp { - range: 99..118, - elt: Name( - ExprName { - range: 100..101, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 102..117, - target: Call( - ExprCall { - range: 106..112, - func: Name( - ExprName { - range: 106..110, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 110..112, - args: [], - keywords: [], - }, - }, - ), - iter: Name( - ExprName { - range: 116..117, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..138, - value: ListComp( - ExprListComp { - range: 119..138, - elt: Name( - ExprName { - range: 120..121, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 122..137, - target: Set( - ExprSet { - range: 126..132, - elts: [ - Name( - ExprName { - range: 127..128, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 130..131, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 136..137, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 155..170, - value: ListComp( - ExprListComp { - range: 155..170, - elt: Name( - ExprName { - range: 156..157, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 158..169, - target: Name( - ExprName { - range: 162..163, - id: "x", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 167..169, - value: Name( - ExprName { - range: 168..169, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 171..191, - value: ListComp( - ExprListComp { - range: 171..191, - elt: Name( - ExprName { - range: 172..173, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 174..190, - target: Name( - ExprName { - range: 178..179, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 183..190, - value: Some( - Name( - ExprName { - range: 189..190, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 192..217, - value: ListComp( - ExprListComp { - range: 192..217, - elt: Name( - ExprName { - range: 193..194, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 195..216, - target: Name( - ExprName { - range: 199..200, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 204..216, - value: Name( - ExprName { - range: 215..216, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 218..242, - value: ListComp( - ExprListComp { - range: 218..242, - elt: Name( - ExprName { - range: 219..220, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 221..241, - target: Name( - ExprName { - range: 225..226, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 230..241, - parameters: Some( - Parameters { - range: 237..238, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 237..238, - parameter: Parameter { - range: 237..238, - name: Identifier { - id: "y", - range: 237..238, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 240..241, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 257..280, - value: ListComp( - ExprListComp { - range: 257..280, - elt: Name( - ExprName { - range: 258..259, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 260..279, - target: Name( - ExprName { - range: 264..265, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 269..273, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Starred( - ExprStarred { - range: 277..279, - value: Name( - ExprName { - range: 278..279, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 281..309, - value: ListComp( - ExprListComp { - range: 281..309, - elt: Name( - ExprName { - range: 282..283, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 284..308, - target: Name( - ExprName { - range: 288..289, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 293..297, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 301..308, - value: Some( - Name( - ExprName { - range: 307..308, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 310..343, - value: ListComp( - ExprListComp { - range: 310..343, - elt: Name( - ExprName { - range: 311..312, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 313..342, - target: Name( - ExprName { - range: 317..318, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 322..326, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 330..342, - value: Name( - ExprName { - range: 341..342, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 344..376, - value: ListComp( - ExprListComp { - range: 344..376, - elt: Name( - ExprName { - range: 345..346, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 347..375, - target: Name( - ExprName { - range: 351..352, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 356..360, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 364..375, - parameters: Some( - Parameters { - range: 371..372, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 371..372, - parameter: Parameter { - range: 371..372, - name: Identifier { - id: "y", - range: 371..372, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 374..375, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Iterable unpacking not allowed -2 | [*x for x in y] - | ^^ Syntax Error: Iterable unpacking cannot be used in a comprehension -3 | -4 | # Invalid target - | - - - | -4 | # Invalid target -5 | [x for 1 in y] - | ^ Syntax Error: Invalid assignment target -6 | [x for 'a' in y] -7 | [x for call() in y] - | - - - | -4 | # Invalid target -5 | [x for 1 in y] -6 | [x for 'a' in y] - | ^^^ Syntax Error: Invalid assignment target -7 | [x for call() in y] -8 | [x for {a, b} in y] - | - - - | -5 | [x for 1 in y] -6 | [x for 'a' in y] -7 | [x for call() in y] - | ^^^^^^ Syntax Error: Invalid assignment target -8 | [x for {a, b} in y] - | - - - | - 6 | [x for 'a' in y] - 7 | [x for call() in y] - 8 | [x for {a, b} in y] - | ^^^^^^ Syntax Error: Invalid assignment target - 9 | -10 | # Invalid iter - | - - - | -10 | # Invalid iter -11 | [x for x in *y] - | ^^ Syntax Error: Starred expression cannot be used here -12 | [x for x in yield y] -13 | [x for x in yield from y] - | - - - | -10 | # Invalid iter -11 | [x for x in *y] -12 | [x for x in yield y] - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -13 | [x for x in yield from y] -14 | [x for x in lambda y: y] - | - - - | -11 | [x for x in *y] -12 | [x for x in yield y] -13 | [x for x in yield from y] - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -14 | [x for x in lambda y: y] - | - - - | -12 | [x for x in yield y] -13 | [x for x in yield from y] -14 | [x for x in lambda y: y] - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -15 | -16 | # Invalid if - | - - - | -16 | # Invalid if -17 | [x for x in data if *y] - | ^^ Syntax Error: Starred expression cannot be used here -18 | [x for x in data if yield y] -19 | [x for x in data if yield from y] - | - - - | -16 | # Invalid if -17 | [x for x in data if *y] -18 | [x for x in data if yield y] - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -19 | [x for x in data if yield from y] -20 | [x for x in data if lambda y: y] - | - - - | -17 | [x for x in data if *y] -18 | [x for x in data if yield y] -19 | [x for x in data if yield from y] - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -20 | [x for x in data if lambda y: y] - | - - - | -18 | [x for x in data if yield y] -19 | [x for x in data if yield from y] -20 | [x for x in data if lambda y: y] - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap.new deleted file mode 100644 index 7bdbfce6af..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap.new +++ /dev/null @@ -1,44 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..43, - body: [ - Expr( - StmtExpr { - range: 42..43, - value: List( - ExprList { - range: 42..43, - elts: [ - Name( - ExprName { - range: 43..43, - id: "", - ctx: Invalid, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing closing bracket 0: No elements -2 | -3 | [ - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap.new deleted file mode 100644 index 61cd90d686..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap.new +++ /dev/null @@ -1,57 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..133, - body: [ - Expr( - StmtExpr { - range: 125..133, - value: List( - ExprList { - range: 125..133, - elts: [ - BinOp( - ExprBinOp { - range: 128..133, - left: Name( - ExprName { - range: 128..129, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 132..133, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | [ -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap.new deleted file mode 100644 index 6629151ef7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap.new +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..141, - body: [ - Expr( - StmtExpr { - range: 131..141, - value: List( - ExprList { - range: 131..141, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 132..133, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 136..141, - left: Name( - ExprName { - range: 136..137, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 140..141, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | [1, -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap.new deleted file mode 100644 index 298e1b21fe..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap.new +++ /dev/null @@ -1,84 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing_closing_bracket_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..140, - body: [ - Expr( - StmtExpr { - range: 114..119, - value: List( - ExprList { - range: 114..119, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 115..116, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 121..140, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 125..128, - }, - type_params: None, - parameters: Parameters { - range: 128..130, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 136..140, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # token starts a statement. -3 | -4 | [1, 2 - | ^ Syntax Error: Expected ']', found newline -5 | -6 | def foo(): -7 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap.new deleted file mode 100644 index 8abb482576..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap.new +++ /dev/null @@ -1,315 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/recover.py ---- -## AST - -``` -Module( - ModModule { - range: 0..208, - body: [ - Expr( - StmtExpr { - range: 82..85, - value: List( - ExprList { - range: 82..85, - elts: [ - Name( - ExprName { - range: 83..83, - id: "", - ctx: Invalid, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 87..93, - value: List( - ExprList { - range: 87..93, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 88..89, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 91..92, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 95..100, - value: List( - ExprList { - range: 95..100, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 96..97, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 118..123, - value: List( - ExprList { - range: 118..123, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 121..122, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 156..162, - value: List( - ExprList { - range: 156..162, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 157..158, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 160..161, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 185..194, - value: List( - ExprList { - range: 185..194, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 186..187, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 189..192, - left: Name( - ExprName { - range: 189..190, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 192..192, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 196..202, - value: List( - ExprList { - range: 196..202, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 197..198, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 200..201, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 204..207, - value: List( - ExprList { - range: 204..207, - elts: [ - Starred( - ExprStarred { - range: 205..206, - value: Name( - ExprName { - range: 206..206, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Test cases for list expressions where the parser recovers from a syntax error. -2 | -3 | [,] - | ^ Syntax Error: Expected an expression -4 | -5 | [1,,2] - | - - - | -3 | [,] -4 | -5 | [1,,2] - | ^ Syntax Error: Expected an expression or a ']' -6 | -7 | [1,,] - | - - - | -5 | [1,,2] -6 | -7 | [1,,] - | ^ Syntax Error: Expected an expression or a ']' -8 | -9 | # Missing comma - | - - - | - 9 | # Missing comma -10 | [1 2] - | ^ Syntax Error: Expected ',', found int -11 | -12 | # Dictionary element in a list - | - - - | -12 | # Dictionary element in a list -13 | [1: 2] - | ^ Syntax Error: Expected an expression or a ']' -14 | -15 | # Missing expression - | - - - | -15 | # Missing expression -16 | [1, x + ] - | ^ Syntax Error: Expected an expression -17 | -18 | [1; 2] - | - - - | -16 | [1, x + ] -17 | -18 | [1; 2] - | ^ Syntax Error: Expected an expression or a ']' -19 | -20 | [*] - | - - - | -18 | [1; 2] -19 | -20 | [*] - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap.new deleted file mode 100644 index 7a912a4681..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap.new +++ /dev/null @@ -1,468 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/list/star_expression_precedence.py ---- -## AST - -``` -Module( - ModModule { - range: 0..200, - body: [ - Expr( - StmtExpr { - range: 84..93, - value: List( - ExprList { - range: 84..93, - elts: [ - Starred( - ExprStarred { - range: 86..88, - value: Name( - ExprName { - range: 87..88, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 91..92, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 94..106, - value: List( - ExprList { - range: 94..106, - elts: [ - Starred( - ExprStarred { - range: 95..102, - value: Compare( - ExprCompare { - range: 96..102, - left: Name( - ExprName { - range: 96..97, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 101..102, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 104..105, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 107..118, - value: List( - ExprList { - range: 107..118, - elts: [ - Starred( - ExprStarred { - range: 108..114, - value: UnaryOp( - ExprUnaryOp { - range: 109..114, - op: Not, - operand: Name( - ExprName { - range: 113..114, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 116..117, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..132, - value: List( - ExprList { - range: 119..132, - elts: [ - Starred( - ExprStarred { - range: 120..128, - value: BoolOp( - ExprBoolOp { - range: 121..128, - op: And, - values: [ - Name( - ExprName { - range: 121..122, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 127..128, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 130..131, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..145, - value: List( - ExprList { - range: 133..145, - elts: [ - Starred( - ExprStarred { - range: 134..141, - value: BoolOp( - ExprBoolOp { - range: 135..141, - op: Or, - values: [ - Name( - ExprName { - range: 135..136, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 140..141, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 143..144, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 146..168, - value: List( - ExprList { - range: 146..168, - elts: [ - Starred( - ExprStarred { - range: 147..164, - value: If( - ExprIf { - range: 148..164, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 153..157, - value: true, - }, - ), - body: Name( - ExprName { - range: 148..149, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 163..164, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 166..167, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 169..186, - value: List( - ExprList { - range: 169..186, - elts: [ - Starred( - ExprStarred { - range: 170..182, - value: Lambda( - ExprLambda { - range: 171..182, - parameters: Some( - Parameters { - range: 178..179, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 178..179, - parameter: Parameter { - range: 178..179, - name: Identifier { - id: "x", - range: 178..179, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 181..182, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 184..185, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 187..199, - value: List( - ExprList { - range: 187..199, - elts: [ - Named( - ExprNamed { - range: 188..195, - target: Starred( - ExprStarred { - range: 188..190, - value: Name( - ExprName { - range: 189..190, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 194..195, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 197..198, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # For list expression, the minimum binding power of star expression is bitwise or. -2 | -3 | [(*x), y] - | ^^ Syntax Error: Starred expression cannot be used here -4 | [*x in y, z] -5 | [*not x, z] - | - - - | -3 | [(*x), y] -4 | [*x in y, z] - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -5 | [*not x, z] -6 | [*x and y, z] - | - - - | -3 | [(*x), y] -4 | [*x in y, z] -5 | [*not x, z] - | ^^^^^ Syntax Error: Boolean expression cannot be used here -6 | [*x and y, z] -7 | [*x or y, z] - | - - - | -4 | [*x in y, z] -5 | [*not x, z] -6 | [*x and y, z] - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -7 | [*x or y, z] -8 | [*x if True else y, z] - | - - - | -5 | [*not x, z] -6 | [*x and y, z] -7 | [*x or y, z] - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -8 | [*x if True else y, z] -9 | [*lambda x: x, z] - | - - - | - 6 | [*x and y, z] - 7 | [*x or y, z] - 8 | [*x if True else y, z] - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here - 9 | [*lambda x: x, z] -10 | [*x := 2, z] - | - - - | - 7 | [*x or y, z] - 8 | [*x if True else y, z] - 9 | [*lambda x: x, z] - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -10 | [*x := 2, z] - | - - - | - 8 | [*x if True else y, z] - 9 | [*lambda x: x, z] -10 | [*x := 2, z] - | ^^ Syntax Error: Assignment expression target must be an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap.new deleted file mode 100644 index 1909a153cf..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap.new +++ /dev/null @@ -1,212 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/invalid_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..109, - body: [ - Expr( - StmtExpr { - range: 58..68, - value: Named( - ExprNamed { - range: 59..67, - target: Attribute( - ExprAttribute { - range: 59..62, - value: Name( - ExprName { - range: 59..60, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "y", - range: 61..62, - }, - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 66..67, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 69..80, - value: Named( - ExprNamed { - range: 70..79, - target: Subscript( - ExprSubscript { - range: 70..74, - value: Name( - ExprName { - range: 70..71, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 72..73, - id: "y", - ctx: Load, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 78..79, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 81..90, - value: Named( - ExprNamed { - range: 82..89, - target: Starred( - ExprStarred { - range: 82..84, - value: Name( - ExprName { - range: 83..84, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 88..89, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 91..109, - value: Named( - ExprNamed { - range: 92..108, - target: List( - ExprList { - range: 92..98, - elts: [ - Name( - ExprName { - range: 93..94, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 96..97, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - value: List( - ExprList { - range: 102..108, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 103..104, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 106..107, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Assignment expression target can only be an identifier -2 | -3 | (x.y := 1) - | ^^^ Syntax Error: Assignment expression target must be an identifier -4 | (x[y] := 1) -5 | (*x := 1) - | - - - | -3 | (x.y := 1) -4 | (x[y] := 1) - | ^^^^ Syntax Error: Assignment expression target must be an identifier -5 | (*x := 1) -6 | ([x, y] := [1, 2]) - | - - - | -3 | (x.y := 1) -4 | (x[y] := 1) -5 | (*x := 1) - | ^^ Syntax Error: Assignment expression target must be an identifier -6 | ([x, y] := [1, 2]) - | - - - | -4 | (x[y] := 1) -5 | (*x := 1) -6 | ([x, y] := [1, 2]) - | ^^^^^^ Syntax Error: Assignment expression target must be an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap.new deleted file mode 100644 index 9c609e5dbd..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap.new +++ /dev/null @@ -1,44 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missing_expression_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..75, - body: [ - Expr( - StmtExpr { - range: 71..72, - value: Name( - ExprName { - range: 71..72, - id: "x", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # There are no parentheses, so this isn't parsed as named expression. -2 | -3 | x := - | ^^ Syntax Error: Expected a statement - | - - - | -1 | # There are no parentheses, so this isn't parsed as named expression. -2 | -3 | x := - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap.new deleted file mode 100644 index b1bd782ada..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap.new +++ /dev/null @@ -1,48 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missing_expression_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..33, - body: [ - Expr( - StmtExpr { - range: 28..33, - value: Named( - ExprNamed { - range: 29..33, - target: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 33..33, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # EOF after the `:=` token -2 | -3 | (x := - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap.new deleted file mode 100644 index c6be122d57..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap.new +++ /dev/null @@ -1,103 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missing_expression_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..87, - body: [ - Expr( - StmtExpr { - range: 61..71, - value: Named( - ExprNamed { - range: 62..71, - target: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 68..71, - id: "def", - ctx: Load, - }, - ), - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 72..87, - target: Call( - ExprCall { - range: 72..77, - func: Name( - ExprName { - range: 72..75, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 75..77, - args: [], - keywords: [], - }, - }, - ), - annotation: Name( - ExprName { - range: 83..87, - id: "pass", - ctx: Load, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, -) -``` -## Errors - - | -3 | (x := -4 | -5 | def foo(): - | ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here -6 | pass - | - - - | -3 | (x := -4 | -5 | def foo(): - | ^^^ Syntax Error: Expected ')', found name -6 | pass - | - - - | -5 | def foo(): -6 | pass - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here - | - - - | -5 | def foo(): -6 | pass - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap.new deleted file mode 100644 index b541a33dc4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap.new +++ /dev/null @@ -1,61 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missing_expression_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..112, - body: [ - Expr( - StmtExpr { - range: 100..112, - value: Named( - ExprNamed { - range: 101..112, - target: Name( - ExprName { - range: 101..102, - id: "x", - ctx: Store, - }, - ), - value: BinOp( - ExprBinOp { - range: 107..112, - left: Name( - ExprName { - range: 107..108, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 111..112, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | (x := -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap.new deleted file mode 100644 index d8b96a9135..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap.new +++ /dev/null @@ -1,75 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missing_expression_4.py ---- -## AST - -``` -Module( - ModModule { - range: 0..78, - body: [ - Expr( - StmtExpr { - range: 64..71, - value: Named( - ExprNamed { - range: 65..69, - target: Name( - ExprName { - range: 65..66, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 69..69, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 73..78, - value: BinOp( - ExprBinOp { - range: 73..78, - left: Name( - ExprName { - range: 73..74, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 77..78, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # No expression on the right side of the assignment expression -2 | -3 | (x := ) - | ^ Syntax Error: Expected an expression -4 | -5 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap.new deleted file mode 100644 index 16f7d61148..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap.new +++ /dev/null @@ -1,145 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/generator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..36, - body: [ - Expr( - StmtExpr { - range: 0..15, - value: Generator( - ExprGenerator { - range: 0..15, - elt: Starred( - ExprStarred { - range: 1..3, - value: Name( - ExprName { - range: 2..3, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 4..14, - target: Name( - ExprName { - range: 8..9, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 13..14, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..24, - value: Tuple( - ExprTuple { - range: 16..24, - elts: [ - Named( - ExprNamed { - range: 17..23, - target: Name( - ExprName { - range: 17..18, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 22..23, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - For( - StmtFor { - range: 25..35, - is_async: false, - target: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 34..35, - id: "y", - ctx: Load, - }, - ), - body: [], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | (*x for x in y) - | ^^ Syntax Error: Iterable unpacking cannot be used in a comprehension -2 | (x := 1, for x in y) - | - - - | -1 | (*x for x in y) -2 | (x := 1, for x in y) - | ^^^ Syntax Error: Expected ')', found 'for' - | - - - | -1 | (*x for x in y) -2 | (x := 1, for x in y) - | ^ Syntax Error: Expected ':', found ')' - | - - - | -1 | (*x for x in y) -2 | (x := 1, for x in y) - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap.new deleted file mode 100644 index 47b2231d8f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap.new +++ /dev/null @@ -1,36 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/missing_closing_paren_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..47, - body: [ - Expr( - StmtExpr { - range: 46..47, - value: Name( - ExprName { - range: 47..47, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing closing parentheses 0: No elements -2 | -3 | ( - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap.new deleted file mode 100644 index b4c3dd2ca5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap.new +++ /dev/null @@ -1,49 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/missing_closing_paren_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..137, - body: [ - Expr( - StmtExpr { - range: 129..137, - value: BinOp( - ExprBinOp { - range: 132..137, - left: Name( - ExprName { - range: 132..133, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 136..137, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | ( -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap.new deleted file mode 100644 index 7a8dddf21c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/missing_closing_paren_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..146, - body: [ - Expr( - StmtExpr { - range: 136..146, - value: Tuple( - ExprTuple { - range: 136..146, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 137..138, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 141..146, - left: Name( - ExprName { - range: 141..142, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 145..146, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | (1, -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap.new deleted file mode 100644 index af97995092..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap.new +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/missing_closing_paren_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..144, - body: [ - Expr( - StmtExpr { - range: 118..123, - value: Tuple( - ExprTuple { - range: 118..123, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 125..144, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 129..132, - }, - type_params: None, - parameters: Parameters { - range: 132..134, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 140..144, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # token starts a statement. -3 | -4 | (1, 2 - | ^ Syntax Error: Expected ')', found newline -5 | -6 | def foo(): -7 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap.new deleted file mode 100644 index 8e1f0e5643..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap.new +++ /dev/null @@ -1,75 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/parenthesized.py ---- -## AST - -``` -Module( - ModModule { - range: 0..125, - body: [ - Expr( - StmtExpr { - range: 66..70, - value: Starred( - ExprStarred { - range: 67..69, - value: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..120, - value: Name( - ExprName { - range: 119..120, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 124..125, - value: NumberLiteral( - ExprNumberLiteral { - range: 124..125, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Starred expression isn't allowed in a parenthesized expression. -2 | (*x) - | ^^ Syntax Error: Starred expression cannot be used here -3 | -4 | # Unparenthesized named expression is allowed. - | - - - | -4 | # Unparenthesized named expression is allowed. -5 | x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap.new deleted file mode 100644 index fdad2a179d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap.new +++ /dev/null @@ -1,391 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/tuple.py ---- -## AST - -``` -Module( - ModModule { - range: 0..267, - body: [ - Expr( - StmtExpr { - range: 83..86, - value: Tuple( - ExprTuple { - range: 83..86, - elts: [ - Name( - ExprName { - range: 84..84, - id: "", - ctx: Invalid, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 88..94, - value: Tuple( - ExprTuple { - range: 88..94, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 92..93, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 96..101, - value: Tuple( - ExprTuple { - range: 96..101, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..121, - value: NumberLiteral( - ExprNumberLiteral { - range: 120..121, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 122..123, - value: NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 2, - ), - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 157..162, - target: NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), - }, - ), - annotation: NumberLiteral( - ExprNumberLiteral { - range: 161..162, - value: Int( - 2, - ), - }, - ), - value: None, - simple: false, - }, - ), - Expr( - StmtExpr { - range: 186..195, - value: Tuple( - ExprTuple { - range: 186..195, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 187..188, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 190..193, - left: Name( - ExprName { - range: 190..191, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 193..193, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 197..199, - value: NumberLiteral( - ExprNumberLiteral { - range: 198..199, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 201..202, - value: NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 2, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 255..267, - value: Tuple( - ExprTuple { - range: 255..267, - elts: [ - Name( - ExprName { - range: 255..256, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 258..259, - id: "y", - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 263..264, - value: Int( - 2, - ), - }, - ), - Name( - ExprName { - range: 266..267, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Test cases for tuple expressions where the parser recovers from a syntax error. -2 | -3 | (,) - | ^ Syntax Error: Expected an expression -4 | -5 | (1,,2) - | - - - | -3 | (,) -4 | -5 | (1,,2) - | ^ Syntax Error: Expected an expression or a ')' -6 | -7 | (1,,) - | - - - | -5 | (1,,2) -6 | -7 | (1,,) - | ^ Syntax Error: Expected an expression or a ')' -8 | -9 | # Missing comma - | - - - | - 9 | # Missing comma -10 | (1 2) - | ^ Syntax Error: Expected ')', found int -11 | -12 | # Dictionary element in a list - | - - - | - 9 | # Missing comma -10 | (1 2) - | ^ Syntax Error: Expected a statement -11 | -12 | # Dictionary element in a list - | - - - | - 9 | # Missing comma -10 | (1 2) - | ^ Syntax Error: Expected a statement -11 | -12 | # Dictionary element in a list -13 | (1: 2) - | - - - | -12 | # Dictionary element in a list -13 | (1: 2) - | ^ Syntax Error: Expected ')', found ':' -14 | -15 | # Missing expression - | - - - | -12 | # Dictionary element in a list -13 | (1: 2) - | ^ Syntax Error: Invalid annotated assignment target -14 | -15 | # Missing expression - | - - - | -12 | # Dictionary element in a list -13 | (1: 2) - | ^ Syntax Error: Expected a statement -14 | -15 | # Missing expression - | - - - | -12 | # Dictionary element in a list -13 | (1: 2) - | ^ Syntax Error: Expected a statement -14 | -15 | # Missing expression -16 | (1, x + ) - | - - - | -15 | # Missing expression -16 | (1, x + ) - | ^ Syntax Error: Expected an expression -17 | -18 | (1; 2) - | - - - | -16 | (1, x + ) -17 | -18 | (1; 2) - | ^ Syntax Error: Expected ')', found ';' -19 | -20 | # Unparenthesized named expression is not allowed - | - - - | -16 | (1, x + ) -17 | -18 | (1; 2) - | ^ Syntax Error: Expected a statement -19 | -20 | # Unparenthesized named expression is not allowed - | - - - | -16 | (1, x + ) -17 | -18 | (1; 2) - | ^ Syntax Error: Expected a statement -19 | -20 | # Unparenthesized named expression is not allowed -21 | x, y := 2, z - | - - - | -20 | # Unparenthesized named expression is not allowed -21 | x, y := 2, z - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap.new deleted file mode 100644 index b6a368efc3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap.new +++ /dev/null @@ -1,1381 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesized/tuple_starred_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..536, - body: [ - Expr( - StmtExpr { - range: 161..182, - value: Tuple( - ExprTuple { - range: 161..182, - elts: [ - Starred( - ExprStarred { - range: 162..169, - value: Compare( - ExprCompare { - range: 163..169, - left: Name( - ExprName { - range: 163..164, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 168..169, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 171..172, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 174..181, - value: Compare( - ExprCompare { - range: 175..181, - left: Name( - ExprName { - range: 175..176, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 180..181, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 183..202, - value: Tuple( - ExprTuple { - range: 183..202, - elts: [ - Starred( - ExprStarred { - range: 184..190, - value: UnaryOp( - ExprUnaryOp { - range: 185..190, - op: Not, - operand: Name( - ExprName { - range: 189..190, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 192..193, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 195..201, - value: UnaryOp( - ExprUnaryOp { - range: 196..201, - op: Not, - operand: Name( - ExprName { - range: 200..201, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 203..226, - value: Tuple( - ExprTuple { - range: 203..226, - elts: [ - Starred( - ExprStarred { - range: 204..212, - value: BoolOp( - ExprBoolOp { - range: 205..212, - op: And, - values: [ - Name( - ExprName { - range: 205..206, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 211..212, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 214..215, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 217..225, - value: BoolOp( - ExprBoolOp { - range: 218..225, - op: And, - values: [ - Name( - ExprName { - range: 218..219, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 224..225, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 227..248, - value: Tuple( - ExprTuple { - range: 227..248, - elts: [ - Starred( - ExprStarred { - range: 228..235, - value: BoolOp( - ExprBoolOp { - range: 229..235, - op: Or, - values: [ - Name( - ExprName { - range: 229..230, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 234..235, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 237..238, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 240..247, - value: BoolOp( - ExprBoolOp { - range: 241..247, - op: Or, - values: [ - Name( - ExprName { - range: 241..242, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 246..247, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 249..290, - value: Tuple( - ExprTuple { - range: 249..290, - elts: [ - Starred( - ExprStarred { - range: 250..267, - value: If( - ExprIf { - range: 251..267, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 256..260, - value: true, - }, - ), - body: Name( - ExprName { - range: 251..252, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 266..267, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 269..270, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 272..289, - value: If( - ExprIf { - range: 273..289, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 278..282, - value: true, - }, - ), - body: Name( - ExprName { - range: 273..274, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 288..289, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 291..322, - value: Tuple( - ExprTuple { - range: 291..322, - elts: [ - Starred( - ExprStarred { - range: 292..304, - value: Lambda( - ExprLambda { - range: 293..304, - parameters: Some( - Parameters { - range: 300..301, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 300..301, - parameter: Parameter { - range: 300..301, - name: Identifier { - id: "x", - range: 300..301, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 303..304, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 306..307, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 309..321, - value: Lambda( - ExprLambda { - range: 310..321, - parameters: Some( - Parameters { - range: 317..318, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 317..318, - parameter: Parameter { - range: 317..318, - name: Identifier { - id: "x", - range: 317..318, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 320..321, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 323..344, - value: Tuple( - ExprTuple { - range: 323..344, - elts: [ - Named( - ExprNamed { - range: 324..331, - target: Starred( - ExprStarred { - range: 324..326, - value: Name( - ExprName { - range: 325..326, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 330..331, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 333..334, - id: "z", - ctx: Load, - }, - ), - Named( - ExprNamed { - range: 336..343, - target: Starred( - ExprStarred { - range: 336..338, - value: Name( - ExprName { - range: 337..338, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 342..343, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 367..386, - value: Tuple( - ExprTuple { - range: 367..386, - elts: [ - Starred( - ExprStarred { - range: 367..374, - value: Compare( - ExprCompare { - range: 368..374, - left: Name( - ExprName { - range: 368..369, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 373..374, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 376..377, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 379..386, - value: Compare( - ExprCompare { - range: 380..386, - left: Name( - ExprName { - range: 380..381, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 385..386, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 387..404, - value: Tuple( - ExprTuple { - range: 387..404, - elts: [ - Starred( - ExprStarred { - range: 387..393, - value: UnaryOp( - ExprUnaryOp { - range: 388..393, - op: Not, - operand: Name( - ExprName { - range: 392..393, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 395..396, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 398..404, - value: UnaryOp( - ExprUnaryOp { - range: 399..404, - op: Not, - operand: Name( - ExprName { - range: 403..404, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 405..426, - value: Tuple( - ExprTuple { - range: 405..426, - elts: [ - Starred( - ExprStarred { - range: 405..413, - value: BoolOp( - ExprBoolOp { - range: 406..413, - op: And, - values: [ - Name( - ExprName { - range: 406..407, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 412..413, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 415..416, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 418..426, - value: BoolOp( - ExprBoolOp { - range: 419..426, - op: And, - values: [ - Name( - ExprName { - range: 419..420, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 425..426, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 427..446, - value: Tuple( - ExprTuple { - range: 427..446, - elts: [ - Starred( - ExprStarred { - range: 427..434, - value: BoolOp( - ExprBoolOp { - range: 428..434, - op: Or, - values: [ - Name( - ExprName { - range: 428..429, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 433..434, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 436..437, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 439..446, - value: BoolOp( - ExprBoolOp { - range: 440..446, - op: Or, - values: [ - Name( - ExprName { - range: 440..441, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 445..446, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 447..486, - value: Tuple( - ExprTuple { - range: 447..486, - elts: [ - Starred( - ExprStarred { - range: 447..464, - value: If( - ExprIf { - range: 448..464, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 453..457, - value: true, - }, - ), - body: Name( - ExprName { - range: 448..449, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 463..464, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 466..467, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 469..486, - value: If( - ExprIf { - range: 470..486, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 475..479, - value: true, - }, - ), - body: Name( - ExprName { - range: 470..471, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 485..486, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 487..516, - value: Tuple( - ExprTuple { - range: 487..516, - elts: [ - Starred( - ExprStarred { - range: 487..499, - value: Lambda( - ExprLambda { - range: 488..499, - parameters: Some( - Parameters { - range: 495..496, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 495..496, - parameter: Parameter { - range: 495..496, - name: Identifier { - id: "x", - range: 495..496, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 498..499, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 501..502, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 504..516, - value: Lambda( - ExprLambda { - range: 505..516, - parameters: Some( - Parameters { - range: 512..513, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 512..513, - parameter: Parameter { - range: 512..513, - name: Identifier { - id: "x", - range: 512..513, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 515..516, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 517..519, - value: Starred( - ExprStarred { - range: 517..519, - value: Name( - ExprName { - range: 518..519, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 523..536, - value: Tuple( - ExprTuple { - range: 523..536, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 523..524, - value: Int( - 2, - ), - }, - ), - Name( - ExprName { - range: 526..527, - id: "z", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 529..531, - value: Name( - ExprName { - range: 530..531, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 535..536, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # Test the first and any other element as the there are two separate calls. -3 | -4 | (*x in y, z, *x in y) - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) - | - - - | -2 | # Test the first and any other element as the there are two separate calls. -3 | -4 | (*x in y, z, *x in y) - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) - | - - - | -4 | (*x in y, z, *x in y) -5 | (*not x, z, *not x) - | ^^^^^ Syntax Error: Boolean expression cannot be used here -6 | (*x and y, z, *x and y) -7 | (*x or y, z, *x or y) - | - - - | -4 | (*x in y, z, *x in y) -5 | (*not x, z, *not x) - | ^^^^^ Syntax Error: Boolean expression cannot be used here -6 | (*x and y, z, *x and y) -7 | (*x or y, z, *x or y) - | - - - | -4 | (*x in y, z, *x in y) -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -7 | (*x or y, z, *x or y) -8 | (*x if True else y, z, *x if True else y) - | - - - | -4 | (*x in y, z, *x in y) -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -7 | (*x or y, z, *x or y) -8 | (*x if True else y, z, *x if True else y) - | - - - | -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) -7 | (*x or y, z, *x or y) - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -8 | (*x if True else y, z, *x if True else y) -9 | (*lambda x: x, z, *lambda x: x) - | - - - | -5 | (*not x, z, *not x) -6 | (*x and y, z, *x and y) -7 | (*x or y, z, *x or y) - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -8 | (*x if True else y, z, *x if True else y) -9 | (*lambda x: x, z, *lambda x: x) - | - - - | - 6 | (*x and y, z, *x and y) - 7 | (*x or y, z, *x or y) - 8 | (*x if True else y, z, *x if True else y) - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here - 9 | (*lambda x: x, z, *lambda x: x) -10 | (*x := 2, z, *x := 2) - | - - - | - 6 | (*x and y, z, *x and y) - 7 | (*x or y, z, *x or y) - 8 | (*x if True else y, z, *x if True else y) - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here - 9 | (*lambda x: x, z, *lambda x: x) -10 | (*x := 2, z, *x := 2) - | - - - | - 7 | (*x or y, z, *x or y) - 8 | (*x if True else y, z, *x if True else y) - 9 | (*lambda x: x, z, *lambda x: x) - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -10 | (*x := 2, z, *x := 2) - | - - - | - 7 | (*x or y, z, *x or y) - 8 | (*x if True else y, z, *x if True else y) - 9 | (*lambda x: x, z, *lambda x: x) - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -10 | (*x := 2, z, *x := 2) - | - - - | - 8 | (*x if True else y, z, *x if True else y) - 9 | (*lambda x: x, z, *lambda x: x) -10 | (*x := 2, z, *x := 2) - | ^^ Syntax Error: Assignment expression target must be an identifier - | - - - | - 8 | (*x if True else y, z, *x if True else y) - 9 | (*lambda x: x, z, *lambda x: x) -10 | (*x := 2, z, *x := 2) - | ^^ Syntax Error: Assignment expression target must be an identifier - | - - - | -13 | # Non-parenthesized -14 | *x in y, z, *x in y - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -15 | *not x, z, *not x -16 | *x and y, z, *x and y - | - - - | -13 | # Non-parenthesized -14 | *x in y, z, *x in y - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -15 | *not x, z, *not x -16 | *x and y, z, *x and y - | - - - | -13 | # Non-parenthesized -14 | *x in y, z, *x in y -15 | *not x, z, *not x - | ^^^^^ Syntax Error: Boolean expression cannot be used here -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y - | - - - | -13 | # Non-parenthesized -14 | *x in y, z, *x in y -15 | *not x, z, *not x - | ^^^^^ Syntax Error: Boolean expression cannot be used here -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y - | - - - | -14 | *x in y, z, *x in y -15 | *not x, z, *not x -16 | *x and y, z, *x and y - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y - | - - - | -14 | *x in y, z, *x in y -15 | *not x, z, *not x -16 | *x and y, z, *x and y - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y - | - - - | -15 | *not x, z, *not x -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x - | - - - | -15 | *not x, z, *not x -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x - | - - - | -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here -19 | *lambda x: x, z, *lambda x: x -20 | *x := 2, z, *x := 2 - | - - - | -16 | *x and y, z, *x and y -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here -19 | *lambda x: x, z, *lambda x: x -20 | *x := 2, z, *x := 2 - | - - - | -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -20 | *x := 2, z, *x := 2 - | - - - | -17 | *x or y, z, *x or y -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -20 | *x := 2, z, *x := 2 - | - - - | -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x -20 | *x := 2, z, *x := 2 - | ^^ Syntax Error: Expected a statement - | - - - | -18 | *x if True else y, z, *x if True else y -19 | *lambda x: x, z, *lambda x: x -20 | *x := 2, z, *x := 2 - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap.new deleted file mode 100644 index d5e059d8da..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap.new +++ /dev/null @@ -1,797 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..377, - body: [ - Expr( - StmtExpr { - range: 33..48, - value: SetComp( - ExprSetComp { - range: 33..48, - elt: Starred( - ExprStarred { - range: 34..36, - value: Name( - ExprName { - range: 35..36, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 37..47, - target: Name( - ExprName { - range: 41..42, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 46..47, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 67..81, - value: SetComp( - ExprSetComp { - range: 67..81, - elt: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 70..80, - target: NumberLiteral( - ExprNumberLiteral { - range: 74..75, - value: Int( - 1, - ), - }, - ), - iter: Name( - ExprName { - range: 79..80, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 82..98, - value: SetComp( - ExprSetComp { - range: 82..98, - elt: Name( - ExprName { - range: 83..84, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 85..97, - target: StringLiteral( - ExprStringLiteral { - range: 89..92, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 89..92, - value: "a", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - iter: Name( - ExprName { - range: 96..97, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 99..118, - value: SetComp( - ExprSetComp { - range: 99..118, - elt: Name( - ExprName { - range: 100..101, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 102..117, - target: Call( - ExprCall { - range: 106..112, - func: Name( - ExprName { - range: 106..110, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 110..112, - args: [], - keywords: [], - }, - }, - ), - iter: Name( - ExprName { - range: 116..117, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..138, - value: SetComp( - ExprSetComp { - range: 119..138, - elt: Name( - ExprName { - range: 120..121, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 122..137, - target: Set( - ExprSet { - range: 126..132, - elts: [ - Name( - ExprName { - range: 127..128, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 130..131, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 136..137, - id: "y", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 155..170, - value: SetComp( - ExprSetComp { - range: 155..170, - elt: Name( - ExprName { - range: 156..157, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 158..169, - target: Name( - ExprName { - range: 162..163, - id: "x", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 167..169, - value: Name( - ExprName { - range: 168..169, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 171..191, - value: SetComp( - ExprSetComp { - range: 171..191, - elt: Name( - ExprName { - range: 172..173, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 174..190, - target: Name( - ExprName { - range: 178..179, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 183..190, - value: Some( - Name( - ExprName { - range: 189..190, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 192..217, - value: SetComp( - ExprSetComp { - range: 192..217, - elt: Name( - ExprName { - range: 193..194, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 195..216, - target: Name( - ExprName { - range: 199..200, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 204..216, - value: Name( - ExprName { - range: 215..216, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 218..242, - value: SetComp( - ExprSetComp { - range: 218..242, - elt: Name( - ExprName { - range: 219..220, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 221..241, - target: Name( - ExprName { - range: 225..226, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 230..241, - parameters: Some( - Parameters { - range: 237..238, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 237..238, - parameter: Parameter { - range: 237..238, - name: Identifier { - id: "y", - range: 237..238, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 240..241, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 257..280, - value: SetComp( - ExprSetComp { - range: 257..280, - elt: Name( - ExprName { - range: 258..259, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 260..279, - target: Name( - ExprName { - range: 264..265, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 269..273, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Starred( - ExprStarred { - range: 277..279, - value: Name( - ExprName { - range: 278..279, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 281..309, - value: SetComp( - ExprSetComp { - range: 281..309, - elt: Name( - ExprName { - range: 282..283, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 284..308, - target: Name( - ExprName { - range: 288..289, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 293..297, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 301..308, - value: Some( - Name( - ExprName { - range: 307..308, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 310..343, - value: SetComp( - ExprSetComp { - range: 310..343, - elt: Name( - ExprName { - range: 311..312, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 313..342, - target: Name( - ExprName { - range: 317..318, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 322..326, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 330..342, - value: Name( - ExprName { - range: 341..342, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 344..376, - value: SetComp( - ExprSetComp { - range: 344..376, - elt: Name( - ExprName { - range: 345..346, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 347..375, - target: Name( - ExprName { - range: 351..352, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 356..360, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 364..375, - parameters: Some( - Parameters { - range: 371..372, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 371..372, - parameter: Parameter { - range: 371..372, - name: Identifier { - id: "y", - range: 371..372, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 374..375, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Iterable unpacking not allowed -2 | {*x for x in y} - | ^^ Syntax Error: Iterable unpacking cannot be used in a comprehension -3 | -4 | # Invalid target - | - - - | -4 | # Invalid target -5 | {x for 1 in y} - | ^ Syntax Error: Invalid assignment target -6 | {x for 'a' in y} -7 | {x for call() in y} - | - - - | -4 | # Invalid target -5 | {x for 1 in y} -6 | {x for 'a' in y} - | ^^^ Syntax Error: Invalid assignment target -7 | {x for call() in y} -8 | {x for {a, b} in y} - | - - - | -5 | {x for 1 in y} -6 | {x for 'a' in y} -7 | {x for call() in y} - | ^^^^^^ Syntax Error: Invalid assignment target -8 | {x for {a, b} in y} - | - - - | - 6 | {x for 'a' in y} - 7 | {x for call() in y} - 8 | {x for {a, b} in y} - | ^^^^^^ Syntax Error: Invalid assignment target - 9 | -10 | # Invalid iter - | - - - | -10 | # Invalid iter -11 | {x for x in *y} - | ^^ Syntax Error: Starred expression cannot be used here -12 | {x for x in yield y} -13 | {x for x in yield from y} - | - - - | -10 | # Invalid iter -11 | {x for x in *y} -12 | {x for x in yield y} - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -13 | {x for x in yield from y} -14 | {x for x in lambda y: y} - | - - - | -11 | {x for x in *y} -12 | {x for x in yield y} -13 | {x for x in yield from y} - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -14 | {x for x in lambda y: y} - | - - - | -12 | {x for x in yield y} -13 | {x for x in yield from y} -14 | {x for x in lambda y: y} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -15 | -16 | # Invalid if - | - - - | -16 | # Invalid if -17 | {x for x in data if *y} - | ^^ Syntax Error: Starred expression cannot be used here -18 | {x for x in data if yield y} -19 | {x for x in data if yield from y} - | - - - | -16 | # Invalid if -17 | {x for x in data if *y} -18 | {x for x in data if yield y} - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -19 | {x for x in data if yield from y} -20 | {x for x in data if lambda y: y} - | - - - | -17 | {x for x in data if *y} -18 | {x for x in data if yield y} -19 | {x for x in data if yield from y} - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -20 | {x for x in data if lambda y: y} - | - - - | -18 | {x for x in data if yield y} -19 | {x for x in data if yield from y} -20 | {x for x in data if lambda y: y} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap.new deleted file mode 100644 index 1ccac5eb0c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap.new +++ /dev/null @@ -1,43 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_closing_curly_brace_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..47, - body: [ - Expr( - StmtExpr { - range: 46..47, - value: Set( - ExprSet { - range: 46..47, - elts: [ - Name( - ExprName { - range: 47..47, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Missing closing curly brace 0: No elements -2 | -3 | { - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap.new deleted file mode 100644 index 3010e77f71..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap.new +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_closing_curly_brace_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..136, - body: [ - Expr( - StmtExpr { - range: 128..136, - value: Set( - ExprSet { - range: 128..136, - elts: [ - BinOp( - ExprBinOp { - range: 131..136, - left: Name( - ExprName { - range: 131..132, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 135..136, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | { -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap.new deleted file mode 100644 index 5bc40db8a9..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap.new +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_closing_curly_brace_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..144, - body: [ - Expr( - StmtExpr { - range: 134..144, - value: Set( - ExprSet { - range: 134..144, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 135..136, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 139..144, - left: Name( - ExprName { - range: 139..140, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 143..144, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -4 | {1, -5 | -6 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap.new deleted file mode 100644 index 1ff2ea5b37..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap.new +++ /dev/null @@ -1,83 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_closing_curly_brace_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..144, - body: [ - Expr( - StmtExpr { - range: 118..123, - value: Set( - ExprSet { - range: 118..123, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 125..144, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 129..132, - }, - type_params: None, - parameters: Parameters { - range: 132..134, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 140..144, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # token starts a statement. -3 | -4 | {1, 2 - | ^ Syntax Error: Expected '}', found newline -5 | -6 | def foo(): -7 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap.new deleted file mode 100644 index e672b6efb3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap.new +++ /dev/null @@ -1,303 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/recover.py ---- -## AST - -``` -Module( - ModModule { - range: 0..323, - body: [ - Expr( - StmtExpr { - range: 197..200, - value: Set( - ExprSet { - range: 197..200, - elts: [ - Name( - ExprName { - range: 198..198, - id: "", - ctx: Invalid, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 202..208, - value: Set( - ExprSet { - range: 202..208, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 203..204, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 206..207, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 210..215, - value: Set( - ExprSet { - range: 210..215, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 211..212, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 233..238, - value: Set( - ExprSet { - range: 233..238, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 234..235, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 236..237, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 271..277, - value: Dict( - ExprDict { - range: 271..277, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 272..273, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 275..276, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 300..309, - value: Set( - ExprSet { - range: 300..309, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 301..302, - value: Int( - 1, - ), - }, - ), - BinOp( - ExprBinOp { - range: 304..307, - left: Name( - ExprName { - range: 304..305, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 307..307, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 311..317, - value: Set( - ExprSet { - range: 311..317, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 312..313, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 315..316, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 319..322, - value: List( - ExprList { - range: 319..322, - elts: [ - Starred( - ExprStarred { - range: 320..321, - value: Name( - ExprName { - range: 321..321, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -3 | # These are same as for the list expressions. -4 | -5 | {,} - | ^ Syntax Error: Expected an expression -6 | -7 | {1,,2} - | - - - | -5 | {,} -6 | -7 | {1,,2} - | ^ Syntax Error: Expected an expression or a '}' -8 | -9 | {1,,} - | - - - | - 7 | {1,,2} - 8 | - 9 | {1,,} - | ^ Syntax Error: Expected an expression or a '}' -10 | -11 | # Missing comma - | - - - | -11 | # Missing comma -12 | {1 2} - | ^ Syntax Error: Expected ',', found int -13 | -14 | # Dictionary element in a list - | - - - | -17 | # Missing expression -18 | {1, x + } - | ^ Syntax Error: Expected an expression -19 | -20 | {1; 2} - | - - - | -18 | {1, x + } -19 | -20 | {1; 2} - | ^ Syntax Error: Expected an expression or a '}' -21 | -22 | [*] - | - - - | -20 | {1; 2} -21 | -22 | [*] - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap.new deleted file mode 100644 index 03cde32507..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap.new +++ /dev/null @@ -1,460 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/set/star_expression_precedence.py ---- -## AST - -``` -Module( - ModModule { - range: 0..198, - body: [ - Expr( - StmtExpr { - range: 83..92, - value: Set( - ExprSet { - range: 83..92, - elts: [ - Starred( - ExprStarred { - range: 85..87, - value: Name( - ExprName { - range: 86..87, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 90..91, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 93..105, - value: Set( - ExprSet { - range: 93..105, - elts: [ - Starred( - ExprStarred { - range: 94..101, - value: Compare( - ExprCompare { - range: 95..101, - left: Name( - ExprName { - range: 95..96, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 100..101, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 103..104, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 106..117, - value: Set( - ExprSet { - range: 106..117, - elts: [ - Starred( - ExprStarred { - range: 107..113, - value: UnaryOp( - ExprUnaryOp { - range: 108..113, - op: Not, - operand: Name( - ExprName { - range: 112..113, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 115..116, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 118..131, - value: Set( - ExprSet { - range: 118..131, - elts: [ - Starred( - ExprStarred { - range: 119..127, - value: BoolOp( - ExprBoolOp { - range: 120..127, - op: And, - values: [ - Name( - ExprName { - range: 120..121, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 126..127, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 129..130, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 132..144, - value: Set( - ExprSet { - range: 132..144, - elts: [ - Starred( - ExprStarred { - range: 133..140, - value: BoolOp( - ExprBoolOp { - range: 134..140, - op: Or, - values: [ - Name( - ExprName { - range: 134..135, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 139..140, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 142..143, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 145..167, - value: Set( - ExprSet { - range: 145..167, - elts: [ - Starred( - ExprStarred { - range: 146..163, - value: If( - ExprIf { - range: 147..163, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 152..156, - value: true, - }, - ), - body: Name( - ExprName { - range: 147..148, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 162..163, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 165..166, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 168..185, - value: Set( - ExprSet { - range: 168..185, - elts: [ - Starred( - ExprStarred { - range: 169..181, - value: Lambda( - ExprLambda { - range: 170..181, - parameters: Some( - Parameters { - range: 177..178, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 177..178, - parameter: Parameter { - range: 177..178, - name: Identifier { - id: "x", - range: 177..178, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 180..181, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 183..184, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 186..198, - value: Set( - ExprSet { - range: 186..198, - elts: [ - Named( - ExprNamed { - range: 187..194, - target: Starred( - ExprStarred { - range: 187..189, - value: Name( - ExprName { - range: 188..189, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 193..194, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 196..197, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # For set expression, the minimum binding power of star expression is bitwise or. -2 | -3 | {(*x), y} - | ^^ Syntax Error: Starred expression cannot be used here -4 | {*x in y, z} -5 | {*not x, z} - | - - - | -3 | {(*x), y} -4 | {*x in y, z} - | ^^^^^^ Syntax Error: Comparison expression cannot be used here -5 | {*not x, z} -6 | {*x and y, z} - | - - - | -3 | {(*x), y} -4 | {*x in y, z} -5 | {*not x, z} - | ^^^^^ Syntax Error: Boolean expression cannot be used here -6 | {*x and y, z} -7 | {*x or y, z} - | - - - | -4 | {*x in y, z} -5 | {*not x, z} -6 | {*x and y, z} - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -7 | {*x or y, z} -8 | {*x if True else y, z} - | - - - | -5 | {*not x, z} -6 | {*x and y, z} -7 | {*x or y, z} - | ^^^^^^ Syntax Error: Boolean expression cannot be used here -8 | {*x if True else y, z} -9 | {*lambda x: x, z} - | - - - | - 6 | {*x and y, z} - 7 | {*x or y, z} - 8 | {*x if True else y, z} - | ^^^^^^^^^^^^^^^^ Syntax Error: Conditional expression cannot be used here - 9 | {*lambda x: x, z} -10 | {*x := 2, z} - | - - - | - 7 | {*x or y, z} - 8 | {*x if True else y, z} - 9 | {*lambda x: x, z} - | ^^^^^^^^^^^ Syntax Error: Lambda expression cannot be used here -10 | {*x := 2, z} - | - - - | - 8 | {*x if True else y, z} - 9 | {*lambda x: x, z} -10 | {*x := 2, z} - | ^^ Syntax Error: Assignment expression target must be an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap.new deleted file mode 100644 index 66393e6613..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap.new +++ /dev/null @@ -1,304 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/invalid_slice_element.py ---- -## AST - -``` -Module( - ModModule { - range: 0..133, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Subscript( - ExprSubscript { - range: 0..10, - value: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 2..9, - lower: Some( - Named( - ExprNamed { - range: 2..8, - target: Name( - ExprName { - range: 2..3, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 7..8, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 33..39, - value: Subscript( - ExprSubscript { - range: 33..39, - value: Name( - ExprName { - range: 33..34, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 35..38, - lower: Some( - Starred( - ExprStarred { - range: 35..37, - value: Name( - ExprName { - range: 36..37, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 40..46, - value: Subscript( - ExprSubscript { - range: 40..46, - value: Name( - ExprName { - range: 40..41, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 42..45, - lower: None, - upper: Some( - Starred( - ExprStarred { - range: 43..45, - value: Name( - ExprName { - range: 44..45, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 47..54, - value: Subscript( - ExprSubscript { - range: 47..54, - value: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 49..53, - lower: None, - upper: None, - step: Some( - Starred( - ExprStarred { - range: 51..53, - value: Name( - ExprName { - range: 52..53, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 70..73, - value: Subscript( - ExprSubscript { - range: 70..73, - value: Name( - ExprName { - range: 70..71, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 72..73, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 123..133, - value: Subscript( - ExprSubscript { - range: 123..133, - value: Name( - ExprName { - range: 123..124, - id: "x", - ctx: Load, - }, - ), - slice: Named( - ExprNamed { - range: 125..132, - target: Starred( - ExprStarred { - range: 125..127, - value: Name( - ExprName { - range: 126..127, - id: "x", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 131..132, - value: Int( - 1, - ), - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x[x := 1:] - | ^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here -2 | -3 | # Starred expression - | - - - | -3 | # Starred expression -4 | x[*x:] - | ^^ Syntax Error: Starred expression cannot be used here -5 | x[:*x] -6 | x[::*x] - | - - - | -3 | # Starred expression -4 | x[*x:] -5 | x[:*x] - | ^^ Syntax Error: Starred expression cannot be used here -6 | x[::*x] - | - - - | -4 | x[*x:] -5 | x[:*x] -6 | x[::*x] - | ^^ Syntax Error: Starred expression cannot be used here -7 | -8 | # Empty slice - | - - - | - 8 | # Empty slice - 9 | x[] - | ^ Syntax Error: Expected index or slice expression -10 | -11 | # Mixed starred expression and named expression - | - - - | -11 | # Mixed starred expression and named expression -12 | x[*x := 1] - | ^^ Syntax Error: Assignment expression target must be an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap.new deleted file mode 100644 index d9e5673f7d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap.new +++ /dev/null @@ -1,71 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/unclosed_slice_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Subscript( - ExprSubscript { - range: 0..10, - value: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 2..10, - lower: None, - upper: Some( - BinOp( - ExprBinOp { - range: 5..10, - left: Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 9..10, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x[: -2 | -3 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap.new deleted file mode 100644 index 915600a7ce..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap.new +++ /dev/null @@ -1,113 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/unclosed_slice_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..25, - body: [ - Expr( - StmtExpr { - range: 0..9, - value: Subscript( - ExprSubscript { - range: 0..9, - value: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 2..9, - lower: None, - upper: None, - step: Some( - Name( - ExprName { - range: 6..9, - id: "def", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 10..25, - target: Call( - ExprCall { - range: 10..15, - func: Name( - ExprName { - range: 10..13, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 13..15, - args: [], - keywords: [], - }, - }, - ), - annotation: Name( - ExprName { - range: 21..25, - id: "pass", - ctx: Load, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | x[:: -2 | -3 | def foo(): - | ^^^ Syntax Error: Expected an identifier, but found a keyword 'def' that cannot be used here -4 | pass - | - - - | -1 | x[:: -2 | -3 | def foo(): - | ^^^ Syntax Error: Expected ']', found name -4 | pass - | - - - | -3 | def foo(): -4 | pass - | ^^^^ Syntax Error: Expected an identifier, but found a keyword 'pass' that cannot be used here - | - - - | -3 | def foo(): -4 | pass - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap.new deleted file mode 100644 index a3b5c9b04d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap.new +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/unary.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: UnaryOp( - ExprUnaryOp { - range: 0..5, - op: Not, - operand: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 9..10, - value: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | not x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap.new deleted file mode 100644 index c6a90a2533..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap.new +++ /dev/null @@ -1,92 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/named_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..18, - body: [ - Expr( - StmtExpr { - range: 0..2, - value: UnaryOp( - ExprUnaryOp { - range: 0..2, - op: USub, - operand: Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 6..7, - value: NumberLiteral( - ExprNumberLiteral { - range: 6..7, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..13, - value: UnaryOp( - ExprUnaryOp { - range: 8..13, - op: Not, - operand: Name( - ExprName { - range: 12..13, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 17..18, - value: NumberLiteral( - ExprNumberLiteral { - range: 17..18, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | -x := 1 - | ^^ Syntax Error: Expected a statement -2 | not x := 1 - | - - - | -1 | -x := 1 -2 | not x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap.new deleted file mode 100644 index 1b8a58c942..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap.new +++ /dev/null @@ -1,67 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/no_expression_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..10, - body: [ - Expr( - StmtExpr { - range: 0..3, - value: UnaryOp( - ExprUnaryOp { - range: 0..3, - op: Not, - operand: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..10, - value: BinOp( - ExprBinOp { - range: 5..10, - left: Name( - ExprName { - range: 5..6, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 9..10, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | not - | ^ Syntax Error: Expected an expression -2 | -3 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap.new deleted file mode 100644 index 55338d6840..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap.new +++ /dev/null @@ -1,67 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/no_expression_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..8, - body: [ - Expr( - StmtExpr { - range: 0..1, - value: UnaryOp( - ExprUnaryOp { - range: 0..1, - op: UAdd, - operand: Name( - ExprName { - range: 1..1, - id: "", - ctx: Invalid, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 3..8, - value: BinOp( - ExprBinOp { - range: 3..8, - left: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 7..8, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | + - | ^ Syntax Error: Expected an expression -2 | -3 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap.new deleted file mode 100644 index 44e5e6210d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap.new +++ /dev/null @@ -1,117 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/yield/named_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..85, - body: [ - Expr( - StmtExpr { - range: 52..59, - value: Yield( - ExprYield { - range: 52..59, - value: Some( - Name( - ExprName { - range: 58..59, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 63..64, - value: NumberLiteral( - ExprNumberLiteral { - range: 63..64, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 66..84, - value: Yield( - ExprYield { - range: 66..84, - value: Some( - Tuple( - ExprTuple { - range: 72..84, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 72..73, - value: Int( - 1, - ), - }, - ), - Name( - ExprName { - range: 75..76, - id: "x", - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 80..81, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Unparenthesized named expressions are not allowed -2 | yield x := 1 - | ^^ Syntax Error: Expected a statement -3 | -4 | yield 1, x := 2, 3 - | - - - | -2 | yield x := 1 -3 | -4 | yield 1, x := 2, 3 - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap.new deleted file mode 100644 index 442d8a004a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap.new +++ /dev/null @@ -1,114 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/yield/star_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - Expr( - StmtExpr { - range: 37..47, - value: Yield( - ExprYield { - range: 37..47, - value: Some( - Starred( - ExprStarred { - range: 44..46, - value: Name( - ExprName { - range: 45..46, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..66, - value: Yield( - ExprYield { - range: 49..66, - value: Some( - Tuple( - ExprTuple { - range: 55..66, - elts: [ - Starred( - ExprStarred { - range: 55..63, - value: BoolOp( - ExprBoolOp { - range: 56..63, - op: And, - values: [ - Name( - ExprName { - range: 56..57, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 62..63, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 65..66, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Cannot use starred expression here -2 | yield (*x) - | ^^ Syntax Error: Starred expression cannot be used here -3 | -4 | yield *x and y, z - | - - - | -2 | yield (*x) -3 | -4 | yield *x and y, z - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap.new deleted file mode 100644 index 66a2eb6ac1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap.new +++ /dev/null @@ -1,94 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/yield_from/starred_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..100, - body: [ - Expr( - StmtExpr { - range: 70..83, - value: YieldFrom( - ExprYieldFrom { - range: 70..83, - value: Starred( - ExprStarred { - range: 81..83, - value: Name( - ExprName { - range: 82..83, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 84..100, - value: YieldFrom( - ExprYieldFrom { - range: 84..100, - value: Tuple( - ExprTuple { - range: 95..100, - elts: [ - Starred( - ExprStarred { - range: 95..97, - value: Name( - ExprName { - range: 96..97, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 99..100, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Yield from doesn't allow top-level starred expression unlike yield -2 | -3 | yield from *x - | ^^ Syntax Error: Starred expression cannot be used here -4 | yield from *x, y - | - - - | -3 | yield from *x -4 | yield from *x, y - | ^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap.new deleted file mode 100644 index 8a05fa6b2b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap.new +++ /dev/null @@ -1,159 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/expressions/yield_from/unparenthesized.py ---- -## AST - -``` -Module( - ModModule { - range: 0..192, - body: [ - Expr( - StmtExpr { - range: 35..47, - value: YieldFrom( - ExprYieldFrom { - range: 35..47, - value: Name( - ExprName { - range: 46..47, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 51..52, - value: NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 89..104, - value: YieldFrom( - ExprYieldFrom { - range: 89..104, - value: Tuple( - ExprTuple { - range: 100..104, - elts: [ - Name( - ExprName { - range: 100..101, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 103..104, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 168..192, - value: YieldFrom( - ExprYieldFrom { - range: 168..192, - value: Tuple( - ExprTuple { - range: 179..192, - elts: [ - Name( - ExprName { - range: 180..181, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 183..191, - value: BoolOp( - ExprBoolOp { - range: 184..191, - op: And, - values: [ - Name( - ExprName { - range: 184..185, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 190..191, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Unparenthesized named expression -2 | yield from x := 1 - | ^^ Syntax Error: Expected a statement -3 | -4 | # Unparenthesized tuple expression - | - - - | -4 | # Unparenthesized tuple expression -5 | yield from x, y - | ^^^^ Syntax Error: Unparenthesized tuple expression cannot be used here -6 | -7 | # This is a tuple expression parsing - | - - - | -7 | # This is a tuple expression parsing -8 | # vvvvvvvvvvvvv -9 | yield from (x, *x and y) - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap.new deleted file mode 100644 index 2ccfb5cb00..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap.new +++ /dev/null @@ -1,112 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_empty_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..14, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: FString( - ExprFString { - range: 0..5, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..5, - elements: [ - Expression( - FStringExpressionElement { - range: 2..4, - expression: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 6..13, - value: FString( - ExprFString { - range: 6..13, - value: FStringValue { - inner: Single( - FString( - FString { - range: 6..13, - elements: [ - Expression( - FStringExpressionElement { - range: 8..12, - expression: Name( - ExprName { - range: 9..9, - id: "", - ctx: Invalid, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"{}" - | ^ Syntax Error: Expected an expression -2 | f"{ }" - | - - - | -1 | f"{}" -2 | f"{ }" - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap.new deleted file mode 100644 index 8e0935bcc6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap.new +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_conversion_flag_name_tok.py ---- -## AST - -``` -Module( - ModModule { - range: 0..9, - body: [ - Expr( - StmtExpr { - range: 0..8, - value: FString( - ExprFString { - range: 0..8, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..8, - elements: [ - Expression( - FStringExpressionElement { - range: 2..7, - expression: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"{x!z}" - | ^ Syntax Error: f-string: invalid conversion character - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap.new deleted file mode 100644 index 25b801d24f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap.new +++ /dev/null @@ -1,112 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_conversion_flag_other_tok.py ---- -## AST - -``` -Module( - ModModule { - range: 0..22, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: FString( - ExprFString { - range: 0..10, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..10, - elements: [ - Expression( - FStringExpressionElement { - range: 2..9, - expression: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..21, - value: FString( - ExprFString { - range: 11..21, - value: FStringValue { - inner: Single( - FString( - FString { - range: 11..21, - elements: [ - Expression( - FStringExpressionElement { - range: 13..20, - expression: Name( - ExprName { - range: 14..15, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"{x!123}" - | ^^^ Syntax Error: f-string: invalid conversion character -2 | f"{x!'a'}" - | - - - | -1 | f"{x!123}" -2 | f"{x!'a'}" - | ^^^ Syntax Error: f-string: invalid conversion character - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap.new deleted file mode 100644 index 0775b47790..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap.new +++ /dev/null @@ -1,205 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_starred_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..112, - body: [ - Expr( - StmtExpr { - range: 77..83, - value: FString( - ExprFString { - range: 77..83, - value: FStringValue { - inner: Single( - FString( - FString { - range: 77..83, - elements: [ - Expression( - FStringExpressionElement { - range: 79..82, - expression: Starred( - ExprStarred { - range: 80..81, - value: Name( - ExprName { - range: 81..81, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 84..97, - value: FString( - ExprFString { - range: 84..97, - value: FStringValue { - inner: Single( - FString( - FString { - range: 84..97, - elements: [ - Expression( - FStringExpressionElement { - range: 86..96, - expression: Starred( - ExprStarred { - range: 87..95, - value: BoolOp( - ExprBoolOp { - range: 88..95, - op: And, - values: [ - Name( - ExprName { - range: 88..89, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 94..95, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 98..111, - value: FString( - ExprFString { - range: 98..111, - value: FStringValue { - inner: Single( - FString( - FString { - range: 98..111, - elements: [ - Expression( - FStringExpressionElement { - range: 100..110, - expression: Starred( - ExprStarred { - range: 101..109, - value: Yield( - ExprYield { - range: 102..109, - value: Some( - Name( - ExprName { - range: 108..109, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Starred expression inside f-string has a minimum precedence of bitwise or. -2 | f"{*}" - | ^ Syntax Error: Expected an expression -3 | f"{*x and y}" -4 | f"{*yield x}" - | - - - | -1 | # Starred expression inside f-string has a minimum precedence of bitwise or. -2 | f"{*}" -3 | f"{*x and y}" - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -4 | f"{*yield x}" - | - - - | -2 | f"{*}" -3 | f"{*x and y}" -4 | f"{*yield x}" - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap.new deleted file mode 100644 index 2ecb44d983..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap.new +++ /dev/null @@ -1,115 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_lambda_without_parentheses.py ---- -## AST - -``` -Module( - ModModule { - range: 0..17, - body: [ - Expr( - StmtExpr { - range: 0..16, - value: FString( - ExprFString { - range: 0..16, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..16, - elements: [ - Expression( - FStringExpressionElement { - range: 2..12, - expression: Lambda( - ExprLambda { - range: 3..12, - parameters: Some( - Parameters { - range: 10..11, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 10..11, - parameter: Parameter { - range: 10..11, - name: Identifier { - id: "x", - range: 10..11, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 12..12, - id: "", - ctx: Invalid, - }, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 12..14, - value: " x", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"{lambda x: x}" - | ^^ Syntax Error: Expected an expression - | - - - | -1 | f"{lambda x: x}" - | ^^^^^^^^^ Syntax Error: f-string: lambda expressions are not allowed without parentheses - | - - - | -1 | f"{lambda x: x}" - | ^^ Syntax Error: f-string: expecting '}' - | - - - | -1 | f"{lambda x: x}" - | ^ Syntax Error: Expected an f-string element or the end of the f-string - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap.new deleted file mode 100644 index 80fcb0c07a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap.new +++ /dev/null @@ -1,351 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_unclosed_lbrace.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - Expr( - StmtExpr { - range: 0..4, - value: FString( - ExprFString { - range: 0..4, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..4, - elements: [ - Expression( - FStringExpressionElement { - range: 2..3, - expression: Name( - ExprName { - range: 3..3, - id: "", - ctx: Invalid, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..14, - value: FString( - ExprFString { - range: 5..14, - value: FStringValue { - inner: Single( - FString( - FString { - range: 5..14, - elements: [ - Expression( - FStringExpressionElement { - range: 7..14, - expression: Name( - ExprName { - range: 8..11, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 15..23, - value: FString( - ExprFString { - range: 15..23, - value: FStringValue { - inner: Single( - FString( - FString { - range: 15..23, - elements: [ - Expression( - FStringExpressionElement { - range: 17..22, - expression: Name( - ExprName { - range: 18..21, - id: "foo", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 24..37, - value: FString( - ExprFString { - range: 24..37, - value: FStringValue { - inner: Concatenated( - [ - FString( - FString { - range: 24..28, - elements: [ - Expression( - FStringExpressionElement { - range: 26..27, - expression: Name( - ExprName { - range: 27..27, - id: "", - ctx: Invalid, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 29..37, - elements: [ - Expression( - FStringExpressionElement { - range: 33..34, - expression: Name( - ExprName { - range: 34..34, - id: "", - ctx: Invalid, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"{" - | ^ Syntax Error: missing closing quote in string literal -2 | f"{foo!r" -3 | f"{foo=" - | - - - | -1 | f"{" - | Syntax Error: f-string: unterminated string -2 | f"{foo!r" -3 | f"{foo=" - | - - - | -1 | f"{" - | Syntax Error: f-string: unterminated string -2 | f"{foo!r" -3 | f"{foo=" - | - - - | -1 | f"{" -2 | f"{foo!r" - | ^^ Syntax Error: missing closing quote in string literal -3 | f"{foo=" -4 | f"{" - | - - - | -1 | f"{" -2 | f"{foo!r" - | Syntax Error: f-string: unterminated string -3 | f"{foo=" -4 | f"{" - | - - - | -1 | f"{" -2 | f"{foo!r" - | Syntax Error: f-string: unterminated string -3 | f"{foo=" -4 | f"{" - | - - - | -1 | f"{" -2 | f"{foo!r" -3 | f"{foo=" - | ^^ Syntax Error: f-string: expecting '}' -4 | f"{" -5 | f"""{""" - | - - - | -1 | f"{" -2 | f"{foo!r" - | Syntax Error: Expected FStringEnd, found Unknown -3 | f"{foo=" -4 | f"{" - | - - - | -1 | f"{" -2 | f"{foo!r" -3 | f"{foo=" - | ^ Syntax Error: missing closing quote in string literal -4 | f"{" -5 | f"""{""" - | - - - | -1 | f"{" -2 | f"{foo!r" -3 | f"{foo=" - | Syntax Error: f-string: unterminated string -4 | f"{" -5 | f"""{""" - | - - - | -1 | f"{" -2 | f"{foo!r" -3 | f"{foo=" - | Syntax Error: f-string: unterminated string -4 | f"{" -5 | f"""{""" - | - - - | -2 | f"{foo!r" -3 | f"{foo=" -4 | f"{" - | ^ Syntax Error: missing closing quote in string literal -5 | f"""{""" - | - - - | -3 | f"{foo=" -4 | f"{" -5 | f"""{""" - | ^^^^ Syntax Error: Expected FStringEnd, found FStringStart - | - - - | -3 | f"{foo=" -4 | f"{" -5 | f"""{""" - | ^^^ Syntax Error: Expected an expression - | - - - | -4 | f"{" -5 | f"""{""" - | - - - | -4 | f"{" -5 | f"""{""" - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap.new deleted file mode 100644 index aa73ebc37c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap.new +++ /dev/null @@ -1,141 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/f_string_unclosed_lbrace_in_format_spec.py ---- -## AST - -``` -Module( - ModModule { - range: 0..29, - body: [ - Expr( - StmtExpr { - range: 0..12, - value: FString( - ExprFString { - range: 0..12, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..12, - elements: [ - Literal( - FStringLiteralElement { - range: 2..8, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 8..11, - expression: Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 11..11, - elements: [], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..28, - value: FString( - ExprFString { - range: 13..28, - value: FStringValue { - inner: Single( - FString( - FString { - range: 13..28, - elements: [ - Literal( - FStringLiteralElement { - range: 15..21, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 21..27, - expression: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 24..27, - elements: [ - Literal( - FStringLiteralElement { - range: 24..27, - value: ".3f", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"hello {x:" - | ^ Syntax Error: f-string: expecting '}' -2 | f"hello {x:.3f" - | - - - | -1 | f"hello {x:" -2 | f"hello {x:.3f" - | ^ Syntax Error: f-string: expecting '}' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap.new deleted file mode 100644 index 6e80134f74..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap.new +++ /dev/null @@ -1,184 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_iter_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..71, - body: [ - For( - StmtFor { - range: 0..22, - is_async: false, - target: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 9..17, - value: BoolOp( - ExprBoolOp { - range: 10..17, - op: And, - values: [ - Name( - ExprName { - range: 10..11, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 16..17, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 23..44, - is_async: false, - target: Name( - ExprName { - range: 27..28, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 32..39, - value: Some( - Name( - ExprName { - range: 38..39, - id: "a", - ctx: Load, - }, - ), - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 41..44, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 41..44, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 45..60, - is_async: false, - target: Name( - ExprName { - range: 49..55, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 59..60, - id: "x", - ctx: Load, - }, - ), - body: [], - orelse: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 64..70, - target: NumberLiteral( - ExprNumberLiteral { - range: 64..65, - value: Int( - 1, - ), - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 67..70, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for x in *a and b: ... - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -2 | for x in yield a: ... -3 | for target in x := 1: ... - | - - - | -1 | for x in *a and b: ... -2 | for x in yield a: ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | for target in x := 1: ... - | - - - | -1 | for x in *a and b: ... -2 | for x in yield a: ... -3 | for target in x := 1: ... - | ^^ Syntax Error: Expected ':', found ':=' - | - - - | -1 | for x in *a and b: ... -2 | for x in yield a: ... -3 | for target in x := 1: ... - | ^ Syntax Error: Invalid annotated assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap.new deleted file mode 100644 index a05e014f07..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap.new +++ /dev/null @@ -1,464 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..154, - body: [ - For( - StmtFor { - range: 0..15, - is_async: false, - target: NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), - iter: Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 12..15, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 12..15, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 16..33, - is_async: false, - target: StringLiteral( - ExprStringLiteral { - range: 20..23, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 20..23, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - iter: Name( - ExprName { - range: 27..28, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 30..33, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 30..33, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 34..56, - is_async: false, - target: Starred( - ExprStarred { - range: 38..46, - value: BoolOp( - ExprBoolOp { - range: 39..46, - op: And, - values: [ - Name( - ExprName { - range: 39..40, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 45..46, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 50..51, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 53..56, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 53..56, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 57..77, - is_async: false, - target: Starred( - ExprStarred { - range: 61..67, - value: BinOp( - ExprBinOp { - range: 62..67, - left: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 66..67, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 71..72, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 74..77, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 74..77, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 78..99, - is_async: false, - target: Await( - ExprAwait { - range: 82..89, - value: Name( - ExprName { - range: 88..89, - id: "x", - ctx: Load, - }, - ), - }, - ), - iter: Name( - ExprName { - range: 93..94, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 96..99, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 96..99, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 100..121, - is_async: false, - target: Yield( - ExprYield { - range: 104..116, - value: Some( - Compare( - ExprCompare { - range: 110..116, - left: Name( - ExprName { - range: 110..111, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 115..116, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - iter: Name( - ExprName { - range: 116..116, - id: "", - ctx: Invalid, - }, - ), - body: [ - Expr( - StmtExpr { - range: 118..121, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 118..121, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 122..153, - is_async: false, - target: List( - ExprList { - range: 126..143, - elts: [ - Name( - ExprName { - range: 127..128, - id: "x", - ctx: Store, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 130..131, - value: Int( - 1, - ), - }, - ), - Name( - ExprName { - range: 133..134, - id: "y", - ctx: Store, - }, - ), - Starred( - ExprStarred { - range: 136..142, - value: List( - ExprList { - range: 137..142, - elts: [ - StringLiteral( - ExprStringLiteral { - range: 138..141, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 138..141, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 147..148, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 150..153, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 150..153, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for 1 in x: ... - | ^ Syntax Error: Invalid assignment target -2 | for "a" in x: ... -3 | for *x and y in z: ... - | - - - | -1 | for 1 in x: ... -2 | for "a" in x: ... - | ^^^ Syntax Error: Invalid assignment target -3 | for *x and y in z: ... -4 | for *x | y in z: ... - | - - - | -1 | for 1 in x: ... -2 | for "a" in x: ... -3 | for *x and y in z: ... - | ^^^^^^^ Syntax Error: Invalid assignment target -4 | for *x | y in z: ... -5 | for await x in z: ... - | - - - | -2 | for "a" in x: ... -3 | for *x and y in z: ... -4 | for *x | y in z: ... - | ^^^^^ Syntax Error: Invalid assignment target -5 | for await x in z: ... -6 | for yield x in y: ... - | - - - | -3 | for *x and y in z: ... -4 | for *x | y in z: ... -5 | for await x in z: ... - | ^^^^^^^ Syntax Error: Invalid assignment target -6 | for yield x in y: ... -7 | for [x, 1, y, *["a"]] in z: ... - | - - - | -4 | for *x | y in z: ... -5 | for await x in z: ... -6 | for yield x in y: ... - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -7 | for [x, 1, y, *["a"]] in z: ... - | - - - | -4 | for *x | y in z: ... -5 | for await x in z: ... -6 | for yield x in y: ... - | ^ Syntax Error: Expected 'in', found ':' -7 | for [x, 1, y, *["a"]] in z: ... - | - - - | -5 | for await x in z: ... -6 | for yield x in y: ... -7 | for [x, 1, y, *["a"]] in z: ... - | ^ Syntax Error: Invalid assignment target - | - - - | -5 | for await x in z: ... -6 | for yield x in y: ... -7 | for [x, 1, y, *["a"]] in z: ... - | ^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap.new deleted file mode 100644 index 88c3861d2b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap.new +++ /dev/null @@ -1,342 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_target_binary_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..124, - body: [ - For( - StmtFor { - range: 0..24, - is_async: false, - target: Compare( - ExprCompare { - range: 4..14, - left: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 13..14, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 18..19, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 21..24, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 21..24, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 25..45, - is_async: false, - target: Compare( - ExprCompare { - range: 29..35, - left: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 34..35, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 39..40, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 42..45, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 42..45, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 46..66, - is_async: false, - target: BoolOp( - ExprBoolOp { - range: 50..56, - op: Or, - values: [ - Name( - ExprName { - range: 50..51, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 55..56, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 60..61, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 63..66, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 63..66, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 67..83, - is_async: false, - target: UnaryOp( - ExprUnaryOp { - range: 71..73, - op: USub, - operand: Name( - ExprName { - range: 72..73, - id: "x", - ctx: Store, - }, - ), - }, - ), - iter: Name( - ExprName { - range: 77..78, - id: "y", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 80..83, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 80..83, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 84..103, - is_async: false, - target: UnaryOp( - ExprUnaryOp { - range: 88..93, - op: Not, - operand: Name( - ExprName { - range: 92..93, - id: "x", - ctx: Store, - }, - ), - }, - ), - iter: Name( - ExprName { - range: 97..98, - id: "y", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 100..103, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 100..103, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 104..123, - is_async: false, - target: BinOp( - ExprBinOp { - range: 108..113, - left: Name( - ExprName { - range: 108..109, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 112..113, - id: "y", - ctx: Load, - }, - ), - }, - ), - iter: Name( - ExprName { - range: 117..118, - id: "z", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 120..123, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 120..123, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for x not in y in z: ... - | ^^^^^^^^^^ Syntax Error: Invalid assignment target -2 | for x == y in z: ... -3 | for x or y in z: ... - | - - - | -1 | for x not in y in z: ... -2 | for x == y in z: ... - | ^^^^^^ Syntax Error: Invalid assignment target -3 | for x or y in z: ... -4 | for -x in y: ... - | - - - | -1 | for x not in y in z: ... -2 | for x == y in z: ... -3 | for x or y in z: ... - | ^^^^^^ Syntax Error: Invalid assignment target -4 | for -x in y: ... -5 | for not x in y: ... - | - - - | -2 | for x == y in z: ... -3 | for x or y in z: ... -4 | for -x in y: ... - | ^^ Syntax Error: Invalid assignment target -5 | for not x in y: ... -6 | for x | y in z: ... - | - - - | -3 | for x or y in z: ... -4 | for -x in y: ... -5 | for not x in y: ... - | ^^^^^ Syntax Error: Invalid assignment target -6 | for x | y in z: ... - | - - - | -4 | for -x in y: ... -5 | for not x in y: ... -6 | for x | y in z: ... - | ^^^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap.new deleted file mode 100644 index e4187c32d9..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap.new +++ /dev/null @@ -1,443 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_target_in_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..170, - body: [ - For( - StmtFor { - range: 0..28, - is_async: false, - target: Call( - ExprCall { - range: 4..13, - func: Name( - ExprName { - range: 4..5, - id: "d", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5..13, - args: [ - Compare( - ExprCompare { - range: 6..12, - left: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 11..12, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ], - keywords: [], - }, - }, - ), - iter: Name( - ExprName { - range: 17..23, - id: "target", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 29..56, - is_async: false, - target: Call( - ExprCall { - range: 33..43, - func: Compare( - ExprCompare { - range: 34..40, - left: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 39..40, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - arguments: Arguments { - range: 41..43, - args: [], - keywords: [], - }, - }, - ), - iter: Name( - ExprName { - range: 47..51, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 53..56, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 53..56, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 57..82, - is_async: false, - target: Compare( - ExprCompare { - range: 62..68, - left: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 67..68, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 73..77, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 79..82, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 79..82, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 83..111, - is_async: false, - target: Tuple( - ExprTuple { - range: 87..98, - elts: [ - Compare( - ExprCompare { - range: 88..94, - left: Name( - ExprName { - range: 88..89, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 93..94, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 96..97, - id: "z", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - iter: Name( - ExprName { - range: 102..106, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 108..111, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 108..111, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 112..140, - is_async: false, - target: List( - ExprList { - range: 116..127, - elts: [ - Compare( - ExprCompare { - range: 117..123, - left: Name( - ExprName { - range: 117..118, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 122..123, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 125..126, - id: "z", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 131..135, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 137..140, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 137..140, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 141..169, - is_async: false, - target: Set( - ExprSet { - range: 145..156, - elts: [ - Compare( - ExprCompare { - range: 146..152, - left: Name( - ExprName { - range: 146..147, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 151..152, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 154..155, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - iter: Name( - ExprName { - range: 160..164, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 166..169, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 166..169, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for d(x in y) in target: ... - | ^^^^^^^^^ Syntax Error: Invalid assignment target -2 | for (x in y)() in iter: ... -3 | for (x in y) in iter: ... - | - - - | -1 | for d(x in y) in target: ... -2 | for (x in y)() in iter: ... - | ^^^^^^^^^^ Syntax Error: Invalid assignment target -3 | for (x in y) in iter: ... -4 | for (x in y, z) in iter: ... - | - - - | -1 | for d(x in y) in target: ... -2 | for (x in y)() in iter: ... -3 | for (x in y) in iter: ... - | ^^^^^^ Syntax Error: Invalid assignment target -4 | for (x in y, z) in iter: ... -5 | for [x in y, z] in iter: ... - | - - - | -2 | for (x in y)() in iter: ... -3 | for (x in y) in iter: ... -4 | for (x in y, z) in iter: ... - | ^^^^^^ Syntax Error: Invalid assignment target -5 | for [x in y, z] in iter: ... -6 | for {x in y, z} in iter: ... - | - - - | -3 | for (x in y) in iter: ... -4 | for (x in y, z) in iter: ... -5 | for [x in y, z] in iter: ... - | ^^^^^^ Syntax Error: Invalid assignment target -6 | for {x in y, z} in iter: ... - | - - - | -4 | for (x in y, z) in iter: ... -5 | for [x in y, z] in iter: ... -6 | for {x in y, z} in iter: ... - | ^^^^^^^^^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap.new deleted file mode 100644 index 012a1f8531..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap.new +++ /dev/null @@ -1,96 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_in_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - For( - StmtFor { - range: 0..12, - is_async: false, - target: Name( - ExprName { - range: 4..5, - id: "a", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 6..7, - id: "b", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 9..12, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 9..12, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 13..23, - is_async: false, - target: Name( - ExprName { - range: 17..18, - id: "a", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 18..18, - id: "", - ctx: Invalid, - }, - ), - body: [ - Expr( - StmtExpr { - range: 20..23, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 20..23, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for a b: ... - | ^ Syntax Error: Expected 'in', found name -2 | for a: ... - | - - - | -1 | for a b: ... -2 | for a: ... - | ^ Syntax Error: Expected 'in', found ':' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap.new deleted file mode 100644 index 12e6d79e63..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap.new +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_iter.py ---- -## AST - -``` -Module( - ModModule { - range: 0..20, - body: [ - For( - StmtFor { - range: 0..19, - is_async: false, - target: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 8..8, - id: "", - ctx: Invalid, - }, - ), - body: [ - Assign( - StmtAssign { - range: 14..19, - targets: [ - Name( - ExprName { - range: 14..15, - id: "a", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for x in: - | ^ Syntax Error: Expected an expression -2 | a = 1 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap.new deleted file mode 100644 index a1a3319155..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap.new +++ /dev/null @@ -1,61 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..14, - body: [ - For( - StmtFor { - range: 0..13, - is_async: false, - target: Name( - ExprName { - range: 4..6, - id: "in", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 10..13, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 10..13, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | for in x: ... - | ^^ Syntax Error: Expected an identifier, but found a keyword 'in' that cannot be used here - | - - - | -1 | for in x: ... - | ^ Syntax Error: Expected 'in', found name - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap.new deleted file mode 100644 index 12a9d76932..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap.new +++ /dev/null @@ -1,170 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_dotted_names.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..16, - module: Some( - Identifier { - id: "x", - range: 5..6, - }, - ), - names: [ - Alias { - range: 14..15, - name: Identifier { - id: "a", - range: 14..15, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 17..34, - module: Some( - Identifier { - id: "x", - range: 22..23, - }, - ), - names: [ - Alias { - range: 31..32, - name: Identifier { - id: "a", - range: 31..32, - }, - asname: None, - }, - Alias { - range: 33..34, - name: Identifier { - id: "b", - range: 33..34, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 35..66, - module: Some( - Identifier { - id: "x", - range: 40..41, - }, - ), - names: [ - Alias { - range: 49..50, - name: Identifier { - id: "a", - range: 49..50, - }, - asname: None, - }, - Alias { - range: 52..53, - name: Identifier { - id: "b", - range: 52..53, - }, - asname: None, - }, - Alias { - range: 54..55, - name: Identifier { - id: "c", - range: 54..55, - }, - asname: None, - }, - Alias { - range: 57..58, - name: Identifier { - id: "d", - range: 57..58, - }, - asname: None, - }, - Alias { - range: 60..61, - name: Identifier { - id: "e", - range: 60..61, - }, - asname: None, - }, - Alias { - range: 62..63, - name: Identifier { - id: "f", - range: 62..63, - }, - asname: None, - }, - Alias { - range: 65..66, - name: Identifier { - id: "g", - range: 65..66, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from x import a. - | ^ Syntax Error: Expected ',', found '.' -2 | from x import a.b -3 | from x import a, b.c, d, e.f, g - | - - - | -1 | from x import a. -2 | from x import a.b - | ^ Syntax Error: Expected ',', found '.' -3 | from x import a, b.c, d, e.f, g - | - - - | -1 | from x import a. -2 | from x import a.b -3 | from x import a, b.c, d, e.f, g - | ^ Syntax Error: Expected ',', found '.' - | - - - | -1 | from x import a. -2 | from x import a.b -3 | from x import a, b.c, d, e.f, g - | ^ Syntax Error: Expected ',', found '.' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap.new deleted file mode 100644 index c4e4be1679..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap.new +++ /dev/null @@ -1,95 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_empty_names.py ---- -## AST - -``` -Module( - ModModule { - range: 0..48, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..13, - module: Some( - Identifier { - id: "x", - range: 5..6, - }, - ), - names: [], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 14..30, - module: Some( - Identifier { - id: "x", - range: 19..20, - }, - ), - names: [], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 31..47, - module: Some( - Identifier { - id: "x", - range: 36..37, - }, - ), - names: [], - level: 0, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from x import - | ^ Syntax Error: Expected one or more symbol names after import -2 | from x import () -3 | from x import ,, - | - - - | -1 | from x import -2 | from x import () - | ^ Syntax Error: Expected one or more symbol names after import -3 | from x import ,, - | - - - | -1 | from x import -2 | from x import () -3 | from x import ,, - | ^ Syntax Error: Expected an import name - | - - - | -1 | from x import -2 | from x import () -3 | from x import ,, - | ^ Syntax Error: Expected an import name - | - - - | -1 | from x import -2 | from x import () -3 | from x import ,, - | ^ Syntax Error: Expected one or more symbol names after import - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap.new deleted file mode 100644 index 05076a015a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap.new +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_missing_module.py ---- -## AST - -``` -Module( - ModModule { - range: 0..19, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..4, - module: None, - names: [], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 5..18, - module: None, - names: [ - Alias { - range: 17..18, - name: Identifier { - id: "x", - range: 17..18, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from - | ^ Syntax Error: Expected a module name -2 | from import x - | - - - | -1 | from -2 | from import x - | ^^^^^^ Syntax Error: Expected a module name - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap.new deleted file mode 100644 index 87e944f5f7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap.new +++ /dev/null @@ -1,148 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_missing_rpar.py ---- -## AST - -``` -Module( - ModModule { - range: 0..53, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..19, - module: Some( - Identifier { - id: "x", - range: 5..6, - }, - ), - names: [ - Alias { - range: 15..16, - name: Identifier { - id: "a", - range: 15..16, - }, - asname: None, - }, - Alias { - range: 18..19, - name: Identifier { - id: "b", - range: 18..19, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 20..25, - value: BinOp( - ExprBinOp { - range: 20..25, - left: NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 24..25, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ImportFrom( - StmtImportFrom { - range: 26..46, - module: Some( - Identifier { - id: "x", - range: 31..32, - }, - ), - names: [ - Alias { - range: 41..42, - name: Identifier { - id: "a", - range: 41..42, - }, - asname: None, - }, - Alias { - range: 44..45, - name: Identifier { - id: "b", - range: 44..45, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 47..52, - value: BinOp( - ExprBinOp { - range: 47..52, - left: NumberLiteral( - ExprNumberLiteral { - range: 47..48, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from x import (a, b - | ^ Syntax Error: Expected ')', found newline -2 | 1 + 1 -3 | from x import (a, b, -4 | 2 + 2 - | - - - | -1 | from x import (a, b -2 | 1 + 1 -3 | from x import (a, b, - | ^ Syntax Error: Expected ')', found newline -4 | 2 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap.new deleted file mode 100644 index 60cf535425..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap.new +++ /dev/null @@ -1,191 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_star_with_other_names.py ---- -## AST - -``` -Module( - ModModule { - range: 0..87, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..18, - module: Some( - Identifier { - id: "x", - range: 5..6, - }, - ), - names: [ - Alias { - range: 14..15, - name: Identifier { - id: "*", - range: 14..15, - }, - asname: None, - }, - Alias { - range: 17..18, - name: Identifier { - id: "a", - range: 17..18, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 19..40, - module: Some( - Identifier { - id: "x", - range: 24..25, - }, - ), - names: [ - Alias { - range: 33..34, - name: Identifier { - id: "a", - range: 33..34, - }, - asname: None, - }, - Alias { - range: 36..37, - name: Identifier { - id: "*", - range: 36..37, - }, - asname: None, - }, - Alias { - range: 39..40, - name: Identifier { - id: "b", - range: 39..40, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 41..64, - module: Some( - Identifier { - id: "x", - range: 46..47, - }, - ), - names: [ - Alias { - range: 55..56, - name: Identifier { - id: "*", - range: 55..56, - }, - asname: None, - }, - Alias { - range: 58..64, - name: Identifier { - id: "a", - range: 58..59, - }, - asname: Some( - Identifier { - id: "b", - range: 63..64, - }, - ), - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 65..86, - module: Some( - Identifier { - id: "x", - range: 70..71, - }, - ), - names: [ - Alias { - range: 79..80, - name: Identifier { - id: "*", - range: 79..80, - }, - asname: None, - }, - Alias { - range: 82..83, - name: Identifier { - id: "*", - range: 82..83, - }, - asname: None, - }, - Alias { - range: 85..86, - name: Identifier { - id: "a", - range: 85..86, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from x import *, a - | ^^^^ Syntax Error: Star import must be the only import -2 | from x import a, *, b -3 | from x import *, a as b - | - - - | -1 | from x import *, a -2 | from x import a, *, b - | ^^^^^^^ Syntax Error: Star import must be the only import -3 | from x import *, a as b -4 | from x import *, *, a - | - - - | -1 | from x import *, a -2 | from x import a, *, b -3 | from x import *, a as b - | ^^^^^^^^^ Syntax Error: Star import must be the only import -4 | from x import *, *, a - | - - - | -2 | from x import a, *, b -3 | from x import *, a as b -4 | from x import *, *, a - | ^^^^^^^ Syntax Error: Star import must be the only import - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap.new deleted file mode 100644 index 1c5103a1b2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap.new +++ /dev/null @@ -1,119 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/from_import_unparenthesized_trailing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..59, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..16, - module: Some( - Identifier { - id: "a", - range: 5..6, - }, - ), - names: [ - Alias { - range: 14..15, - name: Identifier { - id: "b", - range: 14..15, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 17..38, - module: Some( - Identifier { - id: "a", - range: 22..23, - }, - ), - names: [ - Alias { - range: 31..37, - name: Identifier { - id: "b", - range: 31..32, - }, - asname: Some( - Identifier { - id: "c", - range: 36..37, - }, - ), - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 39..58, - module: Some( - Identifier { - id: "a", - range: 44..45, - }, - ), - names: [ - Alias { - range: 53..54, - name: Identifier { - id: "b", - range: 53..54, - }, - asname: None, - }, - Alias { - range: 56..57, - name: Identifier { - id: "c", - range: 56..57, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | from a import b, - | ^ Syntax Error: Trailing comma not allowed -2 | from a import b as c, -3 | from a import b, c, - | - - - | -1 | from a import b, -2 | from a import b as c, - | ^ Syntax Error: Trailing comma not allowed -3 | from a import b, c, - | - - - | -1 | from a import b, -2 | from a import b as c, -3 | from a import b, c, - | ^ Syntax Error: Trailing comma not allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap.new deleted file mode 100644 index 861241eb64..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap.new +++ /dev/null @@ -1,106 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_empty_body.py ---- -## AST - -``` -Module( - ModModule { - range: 0..36, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..10, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 11..28, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 15..18, - }, - type_params: None, - parameters: Parameters { - range: 18..20, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 24..27, - id: "int", - ctx: Load, - }, - ), - ), - body: [], - }, - ), - Assign( - StmtAssign { - range: 29..35, - targets: [ - Name( - ExprName { - range: 29..30, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 33..35, - value: Int( - 42, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(): -2 | def foo() -> int: - | ^^^ Syntax Error: Expected an indented block after function definition -3 | x = 42 - | - - - | -1 | def foo(): -2 | def foo() -> int: -3 | x = 42 - | ^ Syntax Error: Expected an indented block after function definition - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap.new deleted file mode 100644 index d6f7d3faff..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap.new +++ /dev/null @@ -1,182 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_invalid_return_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..74, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..22, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Starred( - ExprStarred { - range: 13..17, - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 23..47, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 27..30, - }, - type_params: None, - parameters: Parameters { - range: 30..32, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Starred( - ExprStarred { - range: 37..41, - value: Name( - ExprName { - range: 38..41, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 44..47, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 44..47, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 48..73, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 52..55, - }, - type_params: None, - parameters: Parameters { - range: 55..57, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Yield( - ExprYield { - range: 61..68, - value: Some( - Name( - ExprName { - range: 67..68, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 70..73, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 70..73, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo() -> *int: ... - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | def foo() -> (*int): ... -3 | def foo() -> yield x: ... - | - - - | -1 | def foo() -> *int: ... -2 | def foo() -> (*int): ... - | ^^^^ Syntax Error: Starred expression cannot be used here -3 | def foo() -> yield x: ... - | - - - | -1 | def foo() -> *int: ... -2 | def foo() -> (*int): ... -3 | def foo() -> yield x: ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap.new deleted file mode 100644 index 6a4b1bec4e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap.new +++ /dev/null @@ -1,104 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_missing_identifier.py ---- -## AST - -``` -Module( - ModModule { - range: 0..31, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..11, - is_async: false, - decorator_list: [], - name: Identifier { - id: "", - range: 3..3, - }, - type_params: None, - parameters: Parameters { - range: 4..6, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 8..11, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 8..11, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 12..30, - is_async: false, - decorator_list: [], - name: Identifier { - id: "", - range: 15..15, - }, - type_params: None, - parameters: Parameters { - range: 16..18, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 22..25, - id: "int", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 27..30, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 27..30, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def (): ... - | ^ Syntax Error: Expected an identifier -2 | def () -> int: ... - | - - - | -1 | def (): ... -2 | def () -> int: ... - | ^ Syntax Error: Expected an identifier - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap.new deleted file mode 100644 index 016cb5c42e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap.new +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_missing_return_type.py ---- -## AST - -``` -Module( - ModModule { - range: 0..19, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..18, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 15..18, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 15..18, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo() -> : ... - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap.new deleted file mode 100644 index c22c247465..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap.new +++ /dev/null @@ -1,234 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_unclosed_parameter_list.py ---- -## AST - -``` -Module( - ModModule { - range: 0..74, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..18, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..18, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..14, - parameter: Parameter { - range: 8..14, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: Some( - Name( - ExprName { - range: 11..14, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 16..18, - parameter: Parameter { - range: 16..18, - name: Identifier { - id: "b", - range: 16..17, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 19..43, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 23..26, - }, - type_params: None, - parameters: Parameters { - range: 26..28, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Return( - StmtReturn { - range: 34..43, - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 41..43, - value: Int( - 42, - ), - }, - ), - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 44..74, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 48..51, - }, - type_params: None, - parameters: Parameters { - range: 51..74, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 52..58, - parameter: Parameter { - range: 52..58, - name: Identifier { - id: "a", - range: 52..53, - }, - annotation: Some( - Name( - ExprName { - range: 55..58, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 60..66, - parameter: Parameter { - range: 60..66, - name: Identifier { - id: "b", - range: 60..61, - }, - annotation: Some( - Name( - ExprName { - range: 63..66, - id: "str", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 67..73, - parameter: Parameter { - range: 67..68, - name: Identifier { - id: "x", - range: 67..68, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 71..73, - value: Int( - 10, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a: int, b: -2 | def foo(): - | ^^^ Syntax Error: Expected an expression -3 | return 42 -4 | def foo(a: int, b: str - | - - - | -1 | def foo(a: int, b: - | ^ Syntax Error: Expected ')', found newline -2 | def foo(): -3 | return 42 -4 | def foo(a: int, b: str - | - - - | -1 | def foo(a: int, b: -2 | def foo(): - | ^^^ Syntax Error: Expected an indented block after function definition -3 | return 42 -4 | def foo(a: int, b: str - | - - - | -3 | return 42 -4 | def foo(a: int, b: str -5 | x = 10 - | ^ Syntax Error: Expected ',', found name - | - - - | -4 | def foo(a: int, b: str -5 | x = 10 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap.new deleted file mode 100644 index 60875d3762..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap.new +++ /dev/null @@ -1,148 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_unclosed_type_param_list.py ---- -## AST - -``` -Module( - ModModule { - range: 0..47, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..39, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: Some( - TypeParams { - range: 7..15, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 8..10, - name: Identifier { - id: "T1", - range: 8..10, - }, - bound: None, - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 12..15, - name: Identifier { - id: "T2", - range: 13..15, - }, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 15..21, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 16..17, - parameter: Parameter { - range: 16..17, - name: Identifier { - id: "a", - range: 16..17, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 19..20, - parameter: Parameter { - range: 19..20, - name: Identifier { - id: "b", - range: 19..20, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Return( - StmtReturn { - range: 27..39, - value: Some( - BinOp( - ExprBinOp { - range: 34..39, - left: Name( - ExprName { - range: 34..35, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 38..39, - id: "b", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, - ), - Assign( - StmtAssign { - range: 40..46, - targets: [ - Name( - ExprName { - range: 40..41, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 44..46, - value: Int( - 10, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo[T1, *T2(a, b): - | ^ Syntax Error: Expected ']', found '(' -2 | return a + b -3 | x = 10 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap.new deleted file mode 100644 index 03a6782e79..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap.new +++ /dev/null @@ -1,137 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/function_def_unparenthesized_return_types.py ---- -## AST - -``` -Module( - ModModule { - range: 0..50, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..22, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Tuple( - ExprTuple { - range: 13..17, - elts: [ - Name( - ExprName { - range: 13..16, - id: "int", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 23..49, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 27..30, - }, - type_params: None, - parameters: Parameters { - range: 30..32, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Tuple( - ExprTuple { - range: 36..44, - elts: [ - Name( - ExprName { - range: 36..39, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 41..44, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 46..49, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 46..49, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo() -> int,: ... - | ^^^^ Syntax Error: Multiple return types must be parenthesized -2 | def foo() -> int, str: ... - | - - - | -1 | def foo() -> int,: ... -2 | def foo() -> int, str: ... - | ^^^^^^^^ Syntax Error: Multiple return types must be parenthesized - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap.new deleted file mode 100644 index 4143cc0634..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap.new +++ /dev/null @@ -1,52 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/global_stmt_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..13, - body: [ - Global( - StmtGlobal { - range: 0..8, - names: [ - Identifier { - id: "x", - range: 7..8, - }, - ], - }, - ), - Expr( - StmtExpr { - range: 9..12, - value: UnaryOp( - ExprUnaryOp { - range: 9..12, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | global x + 1 - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap.new deleted file mode 100644 index c831a7403f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap.new +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/global_stmt_trailing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..32, - body: [ - Global( - StmtGlobal { - range: 0..8, - names: [], - }, - ), - Global( - StmtGlobal { - range: 9..18, - names: [ - Identifier { - id: "x", - range: 16..17, - }, - ], - }, - ), - Global( - StmtGlobal { - range: 19..31, - names: [ - Identifier { - id: "x", - range: 26..27, - }, - Identifier { - id: "y", - range: 29..30, - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | global , - | ^ Syntax Error: Expected an identifier -2 | global x, -3 | global x, y, - | - - - | -1 | global , - | ^ Syntax Error: Global statement must have at least one name -2 | global x, -3 | global x, y, - | - - - | -1 | global , -2 | global x, - | ^ Syntax Error: Trailing comma not allowed -3 | global x, y, - | - - - | -1 | global , -2 | global x, -3 | global x, y, - | ^ Syntax Error: Trailing comma not allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap.new deleted file mode 100644 index 9b5b55d7a4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap.new +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_elif_missing_colon.py ---- -## AST - -``` -Module( - ModModule { - range: 0..46, - body: [ - If( - StmtIf { - range: 0..45, - test: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 10..14, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 15..30, - test: Some( - Name( - ExprName { - range: 20..21, - id: "y", - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 26..30, - }, - ), - ], - }, - ElifElseClause { - range: 31..45, - test: None, - body: [ - Pass( - StmtPass { - range: 41..45, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if x: -2 | pass -3 | elif y - | ^ Syntax Error: Expected ':', found newline -4 | pass -5 | else: -6 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap.new deleted file mode 100644 index 6a1bc76fdc..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap.new +++ /dev/null @@ -1,107 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_invalid_elif_test_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..56, - body: [ - If( - StmtIf { - range: 0..55, - test: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 10..14, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 15..32, - test: Some( - Starred( - ExprStarred { - range: 20..22, - value: Name( - ExprName { - range: 21..22, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 28..32, - }, - ), - ], - }, - ElifElseClause { - range: 33..55, - test: Some( - Yield( - ExprYield { - range: 38..45, - value: Some( - Name( - ExprName { - range: 44..45, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 51..55, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if x: -2 | pass -3 | elif *x: - | ^^ Syntax Error: Starred expression cannot be used here -4 | pass -5 | elif yield x: - | - - - | -3 | elif *x: -4 | pass -5 | elif yield x: - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -6 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap.new deleted file mode 100644 index d1ef3825a6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap.new +++ /dev/null @@ -1,133 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_invalid_test_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..48, - body: [ - If( - StmtIf { - range: 0..10, - test: Starred( - ExprStarred { - range: 3..5, - value: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 7..10, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 7..10, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 11..26, - test: Yield( - ExprYield { - range: 14..21, - value: Some( - Name( - ExprName { - range: 20..21, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 23..26, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 23..26, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 27..47, - test: YieldFrom( - ExprYieldFrom { - range: 30..42, - value: Name( - ExprName { - range: 41..42, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 44..47, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 44..47, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if *x: ... - | ^^ Syntax Error: Starred expression cannot be used here -2 | if yield x: ... -3 | if yield from x: ... - | - - - | -1 | if *x: ... -2 | if yield x: ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | if yield from x: ... - | - - - | -1 | if *x: ... -2 | if yield x: ... -3 | if yield from x: ... - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap.new deleted file mode 100644 index 76603b01c4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap.new +++ /dev/null @@ -1,99 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_missing_colon.py ---- -## AST - -``` -Module( - ModModule { - range: 0..25, - body: [ - If( - StmtIf { - range: 0..4, - test: Name( - ExprName { - range: 3..4, - id: "x", - ctx: Load, - }, - ), - body: [], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 5..18, - test: Name( - ExprName { - range: 8..9, - id: "x", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 14..18, - }, - ), - ], - elif_else_clauses: [], - }, - ), - Assign( - StmtAssign { - range: 19..24, - targets: [ - Name( - ExprName { - range: 19..20, - id: "a", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if x - | ^ Syntax Error: Expected ':', found newline -2 | if x -3 | pass -4 | a = 1 - | - - - | -1 | if x -2 | if x - | ^^ Syntax Error: Expected an indented block after `if` statement -3 | pass -4 | a = 1 - | - - - | -1 | if x -2 | if x - | ^ Syntax Error: Expected ':', found newline -3 | pass -4 | a = 1 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap.new deleted file mode 100644 index 8b61f7f020..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap.new +++ /dev/null @@ -1,47 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_missing_test.py ---- -## AST - -``` -Module( - ModModule { - range: 0..9, - body: [ - If( - StmtIf { - range: 0..8, - test: Name( - ExprName { - range: 2..2, - id: "", - ctx: Invalid, - }, - ), - body: [ - Expr( - StmtExpr { - range: 5..8, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 5..8, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if : ... - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap.new deleted file mode 100644 index 6c4a9e0934..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap.new +++ /dev/null @@ -1,128 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_misspelled_elif.py ---- -## AST - -``` -Module( - ModModule { - range: 0..47, - body: [ - If( - StmtIf { - range: 0..17, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 3..7, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 13..17, - }, - ), - ], - elif_else_clauses: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 18..22, - target: Name( - ExprName { - range: 18..21, - id: "elf", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 22..22, - id: "", - ctx: Invalid, - }, - ), - value: None, - simple: true, - }, - ), - Pass( - StmtPass { - range: 27..31, - }, - ), - Pass( - StmtPass { - range: 42..46, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if True: -2 | pass -3 | elf: - | ^ Syntax Error: Expected an expression -4 | pass -5 | else: -6 | pass - | - - - | -2 | pass -3 | elf: -4 | pass - | ^^^^ Syntax Error: Unexpected indentation -5 | else: -6 | pass - | - - - | -3 | elf: -4 | pass -5 | else: - | Syntax Error: Expected a statement -6 | pass - | - - - | -3 | elf: -4 | pass -5 | else: - | ^ Syntax Error: Expected a statement -6 | pass - | - - - | -3 | elf: -4 | pass -5 | else: - | ^ Syntax Error: Expected a statement -6 | pass - | - - - | -4 | pass -5 | else: -6 | pass - | ^^^^ Syntax Error: Unexpected indentation - | - - - | -5 | else: -6 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap.new deleted file mode 100644 index 4c4d3542ce..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap.new +++ /dev/null @@ -1,179 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string.py ---- -## AST - -``` -Module( - ModModule { - range: 0..47, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: StringLiteral( - ExprStringLiteral { - range: 0..7, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 0..7, - value: "hello", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 15..20, - value: BinOp( - ExprBinOp { - range: 15..20, - left: NumberLiteral( - ExprNumberLiteral { - range: 15..16, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..40, - value: FString( - ExprFString { - range: 21..40, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 21..28, - value: "hello", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 29..40, - elements: [ - Literal( - FStringLiteralElement { - range: 31..37, - value: "world ", - }, - ), - Expression( - FStringExpressionElement { - range: 37..40, - expression: Name( - ExprName { - range: 38..39, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 41..46, - value: BinOp( - ExprBinOp { - range: 41..46, - left: NumberLiteral( - ExprNumberLiteral { - range: 41..42, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 45..46, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | 'hello' 'world - | ^^^^^^ Syntax Error: missing closing quote in string literal -2 | 1 + 1 -3 | 'hello' f'world {x} - | - - - | -1 | 'hello' 'world - | ^ Syntax Error: Expected a statement -2 | 1 + 1 -3 | 'hello' f'world {x} -4 | 2 + 2 - | - - - | -1 | 'hello' 'world -2 | 1 + 1 -3 | 'hello' f'world {x} - | Syntax Error: f-string: unterminated string -4 | 2 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap.new deleted file mode 100644 index 90aa86d45e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap.new +++ /dev/null @@ -1,244 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/implicitly_concatenated_unterminated_string_multiline.py ---- -## AST - -``` -Module( - ModModule { - range: 0..85, - body: [ - Expr( - StmtExpr { - range: 0..31, - value: FString( - ExprFString { - range: 6..31, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 6..13, - value: "hello", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 18..31, - elements: [ - Literal( - FStringLiteralElement { - range: 20..26, - value: "world ", - }, - ), - Expression( - FStringExpressionElement { - range: 26..29, - expression: Name( - ExprName { - range: 27..28, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 32..37, - value: BinOp( - ExprBinOp { - range: 32..37, - left: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 36..37, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 38..51, - value: StringLiteral( - ExprStringLiteral { - range: 44..51, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 44..51, - value: "first", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 68..76, - value: FString( - ExprFString { - range: 68..76, - value: FStringValue { - inner: Single( - FString( - FString { - range: 68..76, - elements: [ - Literal( - FStringLiteralElement { - range: 70..75, - value: "third", - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 79..84, - value: BinOp( - ExprBinOp { - range: 79..84, - left: NumberLiteral( - ExprNumberLiteral { - range: 79..80, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | ( -2 | 'hello' -3 | f'world {x} - | Syntax Error: f-string: unterminated string -4 | ) -5 | 1 + 1 - | - - - | -2 | 'hello' -3 | f'world {x} -4 | ) - | ^ Syntax Error: Expected an f-string element or the end of the f-string -5 | 1 + 1 -6 | ( - | - - - | -2 | 'hello' -3 | f'world {x} -4 | ) - | ^ Syntax Error: Expected FStringEnd, found newline -5 | 1 + 1 -6 | ( -7 | 'first' - | - - - | - 6 | ( - 7 | 'first' - 8 | 'second - | ^^^^^^^ Syntax Error: missing closing quote in string literal - 9 | f'third' -10 | ) - | - - - | - 8 | 'second - 9 | f'third' -10 | ) - | ^ Syntax Error: Expected a statement -11 | 2 + 2 - | - - - | - 8 | 'second - 9 | f'third' -10 | ) - | ^ Syntax Error: Expected a statement -11 | 2 + 2 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap.new deleted file mode 100644 index c444fde1d0..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap.new +++ /dev/null @@ -1,37 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/import_alias_missing_asname.py ---- -## AST - -``` -Module( - ModModule { - range: 0..12, - body: [ - Import( - StmtImport { - range: 0..11, - names: [ - Alias { - range: 7..11, - name: Identifier { - id: "x", - range: 7..8, - }, - asname: None, - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | import x as - | ^ Syntax Error: Expected symbol after `as` - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap.new deleted file mode 100644 index fc2b368d10..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap.new +++ /dev/null @@ -1,82 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_parenthesized_names.py ---- -## AST - -``` -Module( - ModModule { - range: 0..25, - body: [ - Import( - StmtImport { - range: 0..6, - names: [], - }, - ), - Expr( - StmtExpr { - range: 7..10, - value: Name( - ExprName { - range: 8..9, - id: "a", - ctx: Load, - }, - ), - }, - ), - Import( - StmtImport { - range: 11..17, - names: [], - }, - ), - Expr( - StmtExpr { - range: 18..24, - value: Tuple( - ExprTuple { - range: 18..24, - elts: [ - Name( - ExprName { - range: 19..20, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 22..23, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | import (a) - | ^ Syntax Error: Expected one or more symbol names after import -2 | import (a, b) - | - - - | -1 | import (a) -2 | import (a, b) - | ^ Syntax Error: Expected one or more symbol names after import - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap.new deleted file mode 100644 index 3bbb395f36..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_star_import.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Import( - StmtImport { - range: 0..6, - names: [], - }, - ), - Expr( - StmtExpr { - range: 7..8, - value: Starred( - ExprStarred { - range: 7..8, - value: Name( - ExprName { - range: 8..8, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - }, - ), - Import( - StmtImport { - range: 9..18, - names: [ - Alias { - range: 16..17, - name: Identifier { - id: "x", - range: 16..17, - }, - asname: None, - }, - ], - }, - ), - Expr( - StmtExpr { - range: 19..23, - value: Tuple( - ExprTuple { - range: 19..23, - elts: [ - Starred( - ExprStarred { - range: 19..20, - value: Name( - ExprName { - range: 20..20, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 22..23, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | import * - | ^ Syntax Error: Expected one or more symbol names after import -2 | import x, *, y - | - - - | -1 | import * - | ^ Syntax Error: Expected an expression -2 | import x, *, y - | - - - | -1 | import * -2 | import x, *, y - | ^ Syntax Error: Trailing comma not allowed - | - - - | -1 | import * -2 | import x, *, y - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -1 | import * -2 | import x, *, y - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap.new deleted file mode 100644 index 8ac9822392..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_trailing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..22, - body: [ - Import( - StmtImport { - range: 0..8, - names: [], - }, - ), - Import( - StmtImport { - range: 9..21, - names: [ - Alias { - range: 16..17, - name: Identifier { - id: "x", - range: 16..17, - }, - asname: None, - }, - Alias { - range: 19..20, - name: Identifier { - id: "y", - range: 19..20, - }, - asname: None, - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | import , - | ^ Syntax Error: Expected an import name -2 | import x, y, - | - - - | -1 | import , - | ^ Syntax Error: Expected one or more symbol names after import -2 | import x, y, - | - - - | -1 | import , -2 | import x, y, - | ^ Syntax Error: Trailing comma not allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap.new deleted file mode 100644 index f213dd8d4c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap.new +++ /dev/null @@ -1,270 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/invalid_del_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..75, - body: [ - Delete( - StmtDelete { - range: 0..9, - targets: [ - BinOp( - ExprBinOp { - range: 4..9, - left: Name( - ExprName { - range: 4..5, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 10..22, - targets: [ - Dict( - ExprDict { - range: 14..22, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 15..18, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 15..18, - value: "x", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 23..37, - targets: [ - Set( - ExprSet { - range: 27..37, - elts: [ - StringLiteral( - ExprStringLiteral { - range: 28..31, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 28..31, - value: "x", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - StringLiteral( - ExprStringLiteral { - range: 33..36, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 33..36, - value: "y", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 38..74, - targets: [ - NoneLiteral( - ExprNoneLiteral { - range: 42..46, - }, - ), - BooleanLiteral( - ExprBooleanLiteral { - range: 48..52, - value: true, - }, - ), - BooleanLiteral( - ExprBooleanLiteral { - range: 54..59, - value: false, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 61..62, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 64..67, - value: Float( - 1.0, - ), - }, - ), - StringLiteral( - ExprStringLiteral { - range: 69..74, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 69..74, - value: "abc", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | del x + 1 - | ^^^^^ Syntax Error: Invalid delete target -2 | del {'x': 1} -3 | del {'x', 'y'} - | - - - | -1 | del x + 1 -2 | del {'x': 1} - | ^^^^^^^^ Syntax Error: Invalid delete target -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | - - - | -1 | del x + 1 -2 | del {'x': 1} -3 | del {'x', 'y'} - | ^^^^^^^^^^ Syntax Error: Invalid delete target -4 | del None, True, False, 1, 1.0, "abc" - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^^^^ Syntax Error: Invalid delete target - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^^^^ Syntax Error: Invalid delete target - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^^^^^ Syntax Error: Invalid delete target - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^ Syntax Error: Invalid delete target - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^^^ Syntax Error: Invalid delete target - | - - - | -2 | del {'x': 1} -3 | del {'x', 'y'} -4 | del None, True, False, 1, 1.0, "abc" - | ^^^^^ Syntax Error: Invalid delete target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap.new deleted file mode 100644 index 464c1ee863..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap.new +++ /dev/null @@ -1,274 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/lambda_body_with_starred_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..62, - body: [ - Expr( - StmtExpr { - range: 0..12, - value: Lambda( - ExprLambda { - range: 0..12, - parameters: Some( - Parameters { - range: 7..8, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 7..8, - parameter: Parameter { - range: 7..8, - name: Identifier { - id: "x", - range: 7..8, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Starred( - ExprStarred { - range: 10..12, - value: Name( - ExprName { - range: 11..12, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..26, - value: Tuple( - ExprTuple { - range: 13..26, - elts: [ - Lambda( - ExprLambda { - range: 13..25, - parameters: Some( - Parameters { - range: 20..21, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 20..21, - parameter: Parameter { - range: 20..21, - name: Identifier { - id: "x", - range: 20..21, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Starred( - ExprStarred { - range: 23..25, - value: Name( - ExprName { - range: 24..25, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 27..42, - value: Tuple( - ExprTuple { - range: 27..42, - elts: [ - Lambda( - ExprLambda { - range: 27..39, - parameters: Some( - Parameters { - range: 34..35, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 34..35, - parameter: Parameter { - range: 34..35, - name: Identifier { - id: "x", - range: 34..35, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Starred( - ExprStarred { - range: 37..39, - value: Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 41..42, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 43..61, - value: Lambda( - ExprLambda { - range: 43..61, - parameters: Some( - Parameters { - range: 50..51, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 50..51, - parameter: Parameter { - range: 50..51, - name: Identifier { - id: "x", - range: 50..51, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Starred( - ExprStarred { - range: 53..61, - value: BoolOp( - ExprBoolOp { - range: 54..61, - op: And, - values: [ - Name( - ExprName { - range: 54..55, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 60..61, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | lambda x: *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | lambda x: *y, -3 | lambda x: *y, z - | - - - | -1 | lambda x: *y -2 | lambda x: *y, - | ^^ Syntax Error: Starred expression cannot be used here -3 | lambda x: *y, z -4 | lambda x: *y and z - | - - - | -1 | lambda x: *y -2 | lambda x: *y, -3 | lambda x: *y, z - | ^^ Syntax Error: Starred expression cannot be used here -4 | lambda x: *y and z - | - - - | -2 | lambda x: *y, -3 | lambda x: *y, z -4 | lambda x: *y and z - | ^^^^^^^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap.new deleted file mode 100644 index b8bb377bb9..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap.new +++ /dev/null @@ -1,122 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/lambda_body_with_yield_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - Expr( - StmtExpr { - range: 0..17, - value: Lambda( - ExprLambda { - range: 0..17, - parameters: Some( - Parameters { - range: 7..8, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 7..8, - parameter: Parameter { - range: 7..8, - name: Identifier { - id: "x", - range: 7..8, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Yield( - ExprYield { - range: 10..17, - value: Some( - Name( - ExprName { - range: 16..17, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..40, - value: Lambda( - ExprLambda { - range: 18..40, - parameters: Some( - Parameters { - range: 25..26, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 25..26, - parameter: Parameter { - range: 25..26, - name: Identifier { - id: "x", - range: 25..26, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: YieldFrom( - ExprYieldFrom { - range: 28..40, - value: Name( - ExprName { - range: 39..40, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | lambda x: yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -2 | lambda x: yield from y - | - - - | -1 | lambda x: yield y -2 | lambda x: yield from y - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap.new deleted file mode 100644 index 54a2077dde..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap.new +++ /dev/null @@ -1,67 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_classify_as_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..33, - body: [ - Match( - StmtMatch { - range: 0..32, - subject: Yield( - ExprYield { - range: 6..15, - value: Some( - Name( - ExprName { - range: 12..15, - id: "foo", - ctx: Load, - }, - ), - ), - }, - ), - cases: [ - MatchCase { - range: 21..32, - pattern: MatchAs( - PatternMatchAs { - range: 26..27, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match yield foo: - | ^^^^^^^^^ Syntax Error: Yield expression cannot be used here -2 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap.new deleted file mode 100644 index 740fa30bf2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_classify_as_keyword_or_identifier.py ---- -## AST - -``` -Module( - ModModule { - range: 0..39, - body: [ - Match( - StmtMatch { - range: 0..38, - subject: Starred( - ExprStarred { - range: 6..10, - value: Name( - ExprName { - range: 7..10, - id: "foo", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 27..38, - pattern: MatchAs( - PatternMatchAs { - range: 32..33, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 35..38, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 35..38, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match *foo: # Keyword - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap.new deleted file mode 100644 index 4f0fe0183f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_expect_indented_block.py ---- -## AST - -``` -Module( - ModModule { - range: 0..23, - body: [ - Match( - StmtMatch { - range: 0..22, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 11..22, - pattern: MatchAs( - PatternMatchAs { - range: 16..17, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match foo: -2 | case _: ... - | ^^^^ Syntax Error: Expected an indented block after `match` statement - | - - - | -1 | match foo: -2 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap.new deleted file mode 100644 index fe5038381a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap.new +++ /dev/null @@ -1,135 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_expected_case_block.py ---- -## AST - -``` -Module( - ModModule { - range: 0..61, - body: [ - Match( - StmtMatch { - range: 0..13, - subject: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - cases: [], - }, - ), - Assign( - StmtAssign { - range: 13..18, - targets: [ - Name( - ExprName { - range: 13..14, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 17..18, - value: Int( - 1, - ), - }, - ), - }, - ), - Match( - StmtMatch { - range: 19..32, - subject: Name( - ExprName { - range: 25..26, - id: "x", - ctx: Load, - }, - ), - cases: [], - }, - ), - Match( - StmtMatch { - range: 32..60, - subject: Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 49..60, - pattern: MatchAs( - PatternMatchAs { - range: 54..55, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 57..60, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 57..60, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match x: -2 | x = 1 - | ^ Syntax Error: Expected `case` block -3 | match x: -4 | match y: - | - - - | -1 | match x: -2 | x = 1 -3 | match x: - | Syntax Error: Expected a statement -4 | match y: -5 | case _: ... - | - - - | -2 | x = 1 -3 | match x: -4 | match y: - | ^^^^^ Syntax Error: Expected `case` block -5 | case _: ... - | - - - | -4 | match y: -5 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap.new deleted file mode 100644 index 4ae71366b8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap.new +++ /dev/null @@ -1,212 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_invalid_guard_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..100, - body: [ - Match( - StmtMatch { - range: 0..30, - subject: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 13..30, - pattern: MatchAs( - PatternMatchAs { - range: 18..19, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 18..19, - }, - ), - }, - ), - guard: Some( - Starred( - ExprStarred { - range: 23..25, - value: Name( - ExprName { - range: 24..25, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 27..30, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 27..30, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 31..63, - subject: Name( - ExprName { - range: 37..38, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 44..63, - pattern: MatchAs( - PatternMatchAs { - range: 49..50, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 49..50, - }, - ), - }, - ), - guard: Some( - Starred( - ExprStarred { - range: 55..57, - value: Name( - ExprName { - range: 56..57, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 60..63, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 60..63, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 64..99, - subject: Name( - ExprName { - range: 70..71, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 77..99, - pattern: MatchAs( - PatternMatchAs { - range: 82..83, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 82..83, - }, - ), - }, - ), - guard: Some( - Yield( - ExprYield { - range: 87..94, - value: Some( - Name( - ExprName { - range: 93..94, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 96..99, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 96..99, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match x: -2 | case y if *a: ... - | ^^ Syntax Error: Starred expression cannot be used here -3 | match x: -4 | case y if (*a): ... - | - - - | -2 | case y if *a: ... -3 | match x: -4 | case y if (*a): ... - | ^^ Syntax Error: Starred expression cannot be used here -5 | match x: -6 | case y if yield x: ... - | - - - | -4 | case y if (*a): ... -5 | match x: -6 | case y if yield x: ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap.new deleted file mode 100644 index c79c8828b0..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap.new +++ /dev/null @@ -1,204 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_invalid_subject_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..131, - body: [ - Match( - StmtMatch { - range: 0..27, - subject: Starred( - ExprStarred { - range: 7..9, - value: Name( - ExprName { - range: 8..9, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 16..27, - pattern: MatchAs( - PatternMatchAs { - range: 21..22, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 24..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 24..27, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 65..99, - subject: Tuple( - ExprTuple { - range: 71..82, - elts: [ - Starred( - ExprStarred { - range: 71..79, - value: BoolOp( - ExprBoolOp { - range: 72..79, - op: And, - values: [ - Name( - ExprName { - range: 72..73, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 78..79, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 81..82, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 88..99, - pattern: MatchAs( - PatternMatchAs { - range: 93..94, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 96..99, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 96..99, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 100..130, - subject: Yield( - ExprYield { - range: 106..113, - value: Some( - Name( - ExprName { - range: 112..113, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - cases: [ - MatchCase { - range: 119..130, - pattern: MatchAs( - PatternMatchAs { - range: 124..125, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 127..130, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 127..130, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match (*x): - | ^^ Syntax Error: Starred expression cannot be used here -2 | case _: ... -3 | # Starred expression precedence test - | - - - | -2 | case _: ... -3 | # Starred expression precedence test -4 | match *x and y, z: - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here -5 | case _: ... -6 | match yield x: - | - - - | -4 | match *x and y, z: -5 | case _: ... -6 | match yield x: - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -7 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap.new deleted file mode 100644 index cdb363bddb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap.new +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_missing_guard_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Match( - StmtMatch { - range: 0..27, - subject: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 13..27, - pattern: MatchAs( - PatternMatchAs { - range: 18..19, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 18..19, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 24..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 24..27, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match x: -2 | case y if: ... - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap.new deleted file mode 100644 index 6cba7bb461..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap.new +++ /dev/null @@ -1,65 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_missing_pattern.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Match( - StmtMatch { - range: 0..23, - subject: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 13..23, - pattern: MatchValue( - PatternMatchValue { - range: 17..17, - value: Name( - ExprName { - range: 17..17, - id: "", - ctx: Invalid, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 20..23, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 20..23, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match x: -2 | case : ... - | ^ Syntax Error: Expected a pattern - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap.new deleted file mode 100644 index a79dc7d3d6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap.new +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_no_newline_before_case.py ---- -## AST - -``` -Module( - ModModule { - range: 0..23, - body: [ - Match( - StmtMatch { - range: 0..22, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 11..22, - pattern: MatchAs( - PatternMatchAs { - range: 16..17, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match foo: case _: ... - | ^^^^ Syntax Error: Expected newline, found 'case' - | - - - | -1 | match foo: case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap.new deleted file mode 100644 index cfa1a32ae8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_single_starred_subject.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Match( - StmtMatch { - range: 0..27, - subject: Starred( - ExprStarred { - range: 6..10, - value: Name( - ExprName { - range: 7..10, - id: "foo", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 16..27, - pattern: MatchAs( - PatternMatchAs { - range: 21..22, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 24..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 24..27, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match *foo: - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | case _: ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap.new deleted file mode 100644 index f9530c00e5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap.new +++ /dev/null @@ -1,389 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/multiple_clauses_on_same_line.py ---- -## AST - -``` -Module( - ModModule { - range: 0..258, - body: [ - If( - StmtIf { - range: 0..41, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 3..7, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 14..30, - test: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 19..24, - value: false, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 26..30, - }, - ), - ], - }, - ElifElseClause { - range: 31..41, - test: None, - body: [ - Pass( - StmtPass { - range: 37..41, - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 42..85, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 45..49, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 51..55, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 57..73, - test: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 62..67, - value: false, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 69..73, - }, - ), - ], - }, - ElifElseClause { - range: 75..85, - test: None, - body: [ - Pass( - StmtPass { - range: 81..85, - }, - ), - ], - }, - ], - }, - ), - For( - StmtFor { - range: 86..117, - is_async: false, - target: Name( - ExprName { - range: 90..91, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 95..99, - id: "iter", - ctx: Load, - }, - ), - body: [ - Break( - StmtBreak { - range: 101..106, - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 113..117, - }, - ), - ], - }, - ), - For( - StmtFor { - range: 118..150, - is_async: false, - target: Name( - ExprName { - range: 122..123, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 127..131, - id: "iter", - ctx: Load, - }, - ), - body: [ - Break( - StmtBreak { - range: 133..138, - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 146..150, - }, - ), - ], - }, - ), - Try( - StmtTry { - range: 151..202, - body: [ - Pass( - StmtPass { - range: 156..160, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 161..177, - type_: Some( - Name( - ExprName { - range: 168..171, - id: "exc", - ctx: Load, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 173..177, - }, - ), - ], - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 184..188, - }, - ), - ], - finalbody: [ - Pass( - StmtPass { - range: 198..202, - }, - ), - ], - is_star: false, - }, - ), - Try( - StmtTry { - range: 203..257, - body: [ - Pass( - StmtPass { - range: 208..212, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 214..230, - type_: Some( - Name( - ExprName { - range: 221..224, - id: "exc", - ctx: Load, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 226..230, - }, - ), - ], - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 238..242, - }, - ), - ], - finalbody: [ - Pass( - StmtPass { - range: 253..257, - }, - ), - ], - is_star: false, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if True: pass elif False: pass else: pass - | ^^^^ Syntax Error: Expected newline, found 'elif' -2 | if True: pass; elif False: pass; else: pass -3 | for x in iter: break else: pass - | - - - | -1 | if True: pass elif False: pass else: pass - | ^^^^ Syntax Error: Expected newline, found 'else' -2 | if True: pass; elif False: pass; else: pass -3 | for x in iter: break else: pass - | - - - | -1 | if True: pass elif False: pass else: pass -2 | if True: pass; elif False: pass; else: pass - | ^^^^ Syntax Error: Expected newline, found 'elif' -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass - | - - - | -1 | if True: pass elif False: pass else: pass -2 | if True: pass; elif False: pass; else: pass - | ^^^^ Syntax Error: Expected newline, found 'else' -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass - | - - - | -1 | if True: pass elif False: pass else: pass -2 | if True: pass; elif False: pass; else: pass -3 | for x in iter: break else: pass - | ^^^^ Syntax Error: Expected newline, found 'else' -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass - | - - - | -2 | if True: pass; elif False: pass; else: pass -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass - | ^^^^ Syntax Error: Expected newline, found 'else' -5 | try: pass except exc: pass else: pass finally: pass -6 | try: pass; except exc: pass; else: pass; finally: pass - | - - - | -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass - | ^^^^^^ Syntax Error: Expected newline, found 'except' -6 | try: pass; except exc: pass; else: pass; finally: pass - | - - - | -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass - | ^^^^ Syntax Error: Expected newline, found 'else' -6 | try: pass; except exc: pass; else: pass; finally: pass - | - - - | -3 | for x in iter: break else: pass -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass - | ^^^^^^^ Syntax Error: Expected newline, found 'finally' -6 | try: pass; except exc: pass; else: pass; finally: pass - | - - - | -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass -6 | try: pass; except exc: pass; else: pass; finally: pass - | ^^^^^^ Syntax Error: Expected newline, found 'except' - | - - - | -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass -6 | try: pass; except exc: pass; else: pass; finally: pass - | ^^^^ Syntax Error: Expected newline, found 'else' - | - - - | -4 | for x in iter: break; else: pass -5 | try: pass except exc: pass else: pass finally: pass -6 | try: pass; except exc: pass; else: pass; finally: pass - | ^^^^^^^ Syntax Error: Expected newline, found 'finally' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap.new deleted file mode 100644 index 238f6e734c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap.new +++ /dev/null @@ -1,123 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/node_range_with_gaps.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..7, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..7, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 18..32, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 22..25, - }, - type_params: None, - parameters: Parameters { - range: 25..27, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 33..40, - is_async: false, - decorator_list: [], - name: Identifier { - id: "baz", - range: 37..40, - }, - type_params: None, - parameters: Parameters { - range: 40..40, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo # comment - | ^ Syntax Error: Expected '(', found newline -2 | def bar(): ... -3 | def baz - | - - - | -1 | def foo # comment -2 | def bar(): ... - | ^^^ Syntax Error: Expected ')', found 'def' -3 | def baz - | - - - | -1 | def foo # comment -2 | def bar(): ... -3 | def baz - | ^ Syntax Error: Expected '(', found newline - | - - - | -2 | def bar(): ... -3 | def baz - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap.new deleted file mode 100644 index db9c63918c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap.new +++ /dev/null @@ -1,52 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_stmt_expression.py ---- -## AST - -``` -Module( - ModModule { - range: 0..15, - body: [ - Nonlocal( - StmtNonlocal { - range: 0..10, - names: [ - Identifier { - id: "x", - range: 9..10, - }, - ], - }, - ), - Expr( - StmtExpr { - range: 11..14, - value: UnaryOp( - ExprUnaryOp { - range: 11..14, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | nonlocal x + 1 - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap.new deleted file mode 100644 index 43b218c730..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap.new +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_stmt_trailing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - Nonlocal( - StmtNonlocal { - range: 0..10, - names: [], - }, - ), - Nonlocal( - StmtNonlocal { - range: 11..22, - names: [ - Identifier { - id: "x", - range: 20..21, - }, - ], - }, - ), - Nonlocal( - StmtNonlocal { - range: 23..37, - names: [ - Identifier { - id: "x", - range: 32..33, - }, - Identifier { - id: "y", - range: 35..36, - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | nonlocal , - | ^ Syntax Error: Expected an identifier -2 | nonlocal x, -3 | nonlocal x, y, - | - - - | -1 | nonlocal , - | ^ Syntax Error: Nonlocal statement must have at least one name -2 | nonlocal x, -3 | nonlocal x, y, - | - - - | -1 | nonlocal , -2 | nonlocal x, - | ^ Syntax Error: Trailing comma not allowed -3 | nonlocal x, y, - | - - - | -1 | nonlocal , -2 | nonlocal x, -3 | nonlocal x, y, - | ^ Syntax Error: Trailing comma not allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap.new deleted file mode 100644 index 5f838973ef..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap.new +++ /dev/null @@ -1,122 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/param_missing_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..35, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..16, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..11, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..10, - parameter: Parameter { - range: 8..10, - name: Identifier { - id: "x", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 13..16, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 13..16, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 17..34, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 21..24, - }, - type_params: None, - parameters: Parameters { - range: 24..29, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 25..27, - parameter: Parameter { - range: 25..27, - name: Identifier { - id: "x", - range: 25..26, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 31..34, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 31..34, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(x:): ... - | ^ Syntax Error: Expected an expression -2 | def foo(x:,): ... - | - - - | -1 | def foo(x:): ... -2 | def foo(x:,): ... - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap.new deleted file mode 100644 index ed8bb14de6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap.new +++ /dev/null @@ -1,130 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/param_missing_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..16, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..11, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..10, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "x", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 13..16, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 13..16, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 17..40, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 21..24, - }, - type_params: None, - parameters: Parameters { - range: 24..35, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 25..33, - parameter: Parameter { - range: 25..31, - name: Identifier { - id: "x", - range: 25..26, - }, - annotation: Some( - Name( - ExprName { - range: 28..31, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 37..40, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 37..40, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(x=): ... - | ^ Syntax Error: Expected an expression -2 | def foo(x: int = ): ... - | - - - | -1 | def foo(x=): ... -2 | def foo(x: int = ): ... - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap.new deleted file mode 100644 index 38d09cc97a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap.new +++ /dev/null @@ -1,227 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..81, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..23, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..18, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..17, - parameter: Parameter { - range: 8..17, - name: Identifier { - id: "arg", - range: 8..11, - }, - annotation: Some( - Starred( - ExprStarred { - range: 13..17, - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 20..23, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 20..23, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 24..52, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 28..31, - }, - type_params: None, - parameters: Parameters { - range: 31..47, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 32..46, - parameter: Parameter { - range: 32..46, - name: Identifier { - id: "arg", - range: 32..35, - }, - annotation: Some( - Yield( - ExprYield { - range: 37..46, - value: Some( - Name( - ExprName { - range: 43..46, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 49..52, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 49..52, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 53..80, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 57..60, - }, - type_params: None, - parameters: Parameters { - range: 60..75, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 61..67, - parameter: Parameter { - range: 61..67, - name: Identifier { - id: "arg", - range: 61..64, - }, - annotation: Some( - Name( - ExprName { - range: 66..67, - id: "x", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 71..74, - parameter: Parameter { - range: 71..74, - name: Identifier { - id: "int", - range: 71..74, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 77..80, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 77..80, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(arg: *int): ... - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | def foo(arg: yield int): ... -3 | def foo(arg: x := int): ... - | - - - | -1 | def foo(arg: *int): ... -2 | def foo(arg: yield int): ... - | ^^^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | def foo(arg: x := int): ... - | - - - | -1 | def foo(arg: *int): ... -2 | def foo(arg: yield int): ... -3 | def foo(arg: x := int): ... - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap.new deleted file mode 100644 index c85c9d8109..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap.new +++ /dev/null @@ -1,221 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..68, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..20, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..15, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..14, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "x", - range: 8..9, - }, - annotation: None, - }, - default: Some( - Starred( - ExprStarred { - range: 10..14, - value: Name( - ExprName { - range: 11..14, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 17..20, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 17..20, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 21..43, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 25..28, - }, - type_params: None, - parameters: Parameters { - range: 28..38, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 29..37, - parameter: Parameter { - range: 29..30, - name: Identifier { - id: "x", - range: 29..30, - }, - annotation: None, - }, - default: Some( - Starred( - ExprStarred { - range: 32..36, - value: Name( - ExprName { - range: 33..36, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 40..43, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 40..43, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 44..67, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 48..51, - }, - type_params: None, - parameters: Parameters { - range: 51..62, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 52..61, - parameter: Parameter { - range: 52..53, - name: Identifier { - id: "x", - range: 52..53, - }, - annotation: None, - }, - default: Some( - Yield( - ExprYield { - range: 54..61, - value: Some( - Name( - ExprName { - range: 60..61, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 64..67, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 64..67, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(x=*int): ... - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | def foo(x=(*int)): ... -3 | def foo(x=yield y): ... - | - - - | -1 | def foo(x=*int): ... -2 | def foo(x=(*int)): ... - | ^^^^ Syntax Error: Starred expression cannot be used here -3 | def foo(x=yield y): ... - | - - - | -1 | def foo(x=*int): ... -2 | def foo(x=(*int)): ... -3 | def foo(x=yield y): ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap.new deleted file mode 100644 index 5f68409122..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap.new +++ /dev/null @@ -1,311 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_star_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..150, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..22, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..17, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 8..16, - name: Identifier { - id: "args", - range: 9..13, - }, - annotation: Some( - Starred( - ExprStarred { - range: 15..16, - value: Name( - ExprName { - range: 16..16, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 23..57, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 27..30, - }, - type_params: None, - parameters: Parameters { - range: 30..52, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 31..51, - name: Identifier { - id: "args", - range: 32..36, - }, - annotation: Some( - Starred( - ExprStarred { - range: 39..50, - value: Subscript( - ExprSubscript { - range: 40..50, - value: Name( - ExprName { - range: 40..45, - id: "tuple", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 46..49, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 54..57, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 54..57, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 58..90, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 62..65, - }, - type_params: None, - parameters: Parameters { - range: 65..85, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 66..84, - name: Identifier { - id: "args", - range: 67..71, - }, - annotation: Some( - Starred( - ExprStarred { - range: 73..84, - value: BoolOp( - ExprBoolOp { - range: 74..84, - op: Or, - values: [ - Name( - ExprName { - range: 74..77, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 81..84, - id: "str", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 87..90, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 87..90, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 91..120, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 95..98, - }, - type_params: None, - parameters: Parameters { - range: 98..115, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 99..114, - name: Identifier { - id: "args", - range: 100..104, - }, - annotation: Some( - Starred( - ExprStarred { - range: 106..114, - value: Yield( - ExprYield { - range: 107..114, - value: Some( - Name( - ExprName { - range: 113..114, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 117..120, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 117..120, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(*args: *): ... - | ^ Syntax Error: Expected an expression -2 | def foo(*args: (*tuple[int])): ... -3 | def foo(*args: *int or str): ... - | - - - | -1 | def foo(*args: *): ... -2 | def foo(*args: (*tuple[int])): ... - | ^^^^^^^^^^^ Syntax Error: Starred expression cannot be used here -3 | def foo(*args: *int or str): ... -4 | def foo(*args: *yield x): ... - | - - - | -1 | def foo(*args: *): ... -2 | def foo(*args: (*tuple[int])): ... -3 | def foo(*args: *int or str): ... - | ^^^^^^^^^^ Syntax Error: Boolean expression cannot be used here -4 | def foo(*args: *yield x): ... -5 | # def foo(*args: **int): ... - | - - - | -2 | def foo(*args: (*tuple[int])): ... -3 | def foo(*args: *int or str): ... -4 | def foo(*args: *yield x): ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | # def foo(*args: **int): ... - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap.new deleted file mode 100644 index 3edd64d419..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap.new +++ /dev/null @@ -1,164 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_duplicate_names.py ---- -## AST - -``` -Module( - ModModule { - range: 0..42, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..41, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..36, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 11..15, - parameter: Parameter { - range: 11..12, - name: Identifier { - id: "a", - range: 11..12, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 13..15, - value: Int( - 10, - ), - }, - ), - ), - }, - ], - vararg: Some( - Parameter { - range: 17..19, - name: Identifier { - id: "a", - range: 18..19, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 21..22, - parameter: Parameter { - range: 21..22, - name: Identifier { - id: "a", - range: 21..22, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 24..30, - parameter: Parameter { - range: 24..30, - name: Identifier { - id: "a", - range: 24..25, - }, - annotation: Some( - Name( - ExprName { - range: 27..30, - id: "str", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - kwarg: Some( - Parameter { - range: 32..35, - name: Identifier { - id: "a", - range: 34..35, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 38..41, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 38..41, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, a=10, *a, a, a: str, **a): ... - | ^ Syntax Error: Duplicate parameter "a" - | - - - | -1 | def foo(a, a=10, *a, a, a: str, **a): ... - | ^ Syntax Error: Duplicate parameter "a" - | - - - | -1 | def foo(a, a=10, *a, a, a: str, **a): ... - | ^ Syntax Error: Duplicate parameter "a" - | - - - | -1 | def foo(a, a=10, *a, a, a: str, **a): ... - | ^ Syntax Error: Duplicate parameter "a" - | - - - | -1 | def foo(a, a=10, *a, a, a: str, **a): ... - | ^ Syntax Error: Duplicate parameter "a" - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap.new deleted file mode 100644 index b8b40b5d2c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap.new +++ /dev/null @@ -1,260 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_expected_after_star_separator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..98, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..15, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..10, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 12..15, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 12..15, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 16..32, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 20..23, - }, - type_params: None, - parameters: Parameters { - range: 23..27, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 33..51, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 37..40, - }, - type_params: None, - parameters: Parameters { - range: 40..46, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 41..42, - parameter: Parameter { - range: 41..42, - name: Identifier { - id: "a", - range: 41..42, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 48..51, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 48..51, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 52..71, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 56..59, - }, - type_params: None, - parameters: Parameters { - range: 59..66, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 60..61, - parameter: Parameter { - range: 60..61, - name: Identifier { - id: "a", - range: 60..61, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 68..71, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 68..71, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 72..97, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 76..79, - }, - type_params: None, - parameters: Parameters { - range: 79..92, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 83..91, - name: Identifier { - id: "kwargs", - range: 85..91, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 94..97, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 94..97, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(*): ... - | ^ Syntax Error: Expected one or more keyword parameter after '*' separator -2 | def foo(*,): ... -3 | def foo(a, *): ... - | - - - | -1 | def foo(*): ... -2 | def foo(*,): ... - | ^ Syntax Error: Expected one or more keyword parameter after '*' separator -3 | def foo(a, *): ... -4 | def foo(a, *,): ... - | - - - | -1 | def foo(*): ... -2 | def foo(*,): ... -3 | def foo(a, *): ... - | ^ Syntax Error: Expected one or more keyword parameter after '*' separator -4 | def foo(a, *,): ... -5 | def foo(*, **kwargs): ... - | - - - | -2 | def foo(*,): ... -3 | def foo(a, *): ... -4 | def foo(a, *,): ... - | ^ Syntax Error: Expected one or more keyword parameter after '*' separator -5 | def foo(*, **kwargs): ... - | - - - | -3 | def foo(a, *): ... -4 | def foo(a, *,): ... -5 | def foo(*, **kwargs): ... - | ^^^^^^^^ Syntax Error: Expected one or more keyword parameter after '*' separator - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap.new deleted file mode 100644 index 50466a6d76..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap.new +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_kwarg_after_star_separator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..26, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..25, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..20, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 11..19, - name: Identifier { - id: "kwargs", - range: 13..19, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 22..25, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 22..25, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(*, **kwargs): ... - | ^^^^^^^^ Syntax Error: Expected one or more keyword parameter after '*' separator - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap.new deleted file mode 100644 index ac4d515618..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap.new +++ /dev/null @@ -1,77 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_kwargs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..37, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..32, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 22..31, - name: Identifier { - id: "kwargs2", - range: 24..31, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 34..37, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 34..37, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, **kwargs1, **kwargs2): ... - | ^^ Syntax Error: Parameter cannot follow var-keyword parameter - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap.new deleted file mode 100644 index 0265befade..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap.new +++ /dev/null @@ -1,160 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_slash_separator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..53, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..24, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..19, - posonlyargs: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 17..18, - parameter: Parameter { - range: 17..18, - name: Identifier { - id: "b", - range: 17..18, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 21..24, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 21..24, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 25..52, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 29..32, - }, - type_params: None, - parameters: Parameters { - range: 32..47, - posonlyargs: [ - ParameterWithDefault { - range: 33..34, - parameter: Parameter { - range: 33..34, - name: Identifier { - id: "a", - range: 33..34, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 39..40, - parameter: Parameter { - range: 39..40, - name: Identifier { - id: "b", - range: 39..40, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 42..43, - parameter: Parameter { - range: 42..43, - name: Identifier { - id: "c", - range: 42..43, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 49..52, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 49..52, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, /, /, b): ... - | ^ Syntax Error: Only one '/' separator allowed -2 | def foo(a, /, b, c, /): ... - | - - - | -1 | def foo(a, /, /, b): ... -2 | def foo(a, /, b, c, /): ... - | ^ Syntax Error: Only one '/' separator allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap.new deleted file mode 100644 index e20a3c75a2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap.new +++ /dev/null @@ -1,160 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_star_separator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..53, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..24, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..19, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 17..18, - parameter: Parameter { - range: 17..18, - name: Identifier { - id: "b", - range: 17..18, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 21..24, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 21..24, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 25..52, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 29..32, - }, - type_params: None, - parameters: Parameters { - range: 32..47, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 33..34, - parameter: Parameter { - range: 33..34, - name: Identifier { - id: "a", - range: 33..34, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 39..40, - parameter: Parameter { - range: 39..40, - name: Identifier { - id: "b", - range: 39..40, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 42..43, - parameter: Parameter { - range: 42..43, - name: Identifier { - id: "c", - range: 42..43, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 49..52, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 49..52, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, *, *, b): ... - | ^ Syntax Error: Only one '*' separator allowed -2 | def foo(a, *, b, c, *): ... - | - - - | -1 | def foo(a, *, *, b): ... -2 | def foo(a, *, b, c, *): ... - | ^ Syntax Error: Only one '*' separator allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap.new deleted file mode 100644 index 844707d834..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap.new +++ /dev/null @@ -1,257 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_varargs.py ---- -## AST - -``` -Module( - ModModule { - range: 0..136, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..28, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..23, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 14..19, - name: Identifier { - id: "args", - range: 15..19, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 21..22, - parameter: Parameter { - range: 21..22, - name: Identifier { - id: "b", - range: 21..22, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 63..97, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 67..70, - }, - type_params: None, - parameters: Parameters { - range: 70..92, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 71..72, - parameter: Parameter { - range: 71..72, - name: Identifier { - id: "a", - range: 71..72, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 74..80, - name: Identifier { - id: "args1", - range: 75..80, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 90..91, - parameter: Parameter { - range: 90..91, - name: Identifier { - id: "b", - range: 90..91, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 94..97, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 94..97, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 98..135, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 102..105, - }, - type_params: None, - parameters: Parameters { - range: 105..130, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 106..107, - parameter: Parameter { - range: 106..107, - name: Identifier { - id: "a", - range: 106..107, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 109..115, - name: Identifier { - id: "args1", - range: 110..115, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 117..118, - parameter: Parameter { - range: 117..118, - name: Identifier { - id: "b", - range: 117..118, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 120..121, - parameter: Parameter { - range: 120..121, - name: Identifier { - id: "c", - range: 120..121, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 132..135, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 132..135, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, *, *args, b): ... - | ^^^^^ Syntax Error: Only one '*' parameter allowed -2 | # def foo(a, *, b, c, *args): ... -3 | def foo(a, *args1, *args2, b): ... - | - - - | -1 | def foo(a, *, *args, b): ... -2 | # def foo(a, *, b, c, *args): ... -3 | def foo(a, *args1, *args2, b): ... - | ^^^^^^ Syntax Error: Only one '*' parameter allowed -4 | def foo(a, *args1, b, c, *args2): ... - | - - - | -2 | # def foo(a, *, b, c, *args): ... -3 | def foo(a, *args1, *args2, b): ... -4 | def foo(a, *args1, b, c, *args2): ... - | ^^^^^^ Syntax Error: Only one '*' parameter allowed - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap.new deleted file mode 100644 index dabc4cf2f2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap.new +++ /dev/null @@ -1,109 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_no_arg_before_slash.py ---- -## AST - -``` -Module( - ModModule { - range: 0..35, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..15, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..10, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 12..15, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 12..15, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 16..34, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 20..23, - }, - type_params: None, - parameters: Parameters { - range: 23..29, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 27..28, - parameter: Parameter { - range: 27..28, - name: Identifier { - id: "a", - range: 27..28, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 31..34, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 31..34, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(/): ... - | ^ Syntax Error: Position-only parameter separator not allowed as first parameter -2 | def foo(/, a): ... - | - - - | -1 | def foo(/): ... -2 | def foo(/, a): ... - | ^ Syntax Error: Position-only parameter separator not allowed as first parameter - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap.new deleted file mode 100644 index 80bea22dc4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap.new +++ /dev/null @@ -1,115 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_non_default_after_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..30, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..29, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..24, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..12, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 10..12, - value: Int( - 10, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 14..15, - parameter: Parameter { - range: 14..15, - name: Identifier { - id: "b", - range: 14..15, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 17..23, - parameter: Parameter { - range: 17..23, - name: Identifier { - id: "c", - range: 17..18, - }, - annotation: Some( - Name( - ExprName { - range: 20..23, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 26..29, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 26..29, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a=10, b, c: int): ... - | ^ Syntax Error: Parameter without a default cannot follow a parameter with a default - | - - - | -1 | def foo(a=10, b, c: int): ... - | ^^^^^^ Syntax Error: Parameter without a default cannot follow a parameter with a default - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap.new deleted file mode 100644 index 802beea39f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap.new +++ /dev/null @@ -1,302 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_star_after_slash.py ---- -## AST - -``` -Module( - ModModule { - range: 0..105, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..19, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..14, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 8..10, - name: Identifier { - id: "a", - range: 9..10, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 16..19, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 16..19, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 20..48, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 24..27, - }, - type_params: None, - parameters: Parameters { - range: 27..43, - posonlyargs: [ - ParameterWithDefault { - range: 28..29, - parameter: Parameter { - range: 28..29, - name: Identifier { - id: "a", - range: 28..29, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: Some( - Parameter { - range: 31..36, - name: Identifier { - id: "args", - range: 32..36, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 38..39, - parameter: Parameter { - range: 38..39, - name: Identifier { - id: "b", - range: 38..39, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 45..48, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 45..48, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 49..73, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 53..56, - }, - type_params: None, - parameters: Parameters { - range: 56..68, - posonlyargs: [ - ParameterWithDefault { - range: 57..58, - parameter: Parameter { - range: 57..58, - name: Identifier { - id: "a", - range: 57..58, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 66..67, - parameter: Parameter { - range: 66..67, - name: Identifier { - id: "b", - range: 66..67, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 70..73, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 70..73, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 74..104, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 78..81, - }, - type_params: None, - parameters: Parameters { - range: 81..99, - posonlyargs: [ - ParameterWithDefault { - range: 82..83, - parameter: Parameter { - range: 82..83, - name: Identifier { - id: "a", - range: 82..83, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 88..89, - parameter: Parameter { - range: 88..89, - name: Identifier { - id: "b", - range: 88..89, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 91..92, - parameter: Parameter { - range: 91..92, - name: Identifier { - id: "c", - range: 91..92, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 97..98, - parameter: Parameter { - range: 97..98, - name: Identifier { - id: "d", - range: 97..98, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 101..104, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 101..104, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(*a, /): ... - | ^ Syntax Error: '/' parameter must appear before '*' parameter -2 | def foo(a, *args, b, /): ... -3 | def foo(a, *, /, b): ... - | - - - | -1 | def foo(*a, /): ... -2 | def foo(a, *args, b, /): ... - | ^ Syntax Error: '/' parameter must appear before '*' parameter -3 | def foo(a, *, /, b): ... -4 | def foo(a, *, b, c, /, d): ... - | - - - | -1 | def foo(*a, /): ... -2 | def foo(a, *args, b, /): ... -3 | def foo(a, *, /, b): ... - | ^ Syntax Error: '/' parameter must appear before '*' parameter -4 | def foo(a, *, b, c, /, d): ... - | - - - | -2 | def foo(a, *args, b, /): ... -3 | def foo(a, *, /, b): ... -4 | def foo(a, *, b, c, /, d): ... - | ^ Syntax Error: '/' parameter must appear before '*' parameter - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap.new deleted file mode 100644 index 849c0067b2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap.new +++ /dev/null @@ -1,178 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_star_separator_after_star_param.py ---- -## AST - -``` -Module( - ModModule { - range: 0..61, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..28, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..23, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 11..16, - name: Identifier { - id: "args", - range: 12..16, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 21..22, - parameter: Parameter { - range: 21..22, - name: Identifier { - id: "b", - range: 21..22, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 29..60, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 33..36, - }, - type_params: None, - parameters: Parameters { - range: 36..55, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 37..38, - parameter: Parameter { - range: 37..38, - name: Identifier { - id: "a", - range: 37..38, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 40..45, - name: Identifier { - id: "args", - range: 41..45, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 47..48, - parameter: Parameter { - range: 47..48, - name: Identifier { - id: "b", - range: 47..48, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 50..51, - parameter: Parameter { - range: 50..51, - name: Identifier { - id: "c", - range: 50..51, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 57..60, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 57..60, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, *args, *, b): ... - | ^ Syntax Error: Keyword-only parameter separator not allowed after '*' parameter -2 | def foo(a, *args, b, c, *): ... - | - - - | -1 | def foo(a, *args, *, b): ... -2 | def foo(a, *args, b, c, *): ... - | ^ Syntax Error: Keyword-only parameter separator not allowed after '*' parameter - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap.new deleted file mode 100644 index 605176a24e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap.new +++ /dev/null @@ -1,167 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_var_keyword_with_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..43, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..36, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..20, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 11..19, - name: Identifier { - id: "kwargs", - range: 13..19, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 20..36, - value: Dict( - ExprDict { - range: 20..36, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 21..24, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 21..24, - value: "b", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 26..27, - value: Int( - 1, - ), - }, - ), - }, - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 29..32, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 29..32, - value: "c", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 39..42, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 39..42, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, **kwargs={'b': 1, 'c': 2}): ... - | ^ Syntax Error: Parameter with '*' or '**' cannot have default value - | - - - | -1 | def foo(a, **kwargs={'b': 1, 'c': 2}): ... - | ^ Syntax Error: Expected ')', found '{' - | - - - | -1 | def foo(a, **kwargs={'b': 1, 'c': 2}): ... - | ^ Syntax Error: Expected newline, found ')' - | - - - | -1 | def foo(a, **kwargs={'b': 1, 'c': 2}): ... - | ^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap.new deleted file mode 100644 index a7b3b8db02..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap.new +++ /dev/null @@ -1,125 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/params_var_positional_with_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..30, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..23, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..17, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..9, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 11..16, - name: Identifier { - id: "args", - range: 12..16, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 17..23, - value: Tuple( - ExprTuple { - range: 17..23, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 21..22, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 26..29, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 26..29, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo(a, *args=(1, 2)): ... - | ^ Syntax Error: Parameter with '*' or '**' cannot have default value - | - - - | -1 | def foo(a, *args=(1, 2)): ... - | ^ Syntax Error: Expected ')', found '(' - | - - - | -1 | def foo(a, *args=(1, 2)): ... - | ^ Syntax Error: Expected newline, found ')' - | - - - | -1 | def foo(a, *args=(1, 2)): ... - | ^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap.new deleted file mode 100644 index 21d6d06ef8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap.new +++ /dev/null @@ -1,135 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_invalid_cause.py ---- -## AST - -``` -Module( - ModModule { - range: 0..57, - body: [ - Raise( - StmtRaise { - range: 0..15, - exc: Some( - Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Starred( - ExprStarred { - range: 13..15, - value: Name( - ExprName { - range: 14..15, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 16..36, - exc: Some( - Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Yield( - ExprYield { - range: 29..36, - value: Some( - Name( - ExprName { - range: 35..36, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 37..51, - exc: Some( - Name( - ExprName { - range: 43..44, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Name( - ExprName { - range: 50..51, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - Expr( - StmtExpr { - range: 55..56, - value: NumberLiteral( - ExprNumberLiteral { - range: 55..56, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | raise x from *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | raise x from yield y -3 | raise x from y := 1 - | - - - | -1 | raise x from *y -2 | raise x from yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | raise x from y := 1 - | - - - | -1 | raise x from *y -2 | raise x from yield y -3 | raise x from y := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap.new deleted file mode 100644 index 91a8125dda..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap.new +++ /dev/null @@ -1,111 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_invalid_exc.py ---- -## AST - -``` -Module( - ModModule { - range: 0..36, - body: [ - Raise( - StmtRaise { - range: 0..8, - exc: Some( - Starred( - ExprStarred { - range: 6..8, - value: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 9..22, - exc: Some( - Yield( - ExprYield { - range: 15..22, - value: Some( - Name( - ExprName { - range: 21..22, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 23..30, - exc: Some( - Name( - ExprName { - range: 29..30, - id: "x", - ctx: Load, - }, - ), - ), - cause: None, - }, - ), - Expr( - StmtExpr { - range: 34..35, - value: NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | raise *x - | ^^ Syntax Error: Starred expression cannot be used here -2 | raise yield x -3 | raise x := 1 - | - - - | -1 | raise *x -2 | raise yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | raise x := 1 - | - - - | -1 | raise *x -2 | raise yield x -3 | raise x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap.new deleted file mode 100644 index 9ada6dca47..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap.new +++ /dev/null @@ -1,101 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_unparenthesized_tuple_cause.py ---- -## AST - -``` -Module( - ModModule { - range: 0..34, - body: [ - Raise( - StmtRaise { - range: 0..15, - exc: Some( - Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Tuple( - ExprTuple { - range: 13..15, - elts: [ - Name( - ExprName { - range: 13..14, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 16..33, - exc: Some( - Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Tuple( - ExprTuple { - range: 29..33, - elts: [ - Name( - ExprName { - range: 29..30, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 32..33, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | raise x from y, - | ^^ Syntax Error: Unparenthesized tuple expression cannot be used here -2 | raise x from y, z - | - - - | -1 | raise x from y, -2 | raise x from y, z - | ^^^^ Syntax Error: Unparenthesized tuple expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap.new deleted file mode 100644 index 00f744c54b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap.new +++ /dev/null @@ -1,134 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_unparenthesized_tuple_exc.py ---- -## AST - -``` -Module( - ModModule { - range: 0..38, - body: [ - Raise( - StmtRaise { - range: 0..8, - exc: Some( - Tuple( - ExprTuple { - range: 6..8, - elts: [ - Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 9..19, - exc: Some( - Tuple( - ExprTuple { - range: 15..19, - elts: [ - Name( - ExprName { - range: 15..16, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 18..19, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 20..37, - exc: Some( - Tuple( - ExprTuple { - range: 26..30, - elts: [ - Name( - ExprName { - range: 26..27, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 29..30, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - cause: Some( - Name( - ExprName { - range: 36..37, - id: "z", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | raise x, - | ^^ Syntax Error: Unparenthesized tuple expression cannot be used here -2 | raise x, y -3 | raise x, y from z - | - - - | -1 | raise x, -2 | raise x, y - | ^^^^ Syntax Error: Unparenthesized tuple expression cannot be used here -3 | raise x, y from z - | - - - | -1 | raise x, -2 | raise x, y -3 | raise x, y from z - | ^^^^ Syntax Error: Unparenthesized tuple expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap.new deleted file mode 100644 index ee6eaa9613..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap.new +++ /dev/null @@ -1,839 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token.py ---- -## AST - -``` -Module( - ModModule { - range: 0..979, - body: [ - If( - StmtIf { - range: 48..59, - test: Call( - ExprCall { - range: 51..59, - func: Name( - ExprName { - range: 51..55, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 55..59, - args: [ - Name( - ExprName { - range: 56..59, - id: "foo", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [], - elif_else_clauses: [], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 60..79, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 64..67, - }, - type_params: None, - parameters: Parameters { - range: 67..69, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 75..79, - }, - ), - ], - }, - ), - If( - StmtIf { - range: 113..152, - test: Call( - ExprCall { - range: 116..124, - func: Name( - ExprName { - range: 116..120, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 120..124, - args: [ - Name( - ExprName { - range: 121..124, - id: "foo", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 129..152, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 133..136, - }, - type_params: None, - parameters: Parameters { - range: 136..138, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 148..152, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 228..269, - test: Call( - ExprCall { - range: 231..239, - func: Name( - ExprName { - range: 231..235, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 235..239, - args: [ - Name( - ExprName { - range: 236..239, - id: "foo", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 246..269, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 250..253, - }, - type_params: None, - parameters: Parameters { - range: 253..255, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 265..269, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 344..392, - test: Call( - ExprCall { - range: 347..355, - func: Name( - ExprName { - range: 347..351, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 351..355, - args: [ - Name( - ExprName { - range: 352..355, - id: "foo", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 369..392, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 373..376, - }, - type_params: None, - parameters: Parameters { - range: 376..378, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 388..392, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 453..499, - test: Call( - ExprCall { - range: 456..472, - func: Name( - ExprName { - range: 456..460, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 460..472, - args: [ - Name( - ExprName { - range: 461..464, - id: "foo", - ctx: Load, - }, - ), - List( - ExprList { - range: 466..471, - elts: [ - Name( - ExprName { - range: 467..468, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 470..471, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 476..499, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 480..483, - }, - type_params: None, - parameters: Parameters { - range: 483..485, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 495..499, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 564..611, - test: Call( - ExprCall { - range: 567..583, - func: Name( - ExprName { - range: 567..571, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 571..583, - args: [ - Name( - ExprName { - range: 572..575, - id: "foo", - ctx: Load, - }, - ), - List( - ExprList { - range: 577..582, - elts: [ - Name( - ExprName { - range: 578..579, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 581..582, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 588..611, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 592..595, - }, - type_params: None, - parameters: Parameters { - range: 595..597, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 607..611, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 772..824, - test: Call( - ExprCall { - range: 775..796, - func: Name( - ExprName { - range: 775..779, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 779..796, - args: [ - Name( - ExprName { - range: 780..783, - id: "foo", - ctx: Load, - }, - ), - List( - ExprList { - range: 785..794, - elts: [ - Name( - ExprName { - range: 786..787, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 793..794, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 801..824, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 805..808, - }, - type_params: None, - parameters: Parameters { - range: 808..810, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 820..824, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 887..933, - test: Call( - ExprCall { - range: 890..905, - func: Name( - ExprName { - range: 890..894, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 894..905, - args: [ - FString( - ExprFString { - range: 895..905, - value: FStringValue { - inner: Single( - FString( - FString { - range: 895..905, - elements: [ - Literal( - FStringLiteralElement { - range: 897..903, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 903..905, - expression: Name( - ExprName { - range: 904..905, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 910..933, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 914..917, - }, - type_params: None, - parameters: Parameters { - range: 917..919, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 929..933, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 936..956, - test: Call( - ExprCall { - range: 939..956, - func: Name( - ExprName { - range: 939..943, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 943..956, - args: [ - FString( - ExprFString { - range: 944..951, - value: FStringValue { - inner: Single( - FString( - FString { - range: 944..951, - elements: [], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [], - elif_else_clauses: [], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 956..979, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 960..963, - }, - type_params: None, - parameters: Parameters { - range: 963..965, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 975..979, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # No indentation before the function definition -2 | if call(foo - | ^ Syntax Error: Expected ')', found newline -3 | def bar(): -4 | pass - | - - - | -1 | # No indentation before the function definition -2 | if call(foo -3 | def bar(): - | ^^^ Syntax Error: Expected an indented block after `if` statement -4 | pass - | - - - | - 7 | # Indented function definition - 8 | if call(foo - | ^ Syntax Error: Expected ')', found newline - 9 | def bar(): -10 | pass - | - - - | -13 | # There are multiple non-logical newlines (blank lines) in the `if` body -14 | if call(foo - | ^ Syntax Error: Expected ')', found newline -15 | -16 | -17 | def bar(): - | - - - | -21 | # There are trailing whitespaces in the blank line inside the `if` body -22 | if call(foo - | ^ Syntax Error: Expected ')', found newline -23 | -24 | def bar(): -25 | pass - | - - - | -28 | # The lexer is nested with multiple levels of parentheses -29 | if call(foo, [a, b - | ^ Syntax Error: Expected ']', found NonLogicalNewline -30 | def bar(): -31 | pass - | - - - | -34 | # The outer parenthesis is closed but the inner bracket isn't -35 | if call(foo, [a, b) - | ^ Syntax Error: Expected ']', found ')' -36 | def bar(): -37 | pass - | - - - | -34 | # The outer parenthesis is closed but the inner bracket isn't -35 | if call(foo, [a, b) - | ^ Syntax Error: Expected ':', found newline -36 | def bar(): -37 | pass - | - - - | -41 | # test is to make sure it emits a `NonLogicalNewline` token after `b`. -42 | if call(foo, [a, -43 | b - | ^ Syntax Error: Expected ']', found NonLogicalNewline -44 | ) -45 | def bar(): -46 | pass - | - - - | -42 | if call(foo, [a, -43 | b -44 | ) - | ^ Syntax Error: Expected ':', found newline -45 | def bar(): -46 | pass - | - - - | -49 | # F-strings uses normal list parsing, so test those as well -50 | if call(f"hello {x - | Syntax Error: f-string: unterminated string -51 | def bar(): -52 | pass - | - - - | -49 | # F-strings uses normal list parsing, so test those as well -50 | if call(f"hello {x -51 | def bar(): - | ^^^ Syntax Error: f-string: expecting '}' -52 | pass - | - - - | -49 | # F-strings uses normal list parsing, so test those as well -50 | if call(f"hello {x - | Syntax Error: Expected FStringEnd, found Unknown -51 | def bar(): -52 | pass - | - - - | -55 | if call(f"hello - | ^^^^^ Syntax Error: f-string: unterminated string -56 | def bar(): -57 | pass - | - - - | -55 | if call(f"hello - | ^ Syntax Error: Expected FStringEnd, found newline -56 | def bar(): -57 | pass - | - - - | -55 | if call(f"hello -56 | def bar(): - | ^^^^ Syntax Error: Expected ',', found indent -57 | pass - | - - - | -55 | if call(f"hello -56 | def bar(): - | ^^^ Syntax Error: Expected ')', found 'def' -57 | pass - | - - - | -55 | if call(f"hello -56 | def bar(): -57 | pass - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap.new deleted file mode 100644 index bdf6962669..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap.new +++ /dev/null @@ -1,105 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py ---- -## AST - -``` -Module( - ModModule { - range: 0..46, - body: [ - If( - StmtIf { - range: 0..46, - test: Call( - ExprCall { - range: 3..19, - func: Name( - ExprName { - range: 3..7, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 7..19, - args: [ - Name( - ExprName { - range: 8..11, - id: "foo", - ctx: Load, - }, - ), - List( - ExprList { - range: 13..18, - elts: [ - Name( - ExprName { - range: 14..15, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 17..18, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 23..46, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 27..30, - }, - type_params: None, - parameters: Parameters { - range: 30..32, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 42..46, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if call(foo, [a, b def bar(): pass - | Syntax Error: Expected ']', found NonLogicalNewline - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap.new deleted file mode 100644 index d234119959..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap.new +++ /dev/null @@ -1,108 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py ---- -## AST - -``` -Module( - ModModule { - range: 0..50, - body: [ - If( - StmtIf { - range: 0..48, - test: Call( - ExprCall { - range: 3..20, - func: Name( - ExprName { - range: 3..7, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 7..20, - args: [ - Name( - ExprName { - range: 8..11, - id: "foo", - ctx: Load, - }, - ), - List( - ExprList { - range: 13..18, - elts: [ - Name( - ExprName { - range: 14..15, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 17..18, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 24..48, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 28..31, - }, - type_params: None, - parameters: Parameters { - range: 31..33, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 44..48, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | if call(foo, [a, b - | ___________________^ -2 | | def bar(): - | |_^ Syntax Error: Expected ']', found NonLogicalNewline -3 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap.new deleted file mode 100644 index a0cd2c5175..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap.new +++ /dev/null @@ -1,424 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/fstring_format_spec_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..298, - body: [ - Expr( - StmtExpr { - range: 162..192, - value: FString( - ExprFString { - range: 162..192, - value: FStringValue { - inner: Single( - FString( - FString { - range: 162..192, - elements: [ - Literal( - FStringLiteralElement { - range: 164..171, - value: "middle ", - }, - ), - Expression( - FStringExpressionElement { - range: 171..191, - expression: StringLiteral( - ExprStringLiteral { - range: 172..180, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 172..180, - value: "string", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 181..191, - elements: [ - Literal( - FStringLiteralElement { - range: 181..191, - value: " ", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 192..198, - value: Name( - ExprName { - range: 192..198, - id: "format", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 199..203, - value: Name( - ExprName { - range: 199..203, - id: "spec", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 207..228, - value: FString( - ExprFString { - range: 207..228, - value: FStringValue { - inner: Single( - FString( - FString { - range: 207..228, - elements: [ - Literal( - FStringLiteralElement { - range: 209..216, - value: "middle ", - }, - ), - Expression( - FStringExpressionElement { - range: 216..228, - expression: StringLiteral( - ExprStringLiteral { - range: 217..225, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 217..225, - value: "string", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 226..228, - elements: [ - Literal( - FStringLiteralElement { - range: 226..228, - value: "\\", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 237..250, - value: StringLiteral( - ExprStringLiteral { - range: 237..250, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 237..250, - value: "format spec", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 253..285, - value: FString( - ExprFString { - range: 253..285, - value: FStringValue { - inner: Single( - FString( - FString { - range: 253..285, - elements: [ - Literal( - FStringLiteralElement { - range: 255..262, - value: "middle ", - }, - ), - Expression( - FStringExpressionElement { - range: 262..284, - expression: StringLiteral( - ExprStringLiteral { - range: 263..271, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 263..271, - value: "string", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 272..284, - elements: [ - Literal( - FStringLiteralElement { - range: 272..284, - value: "\\ ", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 285..291, - value: Name( - ExprName { - range: 285..291, - id: "format", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 292..296, - value: Name( - ExprName { - range: 292..296, - id: "spec", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -5 | f'middle {'string':\ -6 | 'format spec'} - | ^ Syntax Error: f-string: expecting '}' -7 | -8 | f'middle {'string':\\ - | - - - | -5 | f'middle {'string':\ -6 | 'format spec'} - | ^^^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons -7 | -8 | f'middle {'string':\\ - | - - - | -5 | f'middle {'string':\ -6 | 'format spec'} - | ^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons -7 | -8 | f'middle {'string':\\ - | - - - | -5 | f'middle {'string':\ -6 | 'format spec'} - | ^^ Syntax Error: missing closing quote in string literal -7 | -8 | f'middle {'string':\\ - | - - - | -5 | f'middle {'string':\ -6 | 'format spec'} - | ^ Syntax Error: Expected a statement -7 | -8 | f'middle {'string':\\ -9 | 'format spec'} - | - - - | -6 | 'format spec'} -7 | -8 | f'middle {'string':\\ - | Syntax Error: f-string: unterminated string -9 | 'format spec'} - | - - - | - 8 | f'middle {'string':\\ - 9 | 'format spec'} - | ^^^^^^^^ Syntax Error: Unexpected indentation -10 | -11 | f'middle {'string':\\\ - | - - - | - 8 | f'middle {'string':\\ - 9 | 'format spec'} - | ^ Syntax Error: Expected a statement -10 | -11 | f'middle {'string':\\\ - | - - - | - 8 | f'middle {'string':\\ - 9 | 'format spec'} - | ^ Syntax Error: Expected a statement -10 | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | - - - | - 9 | 'format spec'} -10 | -11 | f'middle {'string':\\\ - | Syntax Error: Expected a statement -12 | 'format spec'} - | - - - | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | ^ Syntax Error: f-string: expecting '}' - | - - - | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | ^^^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | ^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | ^^ Syntax Error: Got unexpected string - | - - - | -11 | f'middle {'string':\\\ -12 | 'format spec'} - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap.new deleted file mode 100644 index d2df2ee573..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap.new +++ /dev/null @@ -1,106 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/line_continuation_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..36, - body: [ - Expr( - StmtExpr { - range: 0..13, - value: Call( - ExprCall { - range: 0..13, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..13, - args: [ - Name( - ExprName { - range: 5..6, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 8..9, - id: "b", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 16..35, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 20..23, - }, - type_params: None, - parameters: Parameters { - range: 23..25, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 31..35, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(a, b, \\\ - | ^ Syntax Error: Expected a newline after line continuation character -2 | -3 | def bar(): - | - - - | -1 | call(a, b, \\\ - | ^ Syntax Error: Expected a newline after line continuation character -2 | -3 | def bar(): - | - - - | -1 | call(a, b, \\\ -2 | - | ^ Syntax Error: Expected ')', found newline -3 | def bar(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap.new deleted file mode 100644 index 447a718882..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap.new +++ /dev/null @@ -1,91 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/line_continuation_windows_eol.py ---- -## AST - -``` -Module( - ModModule { - range: 0..46, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Call( - ExprCall { - range: 0..10, - func: Name( - ExprName { - range: 0..4, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 4..10, - args: [ - Name( - ExprName { - range: 5..6, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 8..9, - id: "b", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - FunctionDef( - StmtFunctionDef { - range: 26..46, - is_async: false, - decorator_list: [], - name: Identifier { - id: "bar", - range: 30..33, - }, - type_params: None, - parameters: Parameters { - range: 33..35, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 42..46, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | call(a, b, # comment \ - | _______________________^ -2 | | - | |_^ Syntax Error: Expected ')', found newline -3 | def bar(): -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap.new deleted file mode 100644 index 58e85bf80a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap.new +++ /dev/null @@ -1,97 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_fstring_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..198, - body: [ - Expr( - StmtExpr { - range: 166..178, - value: FString( - ExprFString { - range: 166..178, - value: FStringValue { - inner: Single( - FString( - FString { - range: 166..178, - elements: [ - Literal( - FStringLiteralElement { - range: 170..176, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 176..178, - expression: Name( - ExprName { - range: 177..178, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -3 | # https://github.com/astral-sh/ruff/issues/11929 -4 | -5 | f"""hello {x # comment - | ___________________________^ -6 | | y = 1 - | |_____^ Syntax Error: f-string: unterminated triple-quoted string - | - - - | -5 | f"""hello {x # comment -6 | y = 1 - | ^ Syntax Error: f-string: expecting '}' - | - - - | -3 | # https://github.com/astral-sh/ruff/issues/11929 -4 | -5 | f"""hello {x # comment - | ___________________________^ -6 | | y = 1 - | |_____^ Syntax Error: Expected FStringEnd, found Unknown - | - - - | -5 | f"""hello {x # comment -6 | y = 1 - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap.new deleted file mode 100644 index 048d12450a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap.new +++ /dev/null @@ -1,76 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_fstring_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..183, - body: [ - Expr( - StmtExpr { - range: 167..183, - value: FString( - ExprFString { - range: 167..183, - value: FStringValue { - inner: Single( - FString( - FString { - range: 167..183, - elements: [ - Expression( - FStringExpressionElement { - range: 171..180, - expression: Name( - ExprName { - range: 172..175, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 176..180, - elements: [ - Literal( - FStringLiteralElement { - range: 176..180, - value: ".3f\n", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -5 | f'''{foo:.3f -6 | ''' - | ^^^ Syntax Error: f-string: expecting '}' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap.new deleted file mode 100644 index 1bb140afee..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap.new +++ /dev/null @@ -1,111 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_fstring_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..262, - body: [ - If( - StmtIf { - range: 231..262, - test: Call( - ExprCall { - range: 234..253, - func: Name( - ExprName { - range: 234..238, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 238..253, - args: [ - FString( - ExprFString { - range: 239..253, - value: FStringValue { - inner: Single( - FString( - FString { - range: 239..253, - elements: [ - Expression( - FStringExpressionElement { - range: 243..250, - expression: Name( - ExprName { - range: 244..245, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 246..250, - elements: [ - Literal( - FStringLiteralElement { - range: 246..250, - value: ".3f\n", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - body: [ - Pass( - StmtPass { - range: 258..262, - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -5 | if call(f'''{x:.3f -6 | ''' - | ^^^ Syntax Error: f-string: expecting '}' -7 | pass - | - - - | -5 | if call(f'''{x:.3f -6 | ''' - | ^ Syntax Error: Expected ')', found newline -7 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap.new deleted file mode 100644 index 47494e5884..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap.new +++ /dev/null @@ -1,183 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/return_stmt_invalid_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..74, - body: [ - Return( - StmtReturn { - range: 0..8, - value: Some( - Starred( - ExprStarred { - range: 7..8, - value: Name( - ExprName { - range: 8..8, - id: "", - ctx: Invalid, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 9..23, - value: Some( - Yield( - ExprYield { - range: 16..23, - value: Some( - Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 24..43, - value: Some( - YieldFrom( - ExprYieldFrom { - range: 31..43, - value: Name( - ExprName { - range: 42..43, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 44..52, - value: Some( - Name( - ExprName { - range: 51..52, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - Expr( - StmtExpr { - range: 56..57, - value: NumberLiteral( - ExprNumberLiteral { - range: 56..57, - value: Int( - 1, - ), - }, - ), - }, - ), - Return( - StmtReturn { - range: 58..73, - value: Some( - Starred( - ExprStarred { - range: 65..73, - value: BoolOp( - ExprBoolOp { - range: 66..73, - op: And, - values: [ - Name( - ExprName { - range: 66..67, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 72..73, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | return * - | ^ Syntax Error: Expected an expression -2 | return yield x -3 | return yield from x -4 | return x := 1 - | - - - | -1 | return * -2 | return yield x - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | return yield from x -4 | return x := 1 - | - - - | -1 | return * -2 | return yield x -3 | return yield from x - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | return x := 1 -5 | return *x and y - | - - - | -2 | return yield x -3 | return yield from x -4 | return x := 1 - | ^^ Syntax Error: Expected a statement -5 | return *x and y - | - - - | -3 | return yield from x -4 | return x := 1 -5 | return *x and y - | ^^^^^^^ Syntax Error: Boolean expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap.new deleted file mode 100644 index 588bc942c4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap.new +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/simple_and_compound_stmt_on_same_line.py ---- -## AST - -``` -Module( - ModModule { - range: 0..17, - body: [ - Expr( - StmtExpr { - range: 0..1, - value: Name( - ExprName { - range: 0..1, - id: "a", - ctx: Load, - }, - ), - }, - ), - If( - StmtIf { - range: 3..16, - test: Name( - ExprName { - range: 6..7, - id: "b", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - Expr( - StmtExpr { - range: 15..16, - value: Name( - ExprName { - range: 15..16, - id: "b", - ctx: Load, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | a; if b: pass; b - | ^^ Syntax Error: Compound statements are not allowed on the same line as simple statements - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap.new deleted file mode 100644 index 1cacba6c79..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap.new +++ /dev/null @@ -1,147 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/simple_stmts_on_same_line.py ---- -## AST - -``` -Module( - ModModule { - range: 0..53, - body: [ - Expr( - StmtExpr { - range: 0..1, - value: Name( - ExprName { - range: 0..1, - id: "a", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 2..3, - value: Name( - ExprName { - range: 2..3, - id: "b", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 4..9, - value: BinOp( - ExprBinOp { - range: 4..9, - left: Name( - ExprName { - range: 4..5, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 8..9, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..15, - value: BinOp( - ExprBinOp { - range: 10..15, - left: Name( - ExprName { - range: 10..11, - id: "c", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 14..15, - id: "d", - ctx: Load, - }, - ), - }, - ), - }, - ), - Break( - StmtBreak { - range: 16..21, - }, - ), - Continue( - StmtContinue { - range: 23..31, - }, - ), - Pass( - StmtPass { - range: 32..36, - }, - ), - Continue( - StmtContinue { - range: 38..46, - }, - ), - Break( - StmtBreak { - range: 47..52, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | a b - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons -2 | a + b c + d -3 | break; continue pass; continue break - | - - - | -1 | a b -2 | a + b c + d - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | break; continue pass; continue break - | - - - | -1 | a b -2 | a + b c + d -3 | break; continue pass; continue break - | ^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | - - - | -1 | a b -2 | a + b c + d -3 | break; continue pass; continue break - | ^^^^^ Syntax Error: Simple statements must be separated by newlines or semicolons - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap.new deleted file mode 100644 index a7820ca504..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap.new +++ /dev/null @@ -1,404 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/function_type_parameters.py ---- -## AST - -``` -Module( - ModModule { - range: 0..988, - body: [ - FunctionDef( - StmtFunctionDef { - range: 796..824, - is_async: false, - decorator_list: [], - name: Identifier { - id: "keyword", - range: 800..807, - }, - type_params: Some( - TypeParams { - range: 807..817, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 808..809, - name: Identifier { - id: "A", - range: 808..809, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 811..816, - name: Identifier { - id: "await", - range: 811..816, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 817..819, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 821..824, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 821..824, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 826..862, - is_async: false, - decorator_list: [], - name: Identifier { - id: "not_a_type_param", - range: 830..846, - }, - type_params: Some( - TypeParams { - range: 846..855, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 847..848, - name: Identifier { - id: "A", - range: 847..848, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 853..854, - name: Identifier { - id: "B", - range: 853..854, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 855..857, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 859..862, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 859..862, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 864..896, - is_async: false, - decorator_list: [], - name: Identifier { - id: "multiple_commas", - range: 868..883, - }, - type_params: Some( - TypeParams { - range: 883..889, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 884..885, - name: Identifier { - id: "A", - range: 884..885, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 887..888, - name: Identifier { - id: "B", - range: 887..888, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 889..891, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 893..896, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 893..896, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 898..938, - is_async: false, - decorator_list: [], - name: Identifier { - id: "multiple_trailing_commas", - range: 902..926, - }, - type_params: Some( - TypeParams { - range: 926..931, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 927..928, - name: Identifier { - id: "A", - range: 927..928, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 931..933, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 935..938, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 935..938, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 940..979, - is_async: false, - decorator_list: [], - name: Identifier { - id: "multiple_commas_and_recovery", - range: 944..972, - }, - type_params: Some( - TypeParams { - range: 972..976, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 973..974, - name: Identifier { - id: "A", - range: 973..974, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 976..976, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 976..979, - value: NumberLiteral( - ExprNumberLiteral { - range: 976..979, - value: Int( - 100, - ), - }, - ), - }, - ), - ], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 980..987, - target: Tuple( - ExprTuple { - range: 980..982, - elts: [], - ctx: Store, - parenthesized: true, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 984..987, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, -) -``` -## Errors - - | - 9 | # on following lines. -10 | -11 | def keyword[A, await](): ... - | ^^^^^ Syntax Error: Expected an identifier, but found a keyword 'await' that cannot be used here -12 | -13 | def not_a_type_param[A, |, B](): ... - | - - - | -11 | def keyword[A, await](): ... -12 | -13 | def not_a_type_param[A, |, B](): ... - | ^ Syntax Error: Expected ',', found '|' -14 | -15 | def multiple_commas[A,,B](): ... - | - - - | -11 | def keyword[A, await](): ... -12 | -13 | def not_a_type_param[A, |, B](): ... - | ^ Syntax Error: Expected a type parameter or the end of the type parameter list -14 | -15 | def multiple_commas[A,,B](): ... - | - - - | -13 | def not_a_type_param[A, |, B](): ... -14 | -15 | def multiple_commas[A,,B](): ... - | ^ Syntax Error: Expected a type parameter or the end of the type parameter list -16 | -17 | def multiple_trailing_commas[A,,](): ... - | - - - | -15 | def multiple_commas[A,,B](): ... -16 | -17 | def multiple_trailing_commas[A,,](): ... - | ^ Syntax Error: Expected a type parameter or the end of the type parameter list -18 | -19 | def multiple_commas_and_recovery[A,,100](): ... - | - - - | -17 | def multiple_trailing_commas[A,,](): ... -18 | -19 | def multiple_commas_and_recovery[A,,100](): ... - | ^ Syntax Error: Expected a type parameter or the end of the type parameter list - | - - - | -17 | def multiple_trailing_commas[A,,](): ... -18 | -19 | def multiple_commas_and_recovery[A,,100](): ... - | ^^^ Syntax Error: Expected ']', found int - | - - - | -17 | def multiple_trailing_commas[A,,](): ... -18 | -19 | def multiple_commas_and_recovery[A,,100](): ... - | ^ Syntax Error: Expected newline, found ']' - | - - - | -17 | def multiple_trailing_commas[A,,](): ... -18 | -19 | def multiple_commas_and_recovery[A,,100](): ... - | ^^ Syntax Error: Only single target (not tuple) can be annotated - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap.new deleted file mode 100644 index d5bb5d9a85..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap.new +++ /dev/null @@ -1,105 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/if_extra_indent.py ---- -## AST - -``` -Module( - ModModule { - range: 0..153, - body: [ - If( - StmtIf { - range: 103..134, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 106..110, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 116..120, - }, - ), - Expr( - StmtExpr { - range: 129..134, - value: BinOp( - ExprBinOp { - range: 129..134, - left: Name( - ExprName { - range: 129..130, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 133..134, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - Pass( - StmtPass { - range: 140..144, - }, - ), - Assign( - StmtAssign { - range: 146..152, - targets: [ - Name( - ExprName { - range: 146..147, - id: "a", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 150..152, - value: Int( - 10, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | if True: -3 | pass -4 | a + b - | ^^^^^^^^ Syntax Error: Unexpected indentation -5 | -6 | pass - | - - - | -6 | pass -7 | -8 | a = 10 - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap.new deleted file mode 100644 index aaa43e26ef..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap.new +++ /dev/null @@ -1,1693 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/invalid_assignment_targets.py ---- -## AST - -``` -Module( - ModModule { - range: 0..788, - body: [ - Assign( - StmtAssign { - range: 201..206, - targets: [ - NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 5, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 205..206, - value: Int( - 3, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 208..214, - target: NumberLiteral( - ExprNumberLiteral { - range: 208..209, - value: Int( - 5, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 213..214, - value: Int( - 3, - ), - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 216..228, - target: NumberLiteral( - ExprNumberLiteral { - range: 217..218, - value: Int( - 5, - ), - }, - ), - annotation: Name( - ExprName { - range: 221..224, - id: "int", - ctx: Load, - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 227..228, - value: Int( - 3, - ), - }, - ), - ), - simple: false, - }, - ), - Assign( - StmtAssign { - range: 303..314, - targets: [ - BoolOp( - ExprBoolOp { - range: 303..309, - op: Or, - values: [ - Name( - ExprName { - range: 303..304, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 308..309, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 312..314, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 315..328, - targets: [ - Named( - ExprNamed { - range: 316..322, - target: Name( - ExprName { - range: 316..317, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 321..322, - value: Int( - 5, - ), - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 326..328, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 329..339, - targets: [ - BinOp( - ExprBinOp { - range: 329..334, - left: Name( - ExprName { - range: 329..330, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 333..334, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 337..339, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 340..347, - targets: [ - UnaryOp( - ExprUnaryOp { - range: 340..342, - op: USub, - operand: Name( - ExprName { - range: 341..342, - id: "x", - ctx: Store, - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 345..347, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 348..366, - targets: [ - Lambda( - ExprLambda { - range: 349..360, - parameters: Some( - Parameters { - range: 356..357, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 356..357, - parameter: Parameter { - range: 356..357, - name: Identifier { - id: "_", - range: 356..357, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 359..360, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 364..366, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 367..385, - targets: [ - If( - ExprIf { - range: 367..380, - test: Name( - ExprName { - range: 372..373, - id: "b", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 367..368, - id: "a", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 379..380, - id: "c", - ctx: Load, - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 383..385, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 386..399, - targets: [ - Dict( - ExprDict { - range: 386..394, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 387..390, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 387..390, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 392..393, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 397..399, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 400..408, - targets: [ - Set( - ExprSet { - range: 400..403, - elts: [ - Name( - ExprName { - range: 401..402, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 406..408, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 409..429, - targets: [ - ListComp( - ExprListComp { - range: 409..424, - elt: Name( - ExprName { - range: 410..411, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 412..423, - target: Name( - ExprName { - range: 416..417, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 421..423, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 427..429, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 430..450, - targets: [ - SetComp( - ExprSetComp { - range: 430..445, - elt: Name( - ExprName { - range: 431..432, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 433..444, - target: Name( - ExprName { - range: 437..438, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 442..444, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 448..450, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 451..478, - targets: [ - DictComp( - ExprDictComp { - range: 451..473, - key: Name( - ExprName { - range: 452..453, - id: "x", - ctx: Load, - }, - ), - value: BinOp( - ExprBinOp { - range: 455..460, - left: Name( - ExprName { - range: 455..456, - id: "x", - ctx: Load, - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 459..460, - value: Int( - 2, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 461..472, - target: Name( - ExprName { - range: 465..466, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 470..472, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 476..478, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 479..499, - targets: [ - Generator( - ExprGenerator { - range: 479..494, - elt: Name( - ExprName { - range: 480..481, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 482..493, - target: Name( - ExprName { - range: 486..487, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 491..493, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 497..499, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 500..512, - targets: [ - Await( - ExprAwait { - range: 500..507, - value: Name( - ExprName { - range: 506..507, - id: "x", - ctx: Load, - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 510..512, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 513..527, - targets: [ - Yield( - ExprYield { - range: 514..521, - value: Some( - Name( - ExprName { - range: 520..521, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 525..527, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 528..548, - targets: [ - YieldFrom( - ExprYieldFrom { - range: 529..542, - value: Name( - ExprName { - range: 540..542, - id: "xs", - ctx: Load, - }, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 546..548, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 549..563, - targets: [ - Compare( - ExprCompare { - range: 549..558, - left: Name( - ExprName { - range: 549..550, - id: "a", - ctx: Load, - }, - ), - ops: [ - Lt, - Lt, - ], - comparators: [ - Name( - ExprName { - range: 553..554, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 557..558, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 561..563, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 564..574, - targets: [ - Call( - ExprCall { - range: 564..569, - func: Name( - ExprName { - range: 564..567, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 567..569, - args: [], - keywords: [], - }, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 572..574, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 576..590, - targets: [ - FString( - ExprFString { - range: 576..585, - value: FStringValue { - inner: Single( - FString( - FString { - range: 576..585, - elements: [ - Expression( - FStringExpressionElement { - range: 578..584, - expression: Name( - ExprName { - range: 579..583, - id: "quux", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 588..590, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 591..614, - targets: [ - FString( - ExprFString { - range: 591..609, - value: FStringValue { - inner: Single( - FString( - FString { - range: 591..609, - elements: [ - Expression( - FStringExpressionElement { - range: 593..598, - expression: Name( - ExprName { - range: 594..597, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 598..603, - value: " and ", - }, - ), - Expression( - FStringExpressionElement { - range: 603..608, - expression: Name( - ExprName { - range: 604..607, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 612..614, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 616..626, - targets: [ - StringLiteral( - ExprStringLiteral { - range: 616..621, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 616..621, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 624..626, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 627..638, - targets: [ - BytesLiteral( - ExprBytesLiteral { - range: 627..633, - value: BytesLiteralValue { - inner: Single( - BytesLiteral { - range: 627..633, - value: [ - 102, - 111, - 111, - ], - flags: BytesLiteralFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 636..638, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 639..647, - targets: [ - NumberLiteral( - ExprNumberLiteral { - range: 639..642, - value: Int( - 123, - ), - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 645..647, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 648..657, - targets: [ - BooleanLiteral( - ExprBooleanLiteral { - range: 648..652, - value: true, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 655..657, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 658..667, - targets: [ - NoneLiteral( - ExprNoneLiteral { - range: 658..662, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 665..667, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 668..676, - targets: [ - EllipsisLiteral( - ExprEllipsisLiteral { - range: 668..671, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 674..676, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 677..688, - targets: [ - Starred( - ExprStarred { - range: 677..683, - value: Call( - ExprCall { - range: 678..683, - func: Name( - ExprName { - range: 678..681, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 681..683, - args: [], - keywords: [], - }, - }, - ), - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 686..688, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 689..717, - targets: [ - List( - ExprList { - range: 689..702, - elts: [ - Name( - ExprName { - range: 690..691, - id: "x", - ctx: Store, - }, - ), - Call( - ExprCall { - range: 693..698, - func: Name( - ExprName { - range: 693..696, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 696..698, - args: [], - keywords: [], - }, - }, - ), - Name( - ExprName { - range: 700..701, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 705..717, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 706..708, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 710..712, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 714..716, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 718..758, - targets: [ - List( - ExprList { - range: 718..737, - elts: [ - List( - ExprList { - range: 719..725, - elts: [ - Name( - ExprName { - range: 720..721, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 723..724, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - List( - ExprList { - range: 727..733, - elts: [ - List( - ExprList { - range: 728..732, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 729..731, - value: Int( - 42, - ), - }, - ), - ], - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - Name( - ExprName { - range: 735..736, - id: "d", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 740..758, - elts: [ - List( - ExprList { - range: 741..747, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 742..743, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 745..746, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - List( - ExprList { - range: 749..754, - elts: [ - List( - ExprList { - range: 750..753, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 751..752, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 756..757, - value: Int( - 4, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 759..787, - targets: [ - Tuple( - ExprTuple { - range: 759..772, - elts: [ - Name( - ExprName { - range: 760..761, - id: "x", - ctx: Store, - }, - ), - Call( - ExprCall { - range: 763..768, - func: Name( - ExprName { - range: 763..766, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 766..768, - args: [], - keywords: [], - }, - }, - ), - Name( - ExprName { - range: 770..771, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 775..787, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 776..778, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 780..782, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 784..786, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -3 | # rejected by the parser. e.g., `5 = 3`, `5 += 3`, `(5): int = 3`. -4 | -5 | 5 = 3 - | ^ Syntax Error: Invalid assignment target -6 | -7 | 5 += 3 - | - - - | -5 | 5 = 3 -6 | -7 | 5 += 3 - | ^ Syntax Error: Invalid augmented assignment target -8 | -9 | (5): int = 3 - | - - - | - 7 | 5 += 3 - 8 | - 9 | (5): int = 3 - | ^ Syntax Error: Invalid annotated assignment target -10 | -11 | # Now we exhaustively test all possible cases where assignment can fail. - | - - - | -11 | # Now we exhaustively test all possible cases where assignment can fail. -12 | x or y = 42 - | ^^^^^^ Syntax Error: Invalid assignment target -13 | (x := 5) = 42 -14 | x + y = 42 - | - - - | -11 | # Now we exhaustively test all possible cases where assignment can fail. -12 | x or y = 42 -13 | (x := 5) = 42 - | ^^^^^^ Syntax Error: Invalid assignment target -14 | x + y = 42 -15 | -x = 42 - | - - - | -12 | x or y = 42 -13 | (x := 5) = 42 -14 | x + y = 42 - | ^^^^^ Syntax Error: Invalid assignment target -15 | -x = 42 -16 | (lambda _: 1) = 42 - | - - - | -13 | (x := 5) = 42 -14 | x + y = 42 -15 | -x = 42 - | ^^ Syntax Error: Invalid assignment target -16 | (lambda _: 1) = 42 -17 | a if b else c = 42 - | - - - | -14 | x + y = 42 -15 | -x = 42 -16 | (lambda _: 1) = 42 - | ^^^^^^^^^^^ Syntax Error: Invalid assignment target -17 | a if b else c = 42 -18 | {"a": 5} = 42 - | - - - | -15 | -x = 42 -16 | (lambda _: 1) = 42 -17 | a if b else c = 42 - | ^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -18 | {"a": 5} = 42 -19 | {a} = 42 - | - - - | -16 | (lambda _: 1) = 42 -17 | a if b else c = 42 -18 | {"a": 5} = 42 - | ^^^^^^^^ Syntax Error: Invalid assignment target -19 | {a} = 42 -20 | [x for x in xs] = 42 - | - - - | -17 | a if b else c = 42 -18 | {"a": 5} = 42 -19 | {a} = 42 - | ^^^ Syntax Error: Invalid assignment target -20 | [x for x in xs] = 42 -21 | {x for x in xs} = 42 - | - - - | -18 | {"a": 5} = 42 -19 | {a} = 42 -20 | [x for x in xs] = 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -21 | {x for x in xs} = 42 -22 | {x: x * 2 for x in xs} = 42 - | - - - | -19 | {a} = 42 -20 | [x for x in xs] = 42 -21 | {x for x in xs} = 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -22 | {x: x * 2 for x in xs} = 42 -23 | (x for x in xs) = 42 - | - - - | -20 | [x for x in xs] = 42 -21 | {x for x in xs} = 42 -22 | {x: x * 2 for x in xs} = 42 - | ^^^^^^^^^^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -23 | (x for x in xs) = 42 -24 | await x = 42 - | - - - | -21 | {x for x in xs} = 42 -22 | {x: x * 2 for x in xs} = 42 -23 | (x for x in xs) = 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -24 | await x = 42 -25 | (yield x) = 42 - | - - - | -22 | {x: x * 2 for x in xs} = 42 -23 | (x for x in xs) = 42 -24 | await x = 42 - | ^^^^^^^ Syntax Error: Invalid assignment target -25 | (yield x) = 42 -26 | (yield from xs) = 42 - | - - - | -23 | (x for x in xs) = 42 -24 | await x = 42 -25 | (yield x) = 42 - | ^^^^^^^ Syntax Error: Invalid assignment target -26 | (yield from xs) = 42 -27 | a < b < c = 42 - | - - - | -24 | await x = 42 -25 | (yield x) = 42 -26 | (yield from xs) = 42 - | ^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -27 | a < b < c = 42 -28 | foo() = 42 - | - - - | -25 | (yield x) = 42 -26 | (yield from xs) = 42 -27 | a < b < c = 42 - | ^^^^^^^^^ Syntax Error: Invalid assignment target -28 | foo() = 42 - | - - - | -26 | (yield from xs) = 42 -27 | a < b < c = 42 -28 | foo() = 42 - | ^^^^^ Syntax Error: Invalid assignment target -29 | -30 | f"{quux}" = 42 - | - - - | -28 | foo() = 42 -29 | -30 | f"{quux}" = 42 - | ^^^^^^^^^ Syntax Error: Invalid assignment target -31 | f"{foo} and {bar}" = 42 - | - - - | -30 | f"{quux}" = 42 -31 | f"{foo} and {bar}" = 42 - | ^^^^^^^^^^^^^^^^^^ Syntax Error: Invalid assignment target -32 | -33 | "foo" = 42 - | - - - | -31 | f"{foo} and {bar}" = 42 -32 | -33 | "foo" = 42 - | ^^^^^ Syntax Error: Invalid assignment target -34 | b"foo" = 42 -35 | 123 = 42 - | - - - | -33 | "foo" = 42 -34 | b"foo" = 42 - | ^^^^^^ Syntax Error: Invalid assignment target -35 | 123 = 42 -36 | True = 42 - | - - - | -33 | "foo" = 42 -34 | b"foo" = 42 -35 | 123 = 42 - | ^^^ Syntax Error: Invalid assignment target -36 | True = 42 -37 | None = 42 - | - - - | -34 | b"foo" = 42 -35 | 123 = 42 -36 | True = 42 - | ^^^^ Syntax Error: Invalid assignment target -37 | None = 42 -38 | ... = 42 - | - - - | -35 | 123 = 42 -36 | True = 42 -37 | None = 42 - | ^^^^ Syntax Error: Invalid assignment target -38 | ... = 42 -39 | *foo() = 42 - | - - - | -36 | True = 42 -37 | None = 42 -38 | ... = 42 - | ^^^ Syntax Error: Invalid assignment target -39 | *foo() = 42 -40 | [x, foo(), y] = [42, 42, 42] - | - - - | -37 | None = 42 -38 | ... = 42 -39 | *foo() = 42 - | ^^^^^ Syntax Error: Invalid assignment target -40 | [x, foo(), y] = [42, 42, 42] -41 | [[a, b], [[42]], d] = [[1, 2], [[3]], 4] - | - - - | -38 | ... = 42 -39 | *foo() = 42 -40 | [x, foo(), y] = [42, 42, 42] - | ^^^^^ Syntax Error: Invalid assignment target -41 | [[a, b], [[42]], d] = [[1, 2], [[3]], 4] -42 | (x, foo(), y) = (42, 42, 42) - | - - - | -39 | *foo() = 42 -40 | [x, foo(), y] = [42, 42, 42] -41 | [[a, b], [[42]], d] = [[1, 2], [[3]], 4] - | ^^ Syntax Error: Invalid assignment target -42 | (x, foo(), y) = (42, 42, 42) - | - - - | -40 | [x, foo(), y] = [42, 42, 42] -41 | [[a, b], [[42]], d] = [[1, 2], [[3]], 4] -42 | (x, foo(), y) = (42, 42, 42) - | ^^^^^ Syntax Error: Invalid assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap.new deleted file mode 100644 index 34323c9f7a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap.new +++ /dev/null @@ -1,1558 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/invalid_augmented_assignment_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..611, - body: [ - AugAssign( - StmtAugAssign { - range: 97..109, - target: BoolOp( - ExprBoolOp { - range: 97..103, - op: Or, - values: [ - Name( - ExprName { - range: 97..98, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 102..103, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 107..109, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 110..124, - target: Named( - ExprNamed { - range: 111..117, - target: Name( - ExprName { - range: 111..112, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 116..117, - value: Int( - 5, - ), - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 122..124, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 125..136, - target: BinOp( - ExprBinOp { - range: 125..130, - left: Name( - ExprName { - range: 125..126, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 129..130, - id: "y", - ctx: Load, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 134..136, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 137..145, - target: UnaryOp( - ExprUnaryOp { - range: 137..139, - op: USub, - operand: Name( - ExprName { - range: 138..139, - id: "x", - ctx: Store, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 143..145, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 146..165, - target: Lambda( - ExprLambda { - range: 147..158, - parameters: Some( - Parameters { - range: 154..155, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 154..155, - parameter: Parameter { - range: 154..155, - name: Identifier { - id: "_", - range: 154..155, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 157..158, - value: Int( - 1, - ), - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 163..165, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 166..185, - target: If( - ExprIf { - range: 166..179, - test: Name( - ExprName { - range: 171..172, - id: "b", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 166..167, - id: "a", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 178..179, - id: "c", - ctx: Load, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 183..185, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 186..200, - target: Dict( - ExprDict { - range: 186..194, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 187..190, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 187..190, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 192..193, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 198..200, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 201..210, - target: Set( - ExprSet { - range: 201..204, - elts: [ - Name( - ExprName { - range: 202..203, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 208..210, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 211..232, - target: ListComp( - ExprListComp { - range: 211..226, - elt: Name( - ExprName { - range: 212..213, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 214..225, - target: Name( - ExprName { - range: 218..219, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 223..225, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 230..232, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 233..254, - target: SetComp( - ExprSetComp { - range: 233..248, - elt: Name( - ExprName { - range: 234..235, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 236..247, - target: Name( - ExprName { - range: 240..241, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 245..247, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 252..254, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 255..283, - target: DictComp( - ExprDictComp { - range: 255..277, - key: Name( - ExprName { - range: 256..257, - id: "x", - ctx: Load, - }, - ), - value: BinOp( - ExprBinOp { - range: 259..264, - left: Name( - ExprName { - range: 259..260, - id: "x", - ctx: Load, - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 263..264, - value: Int( - 2, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 265..276, - target: Name( - ExprName { - range: 269..270, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 274..276, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 281..283, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 284..305, - target: Generator( - ExprGenerator { - range: 284..299, - elt: Name( - ExprName { - range: 285..286, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 287..298, - target: Name( - ExprName { - range: 291..292, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 296..298, - id: "xs", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 303..305, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 306..319, - target: Await( - ExprAwait { - range: 306..313, - value: Name( - ExprName { - range: 312..313, - id: "x", - ctx: Load, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 317..319, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 320..335, - target: Yield( - ExprYield { - range: 321..328, - value: Some( - Name( - ExprName { - range: 327..328, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 333..335, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 336..357, - target: YieldFrom( - ExprYieldFrom { - range: 337..350, - value: Name( - ExprName { - range: 348..350, - id: "xs", - ctx: Load, - }, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 355..357, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 358..373, - target: Compare( - ExprCompare { - range: 358..367, - left: Name( - ExprName { - range: 358..359, - id: "a", - ctx: Load, - }, - ), - ops: [ - Lt, - Lt, - ], - comparators: [ - Name( - ExprName { - range: 362..363, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 366..367, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 371..373, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 374..385, - target: Call( - ExprCall { - range: 374..379, - func: Name( - ExprName { - range: 374..377, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 377..379, - args: [], - keywords: [], - }, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 383..385, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 387..402, - target: FString( - ExprFString { - range: 387..396, - value: FStringValue { - inner: Single( - FString( - FString { - range: 387..396, - elements: [ - Expression( - FStringExpressionElement { - range: 389..395, - expression: Name( - ExprName { - range: 390..394, - id: "quux", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 400..402, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 403..427, - target: FString( - ExprFString { - range: 403..421, - value: FStringValue { - inner: Single( - FString( - FString { - range: 403..421, - elements: [ - Expression( - FStringExpressionElement { - range: 405..410, - expression: Name( - ExprName { - range: 406..409, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 410..415, - value: " and ", - }, - ), - Expression( - FStringExpressionElement { - range: 415..420, - expression: Name( - ExprName { - range: 416..419, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 425..427, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 429..440, - target: StringLiteral( - ExprStringLiteral { - range: 429..434, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 429..434, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 438..440, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 441..453, - target: BytesLiteral( - ExprBytesLiteral { - range: 441..447, - value: BytesLiteralValue { - inner: Single( - BytesLiteral { - range: 441..447, - value: [ - 102, - 111, - 111, - ], - flags: BytesLiteralFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 451..453, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 454..463, - target: NumberLiteral( - ExprNumberLiteral { - range: 454..457, - value: Int( - 123, - ), - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 461..463, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 464..474, - target: BooleanLiteral( - ExprBooleanLiteral { - range: 464..468, - value: true, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 472..474, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 475..485, - target: NoneLiteral( - ExprNoneLiteral { - range: 475..479, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 483..485, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 486..495, - target: EllipsisLiteral( - ExprEllipsisLiteral { - range: 486..489, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 493..495, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 496..508, - target: Starred( - ExprStarred { - range: 496..502, - value: Call( - ExprCall { - range: 497..502, - func: Name( - ExprName { - range: 497..500, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 500..502, - args: [], - keywords: [], - }, - }, - ), - ctx: Store, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 506..508, - value: Int( - 42, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 509..538, - target: List( - ExprList { - range: 509..522, - elts: [ - Name( - ExprName { - range: 510..511, - id: "x", - ctx: Store, - }, - ), - Call( - ExprCall { - range: 513..518, - func: Name( - ExprName { - range: 513..516, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 516..518, - args: [], - keywords: [], - }, - }, - ), - Name( - ExprName { - range: 520..521, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - op: Add, - value: List( - ExprList { - range: 526..538, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 527..529, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 531..533, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 535..537, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 539..580, - target: List( - ExprList { - range: 539..558, - elts: [ - List( - ExprList { - range: 540..546, - elts: [ - Name( - ExprName { - range: 541..542, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 544..545, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - List( - ExprList { - range: 548..554, - elts: [ - List( - ExprList { - range: 549..553, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 550..552, - value: Int( - 42, - ), - }, - ), - ], - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - Name( - ExprName { - range: 556..557, - id: "d", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - op: Add, - value: List( - ExprList { - range: 562..580, - elts: [ - List( - ExprList { - range: 563..569, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 564..565, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 567..568, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - List( - ExprList { - range: 571..576, - elts: [ - List( - ExprList { - range: 572..575, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 573..574, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 578..579, - value: Int( - 4, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 581..610, - target: Tuple( - ExprTuple { - range: 581..594, - elts: [ - Name( - ExprName { - range: 582..583, - id: "x", - ctx: Store, - }, - ), - Call( - ExprCall { - range: 585..590, - func: Name( - ExprName { - range: 585..588, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 588..590, - args: [], - keywords: [], - }, - }, - ), - Name( - ExprName { - range: 592..593, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - op: Add, - value: Tuple( - ExprTuple { - range: 598..610, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 599..601, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 603..605, - value: Int( - 42, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 607..609, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # assignment targets. -3 | -4 | x or y += 42 - | ^^^^^^ Syntax Error: Invalid augmented assignment target -5 | (x := 5) += 42 -6 | x + y += 42 - | - - - | -4 | x or y += 42 -5 | (x := 5) += 42 - | ^^^^^^ Syntax Error: Invalid augmented assignment target -6 | x + y += 42 -7 | -x += 42 - | - - - | -4 | x or y += 42 -5 | (x := 5) += 42 -6 | x + y += 42 - | ^^^^^ Syntax Error: Invalid augmented assignment target -7 | -x += 42 -8 | (lambda _: 1) += 42 - | - - - | -5 | (x := 5) += 42 -6 | x + y += 42 -7 | -x += 42 - | ^^ Syntax Error: Invalid augmented assignment target -8 | (lambda _: 1) += 42 -9 | a if b else c += 42 - | - - - | - 6 | x + y += 42 - 7 | -x += 42 - 8 | (lambda _: 1) += 42 - | ^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target - 9 | a if b else c += 42 -10 | {"a": 5} += 42 - | - - - | - 7 | -x += 42 - 8 | (lambda _: 1) += 42 - 9 | a if b else c += 42 - | ^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -10 | {"a": 5} += 42 -11 | {a} += 42 - | - - - | - 8 | (lambda _: 1) += 42 - 9 | a if b else c += 42 -10 | {"a": 5} += 42 - | ^^^^^^^^ Syntax Error: Invalid augmented assignment target -11 | {a} += 42 -12 | [x for x in xs] += 42 - | - - - | - 9 | a if b else c += 42 -10 | {"a": 5} += 42 -11 | {a} += 42 - | ^^^ Syntax Error: Invalid augmented assignment target -12 | [x for x in xs] += 42 -13 | {x for x in xs} += 42 - | - - - | -10 | {"a": 5} += 42 -11 | {a} += 42 -12 | [x for x in xs] += 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -13 | {x for x in xs} += 42 -14 | {x: x * 2 for x in xs} += 42 - | - - - | -11 | {a} += 42 -12 | [x for x in xs] += 42 -13 | {x for x in xs} += 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -14 | {x: x * 2 for x in xs} += 42 -15 | (x for x in xs) += 42 - | - - - | -12 | [x for x in xs] += 42 -13 | {x for x in xs} += 42 -14 | {x: x * 2 for x in xs} += 42 - | ^^^^^^^^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -15 | (x for x in xs) += 42 -16 | await x += 42 - | - - - | -13 | {x for x in xs} += 42 -14 | {x: x * 2 for x in xs} += 42 -15 | (x for x in xs) += 42 - | ^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -16 | await x += 42 -17 | (yield x) += 42 - | - - - | -14 | {x: x * 2 for x in xs} += 42 -15 | (x for x in xs) += 42 -16 | await x += 42 - | ^^^^^^^ Syntax Error: Invalid augmented assignment target -17 | (yield x) += 42 -18 | (yield from xs) += 42 - | - - - | -15 | (x for x in xs) += 42 -16 | await x += 42 -17 | (yield x) += 42 - | ^^^^^^^ Syntax Error: Invalid augmented assignment target -18 | (yield from xs) += 42 -19 | a < b < c += 42 - | - - - | -16 | await x += 42 -17 | (yield x) += 42 -18 | (yield from xs) += 42 - | ^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -19 | a < b < c += 42 -20 | foo() += 42 - | - - - | -17 | (yield x) += 42 -18 | (yield from xs) += 42 -19 | a < b < c += 42 - | ^^^^^^^^^ Syntax Error: Invalid augmented assignment target -20 | foo() += 42 - | - - - | -18 | (yield from xs) += 42 -19 | a < b < c += 42 -20 | foo() += 42 - | ^^^^^ Syntax Error: Invalid augmented assignment target -21 | -22 | f"{quux}" += 42 - | - - - | -20 | foo() += 42 -21 | -22 | f"{quux}" += 42 - | ^^^^^^^^^ Syntax Error: Invalid augmented assignment target -23 | f"{foo} and {bar}" += 42 - | - - - | -22 | f"{quux}" += 42 -23 | f"{foo} and {bar}" += 42 - | ^^^^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -24 | -25 | "foo" += 42 - | - - - | -23 | f"{foo} and {bar}" += 42 -24 | -25 | "foo" += 42 - | ^^^^^ Syntax Error: Invalid augmented assignment target -26 | b"foo" += 42 -27 | 123 += 42 - | - - - | -25 | "foo" += 42 -26 | b"foo" += 42 - | ^^^^^^ Syntax Error: Invalid augmented assignment target -27 | 123 += 42 -28 | True += 42 - | - - - | -25 | "foo" += 42 -26 | b"foo" += 42 -27 | 123 += 42 - | ^^^ Syntax Error: Invalid augmented assignment target -28 | True += 42 -29 | None += 42 - | - - - | -26 | b"foo" += 42 -27 | 123 += 42 -28 | True += 42 - | ^^^^ Syntax Error: Invalid augmented assignment target -29 | None += 42 -30 | ... += 42 - | - - - | -27 | 123 += 42 -28 | True += 42 -29 | None += 42 - | ^^^^ Syntax Error: Invalid augmented assignment target -30 | ... += 42 -31 | *foo() += 42 - | - - - | -28 | True += 42 -29 | None += 42 -30 | ... += 42 - | ^^^ Syntax Error: Invalid augmented assignment target -31 | *foo() += 42 -32 | [x, foo(), y] += [42, 42, 42] - | - - - | -29 | None += 42 -30 | ... += 42 -31 | *foo() += 42 - | ^^^^^^ Syntax Error: Invalid augmented assignment target -32 | [x, foo(), y] += [42, 42, 42] -33 | [[a, b], [[42]], d] += [[1, 2], [[3]], 4] - | - - - | -30 | ... += 42 -31 | *foo() += 42 -32 | [x, foo(), y] += [42, 42, 42] - | ^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -33 | [[a, b], [[42]], d] += [[1, 2], [[3]], 4] -34 | (x, foo(), y) += (42, 42, 42) - | - - - | -31 | *foo() += 42 -32 | [x, foo(), y] += [42, 42, 42] -33 | [[a, b], [[42]], d] += [[1, 2], [[3]], 4] - | ^^^^^^^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target -34 | (x, foo(), y) += (42, 42, 42) - | - - - | -32 | [x, foo(), y] += [42, 42, 42] -33 | [[a, b], [[42]], d] += [[1, 2], [[3]], 4] -34 | (x, foo(), y) += (42, 42, 42) - | ^^^^^^^^^^^^^ Syntax Error: Invalid augmented assignment target - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap.new deleted file mode 100644 index e1e08a374e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap.new +++ /dev/null @@ -1,93 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_pattern_0.py ---- -## AST - -``` -Module( - ModModule { - range: 0..198, - body: [ - Match( - StmtMatch { - range: 0..197, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 127..197, - pattern: MatchClass( - PatternMatchClass { - range: 132..146, - cls: Name( - ExprName { - range: 133..139, - id: "", - ctx: Invalid, - }, - ), - arguments: PatternArguments { - range: 140..146, - patterns: [ - MatchAs( - PatternMatchAs { - range: 141..142, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 141..142, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 144..145, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 144..145, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 193..197, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -3 | # class pattern -4 | # v -5 | case (x as y)(a, b): - | ^^^^^^ Syntax Error: Invalid value for a class pattern -6 | # ^^^^^^ -7 | # as-pattern - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap.new deleted file mode 100644 index 2bb3e1c827..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap.new +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_pattern_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..210, - body: [ - Match( - StmtMatch { - range: 0..209, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 140..209, - pattern: MatchValue( - PatternMatchValue { - range: 145..158, - value: BinOp( - ExprBinOp { - range: 145..158, - left: Name( - ExprName { - range: 146..152, - id: "", - ctx: Invalid, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 156..158, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 205..209, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -3 | # complex literal pattern -4 | # v -5 | case (x as y) + 1j: - | ^^^^^^ Syntax Error: Expected a real number in complex literal pattern -6 | # ^^^^^^ -7 | # as-pattern - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap.new deleted file mode 100644 index f0d953fc59..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap.new +++ /dev/null @@ -1,127 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_pattern_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..190, - body: [ - Match( - StmtMatch { - range: 0..176, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 159..176, - pattern: MatchAs( - PatternMatchAs { - range: 164..170, - pattern: Some( - MatchAs( - PatternMatchAs { - range: 164..165, - pattern: None, - name: Some( - Identifier { - id: "x", - range: 164..165, - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "y", - range: 169..170, - }, - ), - }, - ), - guard: None, - body: [ - AnnAssign( - StmtAnnAssign { - range: 171..176, - target: UnaryOp( - ExprUnaryOp { - range: 171..175, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 173..175, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - annotation: Name( - ExprName { - range: 176..176, - id: "", - ctx: Invalid, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, - ], - }, - ), - Pass( - StmtPass { - range: 185..189, - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # This `as` pattern is unparenthesied so the parser never takes the path -3 | # where it might be confused as a complex literal pattern. -4 | case x as y + 1j: - | ^ Syntax Error: Expected ':', found '+' -5 | pass - | - - - | -2 | # This `as` pattern is unparenthesied so the parser never takes the path -3 | # where it might be confused as a complex literal pattern. -4 | case x as y + 1j: - | ^ Syntax Error: Expected an expression -5 | pass - | - - - | -3 | # where it might be confused as a complex literal pattern. -4 | case x as y + 1j: -5 | pass - | ^^^^^^^^ Syntax Error: Expected dedent, found indent - | - - - | -4 | case x as y + 1j: -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap.new deleted file mode 100644 index b4cd1d738a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap.new +++ /dev/null @@ -1,155 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_pattern_3.py ---- -## AST - -``` -Module( - ModModule { - range: 0..136, - body: [ - Match( - StmtMatch { - range: 0..120, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 103..120, - pattern: MatchClass( - PatternMatchClass { - range: 108..117, - cls: Dict( - ExprDict { - range: 108..109, - items: [], - }, - ), - arguments: PatternArguments { - range: 109..117, - patterns: [ - MatchAs( - PatternMatchAs { - range: 110..116, - pattern: Some( - MatchAs( - PatternMatchAs { - range: 110..111, - pattern: None, - name: Some( - Identifier { - id: "x", - range: 110..111, - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "y", - range: 115..116, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 119..120, - value: NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Pass( - StmtPass { - range: 131..135, - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # Not in the mapping start token set, so the list parsing bails -3 | # v -4 | case {(x as y): 1}: - | ^ Syntax Error: Expected '}', found '(' -5 | pass - | - - - | -2 | # Not in the mapping start token set, so the list parsing bails -3 | # v -4 | case {(x as y): 1}: - | ^ Syntax Error: Invalid value for a class pattern -5 | pass - | - - - | -2 | # Not in the mapping start token set, so the list parsing bails -3 | # v -4 | case {(x as y): 1}: - | ^ Syntax Error: Expected newline, found '}' -5 | pass - | - - - | -2 | # Not in the mapping start token set, so the list parsing bails -3 | # v -4 | case {(x as y): 1}: - | ^ Syntax Error: Expected a statement -5 | pass - | - - - | -2 | # Not in the mapping start token set, so the list parsing bails -3 | # v -4 | case {(x as y): 1}: - | ^ Syntax Error: Expected a statement -5 | pass - | - - - | -3 | # v -4 | case {(x as y): 1}: -5 | pass - | ^^^^^^^^ Syntax Error: Unexpected indentation - | - - - | -4 | case {(x as y): 1}: -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap.new deleted file mode 100644 index b753840784..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap.new +++ /dev/null @@ -1,117 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_pattern_4.py ---- -## AST - -``` -Module( - ModModule { - range: 0..187, - body: [ - Match( - StmtMatch { - range: 0..186, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 156..186, - pattern: MatchMapping( - PatternMatchMapping { - range: 161..172, - keys: [ - Name( - ExprName { - range: 162..163, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 167..168, - id: "y", - ctx: Store, - }, - ), - ], - patterns: [ - MatchAs( - PatternMatchAs { - range: 164..166, - pattern: None, - name: Some( - Identifier { - id: "as", - range: 164..166, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 170..171, - value: NumberLiteral( - ExprNumberLiteral { - range: 170..171, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 182..186, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # This `as` pattern is unparenthesized so the parser never takes the path -3 | # where it might be confused as a mapping key pattern. -4 | case {x as y: 1}: - | ^ Syntax Error: Invalid mapping pattern key -5 | pass - | - - - | -2 | # This `as` pattern is unparenthesized so the parser never takes the path -3 | # where it might be confused as a mapping key pattern. -4 | case {x as y: 1}: - | ^^ Syntax Error: Expected ':', found 'as' -5 | pass - | - - - | -2 | # This `as` pattern is unparenthesized so the parser never takes the path -3 | # where it might be confused as a mapping key pattern. -4 | case {x as y: 1}: - | ^ Syntax Error: Expected ',', found name -5 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap.new deleted file mode 100644 index 099ecf153a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap.new +++ /dev/null @@ -1,384 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid_class_pattern.py ---- -## AST - -``` -Module( - ModModule { - range: 0..383, - body: [ - Match( - StmtMatch { - range: 44..285, - subject: Name( - ExprName { - range: 50..57, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 63..97, - pattern: MatchClass( - PatternMatchClass { - range: 68..83, - cls: Name( - ExprName { - range: 68..71, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 71..83, - patterns: [], - keywords: [ - PatternKeyword { - range: 72..82, - attr: Identifier { - id: "", - range: 80..80, - }, - pattern: MatchValue( - PatternMatchValue { - range: 81..82, - value: NumberLiteral( - ExprNumberLiteral { - range: 81..82, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 93..97, - }, - ), - ], - }, - MatchCase { - range: 102..135, - pattern: MatchClass( - PatternMatchClass { - range: 107..121, - cls: Name( - ExprName { - range: 107..110, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 110..121, - patterns: [], - keywords: [ - PatternKeyword { - range: 111..120, - attr: Identifier { - id: "", - range: 118..118, - }, - pattern: MatchValue( - PatternMatchValue { - range: 119..120, - value: NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 131..135, - }, - ), - ], - }, - MatchCase { - range: 140..174, - pattern: MatchClass( - PatternMatchClass { - range: 145..160, - cls: Name( - ExprName { - range: 145..148, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 148..160, - patterns: [], - keywords: [ - PatternKeyword { - range: 149..159, - attr: Identifier { - id: "", - range: 157..157, - }, - pattern: MatchValue( - PatternMatchValue { - range: 158..159, - value: NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 170..174, - }, - ), - ], - }, - MatchCase { - range: 179..217, - pattern: MatchClass( - PatternMatchClass { - range: 184..203, - cls: Name( - ExprName { - range: 184..187, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 187..203, - patterns: [], - keywords: [ - PatternKeyword { - range: 188..202, - attr: Identifier { - id: "", - range: 200..200, - }, - pattern: MatchValue( - PatternMatchValue { - range: 201..202, - value: NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 213..217, - }, - ), - ], - }, - MatchCase { - range: 222..249, - pattern: MatchClass( - PatternMatchClass { - range: 227..235, - cls: Name( - ExprName { - range: 227..230, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 230..235, - patterns: [], - keywords: [ - PatternKeyword { - range: 231..234, - attr: Identifier { - id: "", - range: 233..233, - }, - pattern: MatchValue( - PatternMatchValue { - range: 233..234, - value: NumberLiteral( - ExprNumberLiteral { - range: 233..234, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 245..249, - }, - ), - ], - }, - MatchCase { - range: 254..285, - pattern: MatchClass( - PatternMatchClass { - range: 259..271, - cls: Name( - ExprName { - range: 259..262, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 262..271, - patterns: [], - keywords: [ - PatternKeyword { - range: 263..270, - attr: Identifier { - id: "", - range: 269..269, - }, - pattern: MatchValue( - PatternMatchValue { - range: 269..270, - value: NumberLiteral( - ExprNumberLiteral { - range: 269..270, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 281..285, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Invalid keyword pattern in class argument -2 | match subject: -3 | case Foo(x as y = 1): - | ^^^^^^ Syntax Error: Expected an identifier for the keyword pattern -4 | pass -5 | case Foo(x | y = 1): - | - - - | -3 | case Foo(x as y = 1): -4 | pass -5 | case Foo(x | y = 1): - | ^^^^^ Syntax Error: Expected an identifier for the keyword pattern -6 | pass -7 | case Foo([x, y] = 1): - | - - - | -5 | case Foo(x | y = 1): -6 | pass -7 | case Foo([x, y] = 1): - | ^^^^^^ Syntax Error: Expected an identifier for the keyword pattern -8 | pass -9 | case Foo({False: 0} = 1): - | - - - | - 7 | case Foo([x, y] = 1): - 8 | pass - 9 | case Foo({False: 0} = 1): - | ^^^^^^^^^^ Syntax Error: Expected an identifier for the keyword pattern -10 | pass -11 | case Foo(1=1): - | - - - | - 9 | case Foo({False: 0} = 1): -10 | pass -11 | case Foo(1=1): - | ^ Syntax Error: Expected an identifier for the keyword pattern -12 | pass -13 | case Foo(Bar()=1): - | - - - | -11 | case Foo(1=1): -12 | pass -13 | case Foo(Bar()=1): - | ^^^^^ Syntax Error: Expected an identifier for the keyword pattern -14 | pass -15 | # Positional pattern cannot follow keyword pattern - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap.new deleted file mode 100644 index faafb031f3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap.new +++ /dev/null @@ -1,1101 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid_lhs_or_rhs_pattern.py ---- -## AST - -``` -Module( - ModModule { - range: 0..695, - body: [ - Match( - StmtMatch { - range: 0..332, - subject: Name( - ExprName { - range: 6..25, - id: "invalid_lhs_pattern", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 31..60, - pattern: MatchValue( - PatternMatchValue { - range: 36..46, - value: BinOp( - ExprBinOp { - range: 36..46, - left: Call( - ExprCall { - range: 36..41, - func: Name( - ExprName { - range: 36..39, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 39..41, - args: [], - keywords: [], - }, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 44..46, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 56..60, - }, - ), - ], - }, - MatchCase { - range: 65..90, - pattern: MatchValue( - PatternMatchValue { - range: 70..76, - value: BinOp( - ExprBinOp { - range: 70..76, - left: Name( - ExprName { - range: 70..71, - id: "x", - ctx: Store, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 74..76, - value: Complex { - real: 0.0, - imag: 2.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 86..90, - }, - ), - ], - }, - MatchCase { - range: 95..120, - pattern: MatchValue( - PatternMatchValue { - range: 100..106, - value: BinOp( - ExprBinOp { - range: 100..106, - left: Name( - ExprName { - range: 100..101, - id: "_", - ctx: Store, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 104..106, - value: Complex { - real: 0.0, - imag: 3.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 116..120, - }, - ), - ], - }, - MatchCase { - range: 125..156, - pattern: MatchValue( - PatternMatchValue { - range: 130..142, - value: BinOp( - ExprBinOp { - range: 130..142, - left: BinOp( - ExprBinOp { - range: 131..136, - left: NumberLiteral( - ExprNumberLiteral { - range: 131..132, - value: Int( - 1, - ), - }, - ), - op: BitOr, - right: NumberLiteral( - ExprNumberLiteral { - range: 135..136, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 140..142, - value: Complex { - real: 0.0, - imag: 4.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 152..156, - }, - ), - ], - }, - MatchCase { - range: 161..191, - pattern: MatchValue( - PatternMatchValue { - range: 166..177, - value: BinOp( - ExprBinOp { - range: 166..177, - left: List( - ExprList { - range: 166..172, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 167..168, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 170..171, - value: Int( - 2, - ), - }, - ), - ], - ctx: Store, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 175..177, - value: Complex { - real: 0.0, - imag: 5.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 187..191, - }, - ), - ], - }, - MatchCase { - range: 196..229, - pattern: MatchValue( - PatternMatchValue { - range: 201..215, - value: BinOp( - ExprBinOp { - range: 201..215, - left: Dict( - ExprDict { - range: 201..210, - items: [ - DictItem { - key: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 202..206, - value: true, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 208..209, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 213..215, - value: Complex { - real: 0.0, - imag: 6.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 225..229, - }, - ), - ], - }, - MatchCase { - range: 234..260, - pattern: MatchValue( - PatternMatchValue { - range: 239..246, - value: BinOp( - ExprBinOp { - range: 239..246, - left: NumberLiteral( - ExprNumberLiteral { - range: 239..241, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 244..246, - value: Complex { - real: 0.0, - imag: 2.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 256..260, - }, - ), - ], - }, - MatchCase { - range: 265..292, - pattern: MatchValue( - PatternMatchValue { - range: 270..278, - value: BinOp( - ExprBinOp { - range: 270..278, - left: UnaryOp( - ExprUnaryOp { - range: 270..273, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 271..273, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 276..278, - value: Complex { - real: 0.0, - imag: 2.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 288..292, - }, - ), - ], - }, - MatchCase { - range: 297..332, - pattern: MatchValue( - PatternMatchValue { - range: 302..318, - value: BinOp( - ExprBinOp { - range: 302..318, - left: Call( - ExprCall { - range: 302..313, - func: Name( - ExprName { - range: 302..305, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 305..313, - args: [ - Name( - ExprName { - range: 306..312, - id: "", - ctx: Invalid, - }, - ), - ], - keywords: [], - }, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 316..318, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 328..332, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 334..625, - subject: Name( - ExprName { - range: 340..359, - id: "invalid_rhs_pattern", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 365..393, - pattern: MatchValue( - PatternMatchValue { - range: 370..379, - value: BinOp( - ExprBinOp { - range: 370..379, - left: NumberLiteral( - ExprNumberLiteral { - range: 370..371, - value: Int( - 1, - ), - }, - ), - op: Add, - right: Call( - ExprCall { - range: 374..379, - func: Name( - ExprName { - range: 374..377, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 377..379, - args: [], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 389..393, - }, - ), - ], - }, - MatchCase { - range: 398..422, - pattern: MatchValue( - PatternMatchValue { - range: 403..408, - value: BinOp( - ExprBinOp { - range: 403..408, - left: NumberLiteral( - ExprNumberLiteral { - range: 403..404, - value: Int( - 2, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 407..408, - id: "x", - ctx: Store, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 418..422, - }, - ), - ], - }, - MatchCase { - range: 427..451, - pattern: MatchValue( - PatternMatchValue { - range: 432..437, - value: BinOp( - ExprBinOp { - range: 432..437, - left: NumberLiteral( - ExprNumberLiteral { - range: 432..433, - value: Int( - 3, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 436..437, - id: "_", - ctx: Store, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 447..451, - }, - ), - ], - }, - MatchCase { - range: 456..486, - pattern: MatchValue( - PatternMatchValue { - range: 461..472, - value: BinOp( - ExprBinOp { - range: 461..472, - left: NumberLiteral( - ExprNumberLiteral { - range: 461..462, - value: Int( - 4, - ), - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 466..471, - left: NumberLiteral( - ExprNumberLiteral { - range: 466..467, - value: Int( - 1, - ), - }, - ), - op: BitOr, - right: NumberLiteral( - ExprNumberLiteral { - range: 470..471, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 482..486, - }, - ), - ], - }, - MatchCase { - range: 491..520, - pattern: MatchValue( - PatternMatchValue { - range: 496..506, - value: BinOp( - ExprBinOp { - range: 496..506, - left: NumberLiteral( - ExprNumberLiteral { - range: 496..497, - value: Int( - 5, - ), - }, - ), - op: Add, - right: List( - ExprList { - range: 500..506, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 501..502, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 504..505, - value: Int( - 2, - ), - }, - ), - ], - ctx: Store, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 516..520, - }, - ), - ], - }, - MatchCase { - range: 525..557, - pattern: MatchValue( - PatternMatchValue { - range: 530..543, - value: BinOp( - ExprBinOp { - range: 530..543, - left: NumberLiteral( - ExprNumberLiteral { - range: 530..531, - value: Int( - 6, - ), - }, - ), - op: Add, - right: Dict( - ExprDict { - range: 534..543, - items: [ - DictItem { - key: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 535..539, - value: true, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 541..542, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 553..557, - }, - ), - ], - }, - MatchCase { - range: 562..586, - pattern: MatchValue( - PatternMatchValue { - range: 567..572, - value: BinOp( - ExprBinOp { - range: 567..572, - left: NumberLiteral( - ExprNumberLiteral { - range: 567..568, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 571..572, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 582..586, - }, - ), - ], - }, - MatchCase { - range: 591..625, - pattern: MatchValue( - PatternMatchValue { - range: 596..611, - value: BinOp( - ExprBinOp { - range: 596..611, - left: NumberLiteral( - ExprNumberLiteral { - range: 596..597, - value: Int( - 1, - ), - }, - ), - op: Add, - right: Call( - ExprCall { - range: 600..611, - func: Name( - ExprName { - range: 600..603, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 603..611, - args: [ - Name( - ExprName { - range: 604..610, - id: "", - ctx: Invalid, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 621..625, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 627..694, - subject: Name( - ExprName { - range: 633..656, - id: "invalid_lhs_rhs_pattern", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 662..694, - pattern: MatchValue( - PatternMatchValue { - range: 667..680, - value: BinOp( - ExprBinOp { - range: 667..680, - left: Call( - ExprCall { - range: 667..672, - func: Name( - ExprName { - range: 667..670, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 670..672, - args: [], - keywords: [], - }, - }, - ), - op: Add, - right: Call( - ExprCall { - range: 675..680, - func: Name( - ExprName { - range: 675..678, - id: "Bar", - ctx: Load, - }, - ), - arguments: Arguments { - range: 678..680, - args: [], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 690..694, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | match invalid_lhs_pattern: -2 | case Foo() + 1j: - | ^^^^^ Syntax Error: Expected a real number in complex literal pattern -3 | pass -4 | case x + 2j: - | - - - | -2 | case Foo() + 1j: -3 | pass -4 | case x + 2j: - | ^ Syntax Error: Expected a real number in complex literal pattern -5 | pass -6 | case _ + 3j: - | - - - | -4 | case x + 2j: -5 | pass -6 | case _ + 3j: - | ^ Syntax Error: Expected a real number in complex literal pattern -7 | pass -8 | case (1 | 2) + 4j: - | - - - | - 6 | case _ + 3j: - 7 | pass - 8 | case (1 | 2) + 4j: - | ^^^^^ Syntax Error: Expected a real number in complex literal pattern - 9 | pass -10 | case [1, 2] + 5j: - | - - - | - 8 | case (1 | 2) + 4j: - 9 | pass -10 | case [1, 2] + 5j: - | ^^^^^^ Syntax Error: Expected a real number in complex literal pattern -11 | pass -12 | case {True: 1} + 6j: - | - - - | -10 | case [1, 2] + 5j: -11 | pass -12 | case {True: 1} + 6j: - | ^^^^^^^^^ Syntax Error: Expected a real number in complex literal pattern -13 | pass -14 | case 1j + 2j: - | - - - | -12 | case {True: 1} + 6j: -13 | pass -14 | case 1j + 2j: - | ^^ Syntax Error: Expected a real number in complex literal pattern -15 | pass -16 | case -1j + 2j: - | - - - | -14 | case 1j + 2j: -15 | pass -16 | case -1j + 2j: - | ^^^ Syntax Error: Expected a real number in complex literal pattern -17 | pass -18 | case Foo(a as b) + 1j: - | - - - | -16 | case -1j + 2j: -17 | pass -18 | case Foo(a as b) + 1j: - | ^^^^^^^^^^^ Syntax Error: Expected a real number in complex literal pattern -19 | pass - | - - - | -21 | match invalid_rhs_pattern: -22 | case 1 + Foo(): - | ^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -23 | pass -24 | case 2 + x: - | - - - | -22 | case 1 + Foo(): -23 | pass -24 | case 2 + x: - | ^ Syntax Error: Expected an imaginary number in complex literal pattern -25 | pass -26 | case 3 + _: - | - - - | -24 | case 2 + x: -25 | pass -26 | case 3 + _: - | ^ Syntax Error: Expected an imaginary number in complex literal pattern -27 | pass -28 | case 4 + (1 | 2): - | - - - | -26 | case 3 + _: -27 | pass -28 | case 4 + (1 | 2): - | ^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -29 | pass -30 | case 5 + [1, 2]: - | - - - | -28 | case 4 + (1 | 2): -29 | pass -30 | case 5 + [1, 2]: - | ^^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -31 | pass -32 | case 6 + {True: 1}: - | - - - | -30 | case 5 + [1, 2]: -31 | pass -32 | case 6 + {True: 1}: - | ^^^^^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -33 | pass -34 | case 1 + 2: - | - - - | -32 | case 6 + {True: 1}: -33 | pass -34 | case 1 + 2: - | ^ Syntax Error: Expected an imaginary number in complex literal pattern -35 | pass -36 | case 1 + Foo(a as b): - | - - - | -34 | case 1 + 2: -35 | pass -36 | case 1 + Foo(a as b): - | ^^^^^^^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -37 | pass - | - - - | -39 | match invalid_lhs_rhs_pattern: -40 | case Foo() + Bar(): - | ^^^^^ Syntax Error: Expected a real number in complex literal pattern -41 | pass - | - - - | -39 | match invalid_lhs_rhs_pattern: -40 | case Foo() + Bar(): - | ^^^^^ Syntax Error: Expected an imaginary number in complex literal pattern -41 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap.new deleted file mode 100644 index 02bb0c96c1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap.new +++ /dev/null @@ -1,581 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid_mapping_pattern.py ---- -## AST - -``` -Module( - ModModule { - range: 0..509, - body: [ - Match( - StmtMatch { - range: 61..209, - subject: Name( - ExprName { - range: 67..74, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 80..105, - pattern: MatchMapping( - PatternMatchMapping { - range: 85..91, - keys: [ - Starred( - ExprStarred { - range: 86..90, - value: Name( - ExprName { - range: 87..90, - id: "key", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 90..90, - value: Name( - ExprName { - range: 90..90, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 101..105, - }, - ), - ], - }, - MatchCase { - range: 110..138, - pattern: MatchMapping( - PatternMatchMapping { - range: 115..124, - keys: [ - Starred( - ExprStarred { - range: 116..120, - value: Name( - ExprName { - range: 117..120, - id: "key", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 122..123, - value: NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 134..138, - }, - ), - ], - }, - MatchCase { - range: 143..170, - pattern: MatchMapping( - PatternMatchMapping { - range: 148..156, - keys: [ - Starred( - ExprStarred { - range: 149..153, - value: Name( - ExprName { - range: 150..153, - id: "key", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 154..155, - value: NumberLiteral( - ExprNumberLiteral { - range: 154..155, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 166..170, - }, - ), - ], - }, - MatchCase { - range: 175..209, - pattern: MatchMapping( - PatternMatchMapping { - range: 180..195, - keys: [ - Starred( - ExprStarred { - range: 181..185, - value: Name( - ExprName { - range: 182..185, - id: "key", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - NoneLiteral( - ExprNoneLiteral { - range: 187..191, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 185..185, - value: Name( - ExprName { - range: 185..185, - id: "", - ctx: Invalid, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 193..194, - value: NumberLiteral( - ExprNumberLiteral { - range: 193..194, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 205..209, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 305..462, - subject: Name( - ExprName { - range: 311..318, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 324..360, - pattern: MatchMapping( - PatternMatchMapping { - range: 329..346, - keys: [ - NoneLiteral( - ExprNoneLiteral { - range: 338..342, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 344..345, - value: NumberLiteral( - ExprNumberLiteral { - range: 344..345, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: Some( - Identifier { - id: "rest", - range: 332..336, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 356..360, - }, - ), - ], - }, - MatchCase { - range: 365..411, - pattern: MatchMapping( - PatternMatchMapping { - range: 370..397, - keys: [ - NoneLiteral( - ExprNoneLiteral { - range: 389..393, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 395..396, - value: NumberLiteral( - ExprNumberLiteral { - range: 395..396, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: Some( - Identifier { - id: "rest2", - range: 382..387, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 407..411, - }, - ), - ], - }, - MatchCase { - range: 416..462, - pattern: MatchMapping( - PatternMatchMapping { - range: 421..448, - keys: [ - NoneLiteral( - ExprNoneLiteral { - range: 431..435, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 437..438, - value: NumberLiteral( - ExprNumberLiteral { - range: 437..438, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: Some( - Identifier { - id: "rest2", - range: 442..447, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 458..462, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 464..509, - subject: Name( - ExprName { - range: 470..477, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 483..509, - pattern: MatchMapping( - PatternMatchMapping { - range: 488..504, - keys: [ - Call( - ExprCall { - range: 489..500, - func: Name( - ExprName { - range: 489..492, - id: "Foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 492..500, - args: [ - Name( - ExprName { - range: 493..499, - id: "", - ctx: Invalid, - }, - ), - ], - keywords: [], - }, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 502..503, - value: NumberLiteral( - ExprNumberLiteral { - range: 502..503, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 506..509, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 506..509, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Starred expression is not allowed as a mapping pattern key -2 | match subject: -3 | case {*key}: - | ^^^^ Syntax Error: Star pattern cannot be used here -4 | pass -5 | case {*key: 1}: - | - - - | -1 | # Starred expression is not allowed as a mapping pattern key -2 | match subject: -3 | case {*key}: - | ^ Syntax Error: Expected ':', found '}' -4 | pass -5 | case {*key: 1}: - | - - - | -3 | case {*key}: -4 | pass -5 | case {*key: 1}: - | ^^^^ Syntax Error: Star pattern cannot be used here -6 | pass -7 | case {*key 1}: - | - - - | -5 | case {*key: 1}: -6 | pass -7 | case {*key 1}: - | ^^^^ Syntax Error: Star pattern cannot be used here -8 | pass -9 | case {*key, None: 1}: - | - - - | -5 | case {*key: 1}: -6 | pass -7 | case {*key 1}: - | ^ Syntax Error: Expected ':', found int -8 | pass -9 | case {*key, None: 1}: - | - - - | - 7 | case {*key 1}: - 8 | pass - 9 | case {*key, None: 1}: - | ^^^^ Syntax Error: Star pattern cannot be used here -10 | pass - | - - - | - 7 | case {*key 1}: - 8 | pass - 9 | case {*key, None: 1}: - | ^ Syntax Error: Expected ':', found ',' -10 | pass - | - - - | -13 | # Multiple double star patterns are not allowed -14 | match subject: -15 | case {**rest, None: 1}: - | ^^^^^^^ Syntax Error: Pattern cannot follow a double star pattern -16 | pass -17 | case {**rest1, **rest2, None: 1}: - | - - - | -15 | case {**rest, None: 1}: -16 | pass -17 | case {**rest1, **rest2, None: 1}: - | ^^^^^^^ Syntax Error: Only one double star pattern is allowed -18 | pass -19 | case {**rest1, None: 1, **rest2}: - | - - - | -15 | case {**rest, None: 1}: -16 | pass -17 | case {**rest1, **rest2, None: 1}: - | ^^^^^^^ Syntax Error: Pattern cannot follow a double star pattern -18 | pass -19 | case {**rest1, None: 1, **rest2}: - | - - - | -17 | case {**rest1, **rest2, None: 1}: -18 | pass -19 | case {**rest1, None: 1, **rest2}: - | ^^^^^^^ Syntax Error: Pattern cannot follow a double star pattern -20 | pass - | - - - | -17 | case {**rest1, **rest2, None: 1}: -18 | pass -19 | case {**rest1, None: 1, **rest2}: - | ^^^^^^^ Syntax Error: Only one double star pattern is allowed -20 | pass - | - - - | -22 | match subject: -23 | case {Foo(a as b): 1}: ... - | ^^^^^^^^^^^ Syntax Error: Invalid mapping pattern key - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap.new deleted file mode 100644 index ec0973e443..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap.new +++ /dev/null @@ -1,547 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/star_pattern_usage.py ---- -## AST - -``` -Module( - ModModule { - range: 0..408, - body: [ - Match( - StmtMatch { - range: 57..407, - subject: Name( - ExprName { - range: 63..70, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 76..97, - pattern: MatchStar( - PatternMatchStar { - range: 81..83, - name: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 93..97, - }, - ), - ], - }, - MatchCase { - range: 102..128, - pattern: MatchAs( - PatternMatchAs { - range: 107..114, - pattern: Some( - MatchStar( - PatternMatchStar { - range: 107..109, - name: None, - }, - ), - ), - name: Some( - Identifier { - id: "x", - range: 113..114, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 124..128, - }, - ), - ], - }, - MatchCase { - range: 133..156, - pattern: MatchStar( - PatternMatchStar { - range: 138..142, - name: Some( - Identifier { - id: "foo", - range: 139..142, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 152..156, - }, - ), - ], - }, - MatchCase { - range: 161..188, - pattern: MatchOr( - PatternMatchOr { - range: 166..174, - patterns: [ - MatchStar( - PatternMatchStar { - range: 166..170, - name: Some( - Identifier { - id: "foo", - range: 167..170, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 173..174, - value: NumberLiteral( - ExprNumberLiteral { - range: 173..174, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 184..188, - }, - ), - ], - }, - MatchCase { - range: 193..220, - pattern: MatchOr( - PatternMatchOr { - range: 198..206, - patterns: [ - MatchValue( - PatternMatchValue { - range: 198..199, - value: NumberLiteral( - ExprNumberLiteral { - range: 198..199, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 202..206, - name: Some( - Identifier { - id: "foo", - range: 203..206, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 216..220, - }, - ), - ], - }, - MatchCase { - range: 225..251, - pattern: MatchClass( - PatternMatchClass { - range: 230..237, - cls: Name( - ExprName { - range: 230..233, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 233..237, - patterns: [ - MatchStar( - PatternMatchStar { - range: 234..236, - name: None, - }, - ), - ], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 247..251, - }, - ), - ], - }, - MatchCase { - range: 256..284, - pattern: MatchClass( - PatternMatchClass { - range: 261..270, - cls: Name( - ExprName { - range: 261..264, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 264..270, - patterns: [], - keywords: [ - PatternKeyword { - range: 265..269, - attr: Identifier { - id: "x", - range: 265..266, - }, - pattern: MatchStar( - PatternMatchStar { - range: 267..269, - name: None, - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 280..284, - }, - ), - ], - }, - MatchCase { - range: 289..312, - pattern: MatchMapping( - PatternMatchMapping { - range: 294..298, - keys: [ - Starred( - ExprStarred { - range: 295..297, - value: Name( - ExprName { - range: 296..297, - id: "_", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 297..297, - value: Name( - ExprName { - range: 297..297, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 308..312, - }, - ), - ], - }, - MatchCase { - range: 317..343, - pattern: MatchMapping( - PatternMatchMapping { - range: 322..329, - keys: [ - Starred( - ExprStarred { - range: 323..325, - value: Name( - ExprName { - range: 324..325, - id: "_", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 327..328, - value: NumberLiteral( - ExprNumberLiteral { - range: 327..328, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 339..343, - }, - ), - ], - }, - MatchCase { - range: 348..377, - pattern: MatchMapping( - PatternMatchMapping { - range: 353..363, - keys: [ - NoneLiteral( - ExprNoneLiteral { - range: 354..358, - }, - ), - ], - patterns: [ - MatchStar( - PatternMatchStar { - range: 360..362, - name: None, - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 373..377, - }, - ), - ], - }, - MatchCase { - range: 382..407, - pattern: MatchValue( - PatternMatchValue { - range: 387..393, - value: BinOp( - ExprBinOp { - range: 387..393, - left: NumberLiteral( - ExprNumberLiteral { - range: 387..388, - value: Int( - 1, - ), - }, - ), - op: Add, - right: Starred( - ExprStarred { - range: 391..393, - value: Name( - ExprName { - range: 392..393, - id: "_", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 403..407, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Star pattern is only allowed inside a sequence pattern -2 | match subject: -3 | case *_: - | ^^ Syntax Error: Star pattern cannot be used here -4 | pass -5 | case *_ as x: - | - - - | -3 | case *_: -4 | pass -5 | case *_ as x: - | ^^ Syntax Error: Star pattern cannot be used here -6 | pass -7 | case *foo: - | - - - | -5 | case *_ as x: -6 | pass -7 | case *foo: - | ^^^^ Syntax Error: Star pattern cannot be used here -8 | pass -9 | case *foo | 1: - | - - - | - 7 | case *foo: - 8 | pass - 9 | case *foo | 1: - | ^^^^ Syntax Error: Star pattern cannot be used here -10 | pass -11 | case 1 | *foo: - | - - - | - 9 | case *foo | 1: -10 | pass -11 | case 1 | *foo: - | ^^^^ Syntax Error: Star pattern cannot be used here -12 | pass -13 | case Foo(*_): - | - - - | -11 | case 1 | *foo: -12 | pass -13 | case Foo(*_): - | ^^ Syntax Error: Star pattern cannot be used here -14 | pass -15 | case Foo(x=*_): - | - - - | -13 | case Foo(*_): -14 | pass -15 | case Foo(x=*_): - | ^^ Syntax Error: Star pattern cannot be used here -16 | pass -17 | case {*_}: - | - - - | -15 | case Foo(x=*_): -16 | pass -17 | case {*_}: - | ^^ Syntax Error: Star pattern cannot be used here -18 | pass -19 | case {*_: 1}: - | - - - | -15 | case Foo(x=*_): -16 | pass -17 | case {*_}: - | ^ Syntax Error: Expected ':', found '}' -18 | pass -19 | case {*_: 1}: - | - - - | -17 | case {*_}: -18 | pass -19 | case {*_: 1}: - | ^^ Syntax Error: Star pattern cannot be used here -20 | pass -21 | case {None: *_}: - | - - - | -19 | case {*_: 1}: -20 | pass -21 | case {None: *_}: - | ^^ Syntax Error: Star pattern cannot be used here -22 | pass -23 | case 1 + *_: - | - - - | -21 | case {None: *_}: -22 | pass -23 | case 1 + *_: - | ^^ Syntax Error: Star pattern cannot be used here -24 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap.new deleted file mode 100644 index f3bf2bc4e3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap.new +++ /dev/null @@ -1,399 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/match/unary_add_usage.py ---- -## AST - -``` -Module( - ModModule { - range: 0..269, - body: [ - Match( - StmtMatch { - range: 74..268, - subject: Name( - ExprName { - range: 80..87, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 93..114, - pattern: MatchValue( - PatternMatchValue { - range: 98..100, - value: UnaryOp( - ExprUnaryOp { - range: 98..100, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 99..100, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 110..114, - }, - ), - ], - }, - MatchCase { - range: 119..149, - pattern: MatchOr( - PatternMatchOr { - range: 124..135, - patterns: [ - MatchValue( - PatternMatchValue { - range: 124..125, - value: NumberLiteral( - ExprNumberLiteral { - range: 124..125, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 128..130, - value: UnaryOp( - ExprUnaryOp { - range: 128..130, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 129..130, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 133..135, - value: UnaryOp( - ExprUnaryOp { - range: 133..135, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 134..135, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 145..149, - }, - ), - ], - }, - MatchCase { - range: 154..184, - pattern: MatchSequence( - PatternMatchSequence { - range: 159..170, - patterns: [ - MatchValue( - PatternMatchValue { - range: 160..161, - value: NumberLiteral( - ExprNumberLiteral { - range: 160..161, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 163..165, - value: UnaryOp( - ExprUnaryOp { - range: 163..165, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 164..165, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 167..169, - value: UnaryOp( - ExprUnaryOp { - range: 167..169, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 168..169, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 180..184, - }, - ), - ], - }, - MatchCase { - range: 189..223, - pattern: MatchClass( - PatternMatchClass { - range: 194..209, - cls: Name( - ExprName { - range: 194..197, - id: "Foo", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 197..209, - patterns: [], - keywords: [ - PatternKeyword { - range: 198..202, - attr: Identifier { - id: "x", - range: 198..199, - }, - pattern: MatchValue( - PatternMatchValue { - range: 200..202, - value: UnaryOp( - ExprUnaryOp { - range: 200..202, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - PatternKeyword { - range: 204..208, - attr: Identifier { - id: "y", - range: 204..205, - }, - pattern: MatchValue( - PatternMatchValue { - range: 206..208, - value: UnaryOp( - ExprUnaryOp { - range: 206..208, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 207..208, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 219..223, - }, - ), - ], - }, - MatchCase { - range: 228..268, - pattern: MatchMapping( - PatternMatchMapping { - range: 233..254, - keys: [ - BooleanLiteral( - ExprBooleanLiteral { - range: 234..238, - value: true, - }, - ), - BooleanLiteral( - ExprBooleanLiteral { - range: 244..249, - value: false, - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 240..242, - value: UnaryOp( - ExprUnaryOp { - range: 240..242, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 241..242, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 251..253, - value: UnaryOp( - ExprUnaryOp { - range: 251..253, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 252..253, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 264..268, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # Unary addition isn't allowed but we parse it for better error recovery. -2 | match subject: -3 | case +1: - | ^^ Syntax Error: Unary '+' is not allowed as a literal pattern -4 | pass -5 | case 1 | +2 | -3: - | - - - | -3 | case +1: -4 | pass -5 | case 1 | +2 | -3: - | ^^ Syntax Error: Unary '+' is not allowed as a literal pattern -6 | pass -7 | case [1, +2, -3]: - | - - - | -5 | case 1 | +2 | -3: -6 | pass -7 | case [1, +2, -3]: - | ^^ Syntax Error: Unary '+' is not allowed as a literal pattern -8 | pass -9 | case Foo(x=+1, y=-2): - | - - - | - 7 | case [1, +2, -3]: - 8 | pass - 9 | case Foo(x=+1, y=-2): - | ^^ Syntax Error: Unary '+' is not allowed as a literal pattern -10 | pass -11 | case {True: +1, False: -2}: - | - - - | - 9 | case Foo(x=+1, y=-2): -10 | pass -11 | case {True: +1, False: -2}: - | ^^ Syntax Error: Unary '+' is not allowed as a literal pattern -12 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap.new deleted file mode 100644 index e4eb831ef2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap.new +++ /dev/null @@ -1,1675 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/with/ambiguous_lpar_with_items.py ---- -## AST - -``` -Module( - ModModule { - range: 0..950, - body: [ - With( - StmtWith { - range: 163..188, - is_async: false, - items: [ - WithItem { - range: 168..182, - context_expr: Tuple( - ExprTuple { - range: 168..182, - elts: [ - Name( - ExprName { - range: 169..174, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 176..181, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 185..188, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 185..188, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 189..219, - is_async: false, - items: [ - WithItem { - range: 194..208, - context_expr: Tuple( - ExprTuple { - range: 194..208, - elts: [ - Name( - ExprName { - range: 195..200, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 202..207, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 213..214, - context_expr: Name( - ExprName { - range: 213..214, - id: "f", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 216..219, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 216..219, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 220..252, - is_async: false, - items: [ - WithItem { - range: 225..239, - context_expr: Tuple( - ExprTuple { - range: 225..239, - elts: [ - Name( - ExprName { - range: 226..231, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 233..238, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 241..246, - context_expr: Name( - ExprName { - range: 241..246, - id: "item3", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 249..252, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 249..252, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 253..270, - is_async: false, - items: [ - WithItem { - range: 258..265, - context_expr: Starred( - ExprStarred { - range: 259..264, - value: Name( - ExprName { - range: 260..264, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 267..270, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 267..270, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 271..293, - is_async: false, - items: [ - WithItem { - range: 276..288, - context_expr: Starred( - ExprStarred { - range: 277..282, - value: Name( - ExprName { - range: 278..282, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 287..288, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 290..293, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 290..293, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 294..321, - is_async: false, - items: [ - WithItem { - range: 300..315, - context_expr: Named( - ExprNamed { - range: 300..310, - target: Name( - ExprName { - range: 300..304, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 308..310, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 314..315, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 318..321, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 318..321, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 322..357, - is_async: false, - items: [ - WithItem { - range: 328..333, - context_expr: Name( - ExprName { - range: 328..333, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 335..351, - context_expr: Named( - ExprNamed { - range: 335..346, - target: Name( - ExprName { - range: 335..340, - id: "item2", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 344..346, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 350..351, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 354..357, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 354..357, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 358..396, - is_async: false, - items: [ - WithItem { - range: 363..384, - context_expr: Generator( - ExprGenerator { - range: 363..384, - elt: Name( - ExprName { - range: 364..365, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 366..384, - target: Name( - ExprName { - range: 370..371, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 375..384, - func: Name( - ExprName { - range: 375..380, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 380..384, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 381..383, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 386..390, - context_expr: Name( - ExprName { - range: 386..390, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 393..396, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 393..396, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 397..410, - is_async: false, - items: [ - WithItem { - range: 402..410, - context_expr: Tuple( - ExprTuple { - range: 402..410, - elts: [ - Name( - ExprName { - range: 403..407, - id: "item", - ctx: Load, - }, - ), - Name( - ExprName { - range: 409..410, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [], - }, - ), - For( - StmtFor { - range: 411..429, - is_async: false, - target: Name( - ExprName { - range: 415..416, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 420..429, - func: Name( - ExprName { - range: 420..425, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 425..429, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 426..428, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - body: [], - orelse: [], - }, - ), - Expr( - StmtExpr { - range: 432..435, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 432..435, - }, - ), - }, - ), - With( - StmtWith { - range: 496..515, - is_async: false, - items: [ - WithItem { - range: 502..509, - context_expr: Starred( - ExprStarred { - range: 503..508, - value: Name( - ExprName { - range: 504..508, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 512..515, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 512..515, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 517..551, - is_async: false, - items: [ - WithItem { - range: 522..539, - context_expr: Generator( - ExprGenerator { - range: 522..539, - elt: Starred( - ExprStarred { - range: 523..525, - value: Name( - ExprName { - range: 524..525, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 526..539, - target: Name( - ExprName { - range: 530..531, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 535..539, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 541..545, - context_expr: Name( - ExprName { - range: 541..545, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 548..551, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 548..551, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 552..567, - is_async: false, - items: [ - WithItem { - range: 557..567, - context_expr: Tuple( - ExprTuple { - range: 557..567, - elts: [ - Name( - ExprName { - range: 558..563, - id: "item1", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 565..567, - value: Name( - ExprName { - range: 566..567, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [], - }, - ), - For( - StmtFor { - range: 568..588, - is_async: false, - target: Name( - ExprName { - range: 572..573, - id: "x", - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 577..588, - elts: [ - Name( - ExprName { - range: 577..581, - id: "iter", - ctx: Load, - }, - ), - Name( - ExprName { - range: 583..588, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - body: [], - orelse: [], - }, - ), - Expr( - StmtExpr { - range: 591..594, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 591..594, - }, - ), - }, - ), - With( - StmtWith { - range: 595..617, - is_async: false, - items: [ - WithItem { - range: 601..607, - context_expr: Name( - ExprName { - range: 601..602, - id: "x", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 606..607, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 609..611, - context_expr: Starred( - ExprStarred { - range: 609..611, - value: Name( - ExprName { - range: 610..611, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 614..617, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 614..617, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 618..640, - is_async: false, - items: [ - WithItem { - range: 624..626, - context_expr: Starred( - ExprStarred { - range: 624..626, - value: Name( - ExprName { - range: 625..626, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 628..634, - context_expr: Name( - ExprName { - range: 628..629, - id: "y", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 633..634, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 637..640, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 637..640, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 641..663, - is_async: false, - items: [ - WithItem { - range: 646..658, - context_expr: Tuple( - ExprTuple { - range: 646..658, - elts: [ - Name( - ExprName { - range: 647..648, - id: "x", - ctx: Load, - }, - ), - Yield( - ExprYield { - range: 650..657, - value: Some( - Name( - ExprName { - range: 656..657, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 660..663, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 660..663, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 664..689, - is_async: false, - items: [ - WithItem { - range: 669..684, - context_expr: Tuple( - ExprTuple { - range: 669..684, - elts: [ - Name( - ExprName { - range: 670..671, - id: "x", - ctx: Load, - }, - ), - Yield( - ExprYield { - range: 673..683, - value: Some( - Tuple( - ExprTuple { - range: 679..683, - elts: [ - Name( - ExprName { - range: 679..680, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 682..683, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 686..689, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 686..689, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 690..717, - is_async: false, - items: [ - WithItem { - range: 695..712, - context_expr: Tuple( - ExprTuple { - range: 695..712, - elts: [ - Name( - ExprName { - range: 696..697, - id: "x", - ctx: Load, - }, - ), - YieldFrom( - ExprYieldFrom { - range: 699..711, - value: Name( - ExprName { - range: 710..711, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 714..717, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 714..717, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 718..734, - is_async: false, - items: [ - WithItem { - range: 724..730, - context_expr: Name( - ExprName { - range: 724..725, - id: "x", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 729..730, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 732..733, - context_expr: Name( - ExprName { - range: 732..733, - id: "y", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 738..744, - target: Name( - ExprName { - range: 738..739, - id: "f", - ctx: Store, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 741..744, - }, - ), - value: None, - simple: true, - }, - ), - With( - StmtWith { - range: 745..777, - is_async: false, - items: [ - WithItem { - range: 750..771, - context_expr: Generator( - ExprGenerator { - range: 750..766, - elt: Name( - ExprName { - range: 751..752, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 753..766, - target: Name( - ExprName { - range: 757..758, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 762..766, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 770..771, - id: "y", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 774..777, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 774..777, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 837..854, - is_async: false, - items: [ - WithItem { - range: 843..853, - context_expr: Name( - ExprName { - range: 844..848, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 852..853, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [], - }, - ), - Expr( - StmtExpr { - range: 857..860, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 857..860, - }, - ), - }, - ), - With( - StmtWith { - range: 862..878, - is_async: false, - items: [ - WithItem { - range: 868..877, - context_expr: Name( - ExprName { - range: 868..872, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 876..877, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 880..886, - target: Name( - ExprName { - range: 880..881, - id: "x", - ctx: Store, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 883..886, - }, - ), - value: None, - simple: true, - }, - ), - With( - StmtWith { - range: 887..904, - is_async: false, - items: [ - WithItem { - range: 893..903, - context_expr: Name( - ExprName { - range: 893..897, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 901..903, - id: "f1", - ctx: Store, - }, - ), - ), - }, - ], - body: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 908..915, - target: Name( - ExprName { - range: 908..910, - id: "f2", - ctx: Store, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 912..915, - }, - ), - value: None, - simple: true, - }, - ), - With( - StmtWith { - range: 916..950, - is_async: false, - items: [ - WithItem { - range: 922..932, - context_expr: Name( - ExprName { - range: 922..927, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 931..932, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 934..944, - context_expr: Named( - ExprNamed { - range: 934..944, - target: Name( - ExprName { - range: 934..939, - id: "item2", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 943..944, - value: Int( - 0, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 947..950, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 947..950, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # These cases should raise the correct syntax error and recover properly. -3 | -4 | with (item1, item2),: ... - | ^ Syntax Error: Trailing comma not allowed -5 | with (item1, item2), as f: ... -6 | with (item1, item2), item3,: ... - | - - - | -4 | with (item1, item2),: ... -5 | with (item1, item2), as f: ... - | ^^ Syntax Error: Expected ',', found 'as' -6 | with (item1, item2), item3,: ... -7 | with (*item): ... - | - - - | -4 | with (item1, item2),: ... -5 | with (item1, item2), as f: ... -6 | with (item1, item2), item3,: ... - | ^ Syntax Error: Trailing comma not allowed -7 | with (*item): ... -8 | with (*item) as f: ... - | - - - | -5 | with (item1, item2), as f: ... -6 | with (item1, item2), item3,: ... -7 | with (*item): ... - | ^^^^^ Syntax Error: Starred expression cannot be used here -8 | with (*item) as f: ... -9 | with (item := 10 as f): ... - | - - - | - 6 | with (item1, item2), item3,: ... - 7 | with (*item): ... - 8 | with (*item) as f: ... - | ^^^^^ Syntax Error: Starred expression cannot be used here - 9 | with (item := 10 as f): ... -10 | with (item1, item2 := 10 as f): ... - | - - - | - 7 | with (*item): ... - 8 | with (*item) as f: ... - 9 | with (item := 10 as f): ... - | ^^^^^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... - | - - - | - 8 | with (*item) as f: ... - 9 | with (item := 10 as f): ... -10 | with (item1, item2 := 10 as f): ... - | ^^^^^^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here -11 | with (x for x in range(10), item): ... -12 | with (item, x for x in range(10)): ... - | - - - | - 9 | with (item := 10 as f): ... -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... - | ^ Syntax Error: Expected ')', found ',' -12 | with (item, x for x in range(10)): ... - | - - - | - 9 | with (item := 10 as f): ... -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... - | ^ Syntax Error: Expected ',', found ')' -12 | with (item, x for x in range(10)): ... - | - - - | -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... -12 | with (item, x for x in range(10)): ... - | ^^^ Syntax Error: Expected ')', found 'for' -13 | -14 | # Make sure the parser doesn't report the same error twice - | - - - | -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... -12 | with (item, x for x in range(10)): ... - | ^ Syntax Error: Expected ':', found ')' -13 | -14 | # Make sure the parser doesn't report the same error twice - | - - - | -10 | with (item1, item2 := 10 as f): ... -11 | with (x for x in range(10), item): ... -12 | with (item, x for x in range(10)): ... - | ^ Syntax Error: Expected a statement -13 | -14 | # Make sure the parser doesn't report the same error twice - | - - - | -14 | # Make sure the parser doesn't report the same error twice -15 | with ((*item)): ... - | ^^^^^ Syntax Error: Starred expression cannot be used here -16 | -17 | with (*x for x in iter, item): ... - | - - - | -15 | with ((*item)): ... -16 | -17 | with (*x for x in iter, item): ... - | ^^ Syntax Error: Iterable unpacking cannot be used in a comprehension -18 | with (item1, *x for x in iter, item2): ... -19 | with (x as f, *y): ... - | - - - | -15 | with ((*item)): ... -16 | -17 | with (*x for x in iter, item): ... - | ^ Syntax Error: Expected ')', found ',' -18 | with (item1, *x for x in iter, item2): ... -19 | with (x as f, *y): ... - | - - - | -15 | with ((*item)): ... -16 | -17 | with (*x for x in iter, item): ... - | ^ Syntax Error: Expected ',', found ')' -18 | with (item1, *x for x in iter, item2): ... -19 | with (x as f, *y): ... - | - - - | -17 | with (*x for x in iter, item): ... -18 | with (item1, *x for x in iter, item2): ... - | ^^^ Syntax Error: Expected ')', found 'for' -19 | with (x as f, *y): ... -20 | with (*x, y as f): ... - | - - - | -17 | with (*x for x in iter, item): ... -18 | with (item1, *x for x in iter, item2): ... - | ^ Syntax Error: Expected ':', found ')' -19 | with (x as f, *y): ... -20 | with (*x, y as f): ... - | - - - | -17 | with (*x for x in iter, item): ... -18 | with (item1, *x for x in iter, item2): ... - | ^ Syntax Error: Expected a statement -19 | with (x as f, *y): ... -20 | with (*x, y as f): ... - | - - - | -17 | with (*x for x in iter, item): ... -18 | with (item1, *x for x in iter, item2): ... -19 | with (x as f, *y): ... - | ^^ Syntax Error: Starred expression cannot be used here -20 | with (*x, y as f): ... -21 | with (x, yield y): ... - | - - - | -18 | with (item1, *x for x in iter, item2): ... -19 | with (x as f, *y): ... -20 | with (*x, y as f): ... - | ^^ Syntax Error: Starred expression cannot be used here -21 | with (x, yield y): ... -22 | with (x, yield y, z): ... - | - - - | -19 | with (x as f, *y): ... -20 | with (*x, y as f): ... -21 | with (x, yield y): ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -22 | with (x, yield y, z): ... -23 | with (x, yield from y): ... - | - - - | -20 | with (*x, y as f): ... -21 | with (x, yield y): ... -22 | with (x, yield y, z): ... - | ^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -23 | with (x, yield from y): ... -24 | with (x as f, y) as f: ... - | - - - | -21 | with (x, yield y): ... -22 | with (x, yield y, z): ... -23 | with (x, yield from y): ... - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -24 | with (x as f, y) as f: ... -25 | with (x for x in iter as y): ... - | - - - | -22 | with (x, yield y, z): ... -23 | with (x, yield from y): ... -24 | with (x as f, y) as f: ... - | ^^ Syntax Error: Expected ':', found 'as' -25 | with (x for x in iter as y): ... - | - - - | -23 | with (x, yield from y): ... -24 | with (x as f, y) as f: ... -25 | with (x for x in iter as y): ... - | ^^ Syntax Error: Expected ')', found 'as' -26 | -27 | # The inner `(...)` is parsed as parenthesized expression - | - - - | -23 | with (x, yield from y): ... -24 | with (x as f, y) as f: ... -25 | with (x for x in iter as y): ... - | ^ Syntax Error: Expected ',', found ')' -26 | -27 | # The inner `(...)` is parsed as parenthesized expression - | - - - | -27 | # The inner `(...)` is parsed as parenthesized expression -28 | with ((item as f)): ... - | ^^ Syntax Error: Expected ')', found 'as' -29 | -30 | with (item as f), x: ... - | - - - | -27 | # The inner `(...)` is parsed as parenthesized expression -28 | with ((item as f)): ... - | ^ Syntax Error: Expected ':', found ')' -29 | -30 | with (item as f), x: ... - | - - - | -27 | # The inner `(...)` is parsed as parenthesized expression -28 | with ((item as f)): ... - | ^ Syntax Error: Expected a statement -29 | -30 | with (item as f), x: ... - | - - - | -28 | with ((item as f)): ... -29 | -30 | with (item as f), x: ... - | ^ Syntax Error: Expected ':', found ',' -31 | with (item as f1) as f2: ... -32 | with (item1 as f, item2 := 0): ... - | - - - | -30 | with (item as f), x: ... -31 | with (item as f1) as f2: ... - | ^^ Syntax Error: Expected ':', found 'as' -32 | with (item1 as f, item2 := 0): ... - | - - - | -30 | with (item as f), x: ... -31 | with (item as f1) as f2: ... -32 | with (item1 as f, item2 := 0): ... - | ^^^^^^^^^^ Syntax Error: Unparenthesized named expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap.new deleted file mode 100644 index d67e218d29..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap.new +++ /dev/null @@ -1,70 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/with/empty_with_items.py ---- -## AST - -``` -Module( - ModModule { - range: 0..105, - body: [ - With( - StmtWith { - range: 88..98, - is_async: false, - items: [], - body: [ - Expr( - StmtExpr { - range: 95..98, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 95..98, - }, - ), - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 100..105, - value: BinOp( - ExprBinOp { - range: 100..105, - left: Name( - ExprName { - range: 100..101, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 104..105, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -2 | # The parser should recover from this syntax error. -3 | -4 | with : ... - | ^ Syntax Error: Expected the start of an expression after `with` keyword -5 | -6 | x + y - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap.new deleted file mode 100644 index 5cafa4ff69..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap.new +++ /dev/null @@ -1,78 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/with/unclosed_ambiguous_lpar.py ---- -## AST - -``` -Module( - ModModule { - range: 0..14, - body: [ - With( - StmtWith { - range: 0..14, - is_async: false, - items: [ - WithItem { - range: 5..6, - context_expr: Name( - ExprName { - range: 6..6, - id: "", - ctx: Invalid, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 9..14, - value: BinOp( - ExprBinOp { - range: 9..14, - left: Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 13..14, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | with (: - | ^ Syntax Error: Expected an expression -2 | -3 | x + y - | - - - | -1 | with (: -2 | -3 | x + y - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap.new deleted file mode 100644 index 924c11a959..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap.new +++ /dev/null @@ -1,42 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/with/unclosed_ambiguous_lpar_eof.py ---- -## AST - -``` -Module( - ModModule { - range: 0..6, - body: [ - With( - StmtWith { - range: 0..6, - is_async: false, - items: [ - WithItem { - range: 5..6, - context_expr: Name( - ExprName { - range: 6..6, - id: "", - ctx: Invalid, - }, - ), - optional_vars: None, - }, - ], - body: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | with ( - | Syntax Error: unexpected EOF while parsing - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap.new deleted file mode 100644 index 6d13719da7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap.new +++ /dev/null @@ -1,362 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/invalid/statements/with/unparenthesized_with_items.py ---- -## AST - -``` -Module( - ModModule { - range: 0..249, - body: [ - With( - StmtWith { - range: 86..102, - is_async: false, - items: [ - WithItem { - range: 91..95, - context_expr: Name( - ExprName { - range: 91..95, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 98..102, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 103..124, - is_async: false, - items: [ - WithItem { - range: 108..117, - context_expr: Name( - ExprName { - range: 108..112, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 116..117, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 120..124, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 125..141, - is_async: false, - items: [ - WithItem { - range: 130..135, - context_expr: Starred( - ExprStarred { - range: 130..135, - value: Name( - ExprName { - range: 131..135, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 137..141, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 142..163, - is_async: false, - items: [ - WithItem { - range: 147..157, - context_expr: Starred( - ExprStarred { - range: 147..152, - value: Name( - ExprName { - range: 148..152, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 156..157, - id: "x", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 159..163, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 164..193, - is_async: false, - items: [ - WithItem { - range: 169..175, - context_expr: Starred( - ExprStarred { - range: 169..175, - value: Name( - ExprName { - range: 170..175, - id: "item1", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 177..187, - context_expr: Name( - ExprName { - range: 177..182, - id: "item2", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 186..187, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 189..193, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 194..223, - is_async: false, - items: [ - WithItem { - range: 199..209, - context_expr: Name( - ExprName { - range: 199..204, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 208..209, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 211..217, - context_expr: Starred( - ExprStarred { - range: 211..217, - value: Name( - ExprName { - range: 212..217, - id: "item2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 219..223, - }, - ), - ], - }, - ), - With( - StmtWith { - range: 224..249, - is_async: false, - items: [ - WithItem { - range: 229..233, - context_expr: Name( - ExprName { - range: 229..233, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 237..243, - context_expr: NumberLiteral( - ExprNumberLiteral { - range: 237..238, - value: Int( - 0, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 242..243, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Pass( - StmtPass { - range: 245..249, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # For parenthesized with items test cases, refer to `./ambiguous_lpar_with_items.py` -2 | -3 | with item,: pass - | ^ Syntax Error: Trailing comma not allowed -4 | with item as x,: pass -5 | with *item: pass - | - - - | -3 | with item,: pass -4 | with item as x,: pass - | ^ Syntax Error: Trailing comma not allowed -5 | with *item: pass -6 | with *item as x: pass - | - - - | -3 | with item,: pass -4 | with item as x,: pass -5 | with *item: pass - | ^^^^^ Syntax Error: Starred expression cannot be used here -6 | with *item as x: pass -7 | with *item1, item2 as f: pass - | - - - | -4 | with item as x,: pass -5 | with *item: pass -6 | with *item as x: pass - | ^^^^^ Syntax Error: Starred expression cannot be used here -7 | with *item1, item2 as f: pass -8 | with item1 as f, *item2: pass - | - - - | -5 | with *item: pass -6 | with *item as x: pass -7 | with *item1, item2 as f: pass - | ^^^^^^ Syntax Error: Starred expression cannot be used here -8 | with item1 as f, *item2: pass -9 | with item := 0 as f: pass - | - - - | -6 | with *item as x: pass -7 | with *item1, item2 as f: pass -8 | with item1 as f, *item2: pass - | ^^^^^^ Syntax Error: Starred expression cannot be used here -9 | with item := 0 as f: pass - | - - - | -7 | with *item1, item2 as f: pass -8 | with item1 as f, *item2: pass -9 | with item := 0 as f: pass - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap.new deleted file mode 100644 index 635b7c558f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap.new +++ /dev/null @@ -1,273 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/try_stmt_misspelled_except.py ---- -## AST - -``` -Module( - ModModule { - range: 0..165, - body: [ - Try( - StmtTry { - range: 0..13, - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - handlers: [], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 14..20, - target: Name( - ExprName { - range: 14..19, - id: "exept", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 20..20, - id: "", - ctx: Invalid, - }, - ), - value: None, - simple: true, - }, - ), - Pass( - StmtPass { - range: 54..58, - }, - ), - Pass( - StmtPass { - range: 72..76, - }, - ), - Assign( - StmtAssign { - range: 77..82, - targets: [ - Name( - ExprName { - range: 77..78, - id: "a", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 81..82, - value: Int( - 1, - ), - }, - ), - }, - ), - Try( - StmtTry { - range: 83..113, - body: [ - Pass( - StmtPass { - range: 92..96, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 97..113, - type_: None, - name: None, - body: [ - Pass( - StmtPass { - range: 109..113, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 114..120, - target: Name( - ExprName { - range: 114..119, - id: "exept", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 120..120, - id: "", - ctx: Invalid, - }, - ), - value: None, - simple: true, - }, - ), - Pass( - StmtPass { - range: 154..158, - }, - ), - Assign( - StmtAssign { - range: 159..164, - targets: [ - Name( - ExprName { - range: 159..160, - id: "b", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 163..164, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | try: -2 | pass -3 | exept: # spellchecker:disable-line - | ^^^^^ Syntax Error: Expected `except` or `finally` after `try` block -4 | pass -5 | finally: - | - - - | -1 | try: -2 | pass -3 | exept: # spellchecker:disable-line - | ^ Syntax Error: Expected an expression -4 | pass -5 | finally: -6 | pass - | - - - | -2 | pass -3 | exept: # spellchecker:disable-line -4 | pass - | ^^^^ Syntax Error: Unexpected indentation -5 | finally: -6 | pass - | - - - | -3 | exept: # spellchecker:disable-line -4 | pass -5 | finally: - | Syntax Error: Expected a statement -6 | pass -7 | a = 1 - | - - - | -3 | exept: # spellchecker:disable-line -4 | pass -5 | finally: - | ^ Syntax Error: Expected a statement -6 | pass -7 | a = 1 - | - - - | -3 | exept: # spellchecker:disable-line -4 | pass -5 | finally: - | ^ Syntax Error: Expected a statement -6 | pass -7 | a = 1 -8 | try: - | - - - | -4 | pass -5 | finally: -6 | pass - | ^^^^ Syntax Error: Unexpected indentation -7 | a = 1 -8 | try: - | - - - | -5 | finally: -6 | pass -7 | a = 1 - | Syntax Error: Expected a statement -8 | try: -9 | pass - | - - - | -10 | except: -11 | pass -12 | exept: # spellchecker:disable-line - | ^ Syntax Error: Expected an expression -13 | pass -14 | b = 1 - | - - - | -11 | pass -12 | exept: # spellchecker:disable-line -13 | pass - | ^^^^ Syntax Error: Unexpected indentation -14 | b = 1 - | - - - | -12 | exept: # spellchecker:disable-line -13 | pass -14 | b = 1 - | Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap.new deleted file mode 100644 index b27b0f4cfb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap.new +++ /dev/null @@ -1,88 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_alias_incomplete_stmt.py ---- -## AST - -``` -Module( - ModModule { - range: 0..21, - body: [ - Expr( - StmtExpr { - range: 0..4, - value: Name( - ExprName { - range: 0..4, - id: "type", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5..9, - value: Name( - ExprName { - range: 5..9, - id: "type", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..11, - value: Name( - ExprName { - range: 10..11, - id: "x", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 12..20, - name: Name( - ExprName { - range: 17..18, - id: "x", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 20..20, - id: "", - ctx: Invalid, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type -2 | type x - | ^ Syntax Error: Simple statements must be separated by newlines or semicolons -3 | type x = - | - - - | -1 | type -2 | type x -3 | type x = - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap.new deleted file mode 100644 index b656fa9f91..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap.new +++ /dev/null @@ -1,161 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_alias_invalid_value_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..11, - name: Name( - ExprName { - range: 5..6, - id: "x", - ctx: Store, - }, - ), - type_params: None, - value: Starred( - ExprStarred { - range: 9..11, - value: Name( - ExprName { - range: 10..11, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 12..28, - name: Name( - ExprName { - range: 17..18, - id: "x", - ctx: Store, - }, - ), - type_params: None, - value: Yield( - ExprYield { - range: 21..28, - value: Some( - Name( - ExprName { - range: 27..28, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 29..50, - name: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Store, - }, - ), - type_params: None, - value: YieldFrom( - ExprYieldFrom { - range: 38..50, - value: Name( - ExprName { - range: 49..50, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 51..61, - name: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 60..61, - id: "x", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 65..66, - value: NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type x = *y - | ^^ Syntax Error: Starred expression cannot be used here -2 | type x = yield y -3 | type x = yield from y - | - - - | -1 | type x = *y -2 | type x = yield y - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | type x = yield from y -4 | type x = x := 1 - | - - - | -1 | type x = *y -2 | type x = yield y -3 | type x = yield from y - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | type x = x := 1 - | - - - | -2 | type x = yield y -3 | type x = yield from y -4 | type x = x := 1 - | ^^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap.new deleted file mode 100644 index de47eb1a7d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap.new +++ /dev/null @@ -1,259 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_invalid_bound_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..103, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..21, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..15, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 7..14, - name: Identifier { - id: "T", - range: 7..8, - }, - bound: Some( - Starred( - ExprStarred { - range: 10..14, - value: Name( - ExprName { - range: 11..14, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 18..21, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 22..46, - name: Name( - ExprName { - range: 27..28, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 28..40, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 29..39, - name: Identifier { - id: "T", - range: 29..30, - }, - bound: Some( - Yield( - ExprYield { - range: 32..39, - value: Some( - Name( - ExprName { - range: 38..39, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 43..46, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 47..76, - name: Name( - ExprName { - range: 52..53, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 53..70, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 54..69, - name: Identifier { - id: "T", - range: 54..55, - }, - bound: Some( - YieldFrom( - ExprYieldFrom { - range: 57..69, - value: Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 73..76, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 77..102, - name: Name( - ExprName { - range: 82..83, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 83..96, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 84..88, - name: Identifier { - id: "T", - range: 84..85, - }, - bound: Some( - Name( - ExprName { - range: 87..88, - id: "x", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 92..95, - name: Identifier { - id: "int", - range: 92..95, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 99..102, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[T: *int] = int - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | type X[T: yield x] = int -3 | type X[T: yield from x] = int - | - - - | -1 | type X[T: *int] = int -2 | type X[T: yield x] = int - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | type X[T: yield from x] = int -4 | type X[T: x := int] = int - | - - - | -1 | type X[T: *int] = int -2 | type X[T: yield x] = int -3 | type X[T: yield from x] = int - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | type X[T: x := int] = int - | - - - | -2 | type X[T: yield x] = int -3 | type X[T: yield from x] = int -4 | type X[T: x := int] = int - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap.new deleted file mode 100644 index 9439450b96..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap.new +++ /dev/null @@ -1,115 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_missing_bound.py ---- -## AST - -``` -Module( - ModModule { - range: 0..41, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..17, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..11, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 7..9, - name: Identifier { - id: "T", - range: 7..8, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 18..40, - name: Name( - ExprName { - range: 23..24, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 24..34, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 25..28, - name: Identifier { - id: "T1", - range: 25..27, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 31..33, - name: Identifier { - id: "T2", - range: 31..33, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 37..40, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[T: ] = int - | ^ Syntax Error: Expected an expression -2 | type X[T1: , T2] = int - | - - - | -1 | type X[T: ] = int -2 | type X[T1: , T2] = int - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap.new deleted file mode 100644 index 7ca453bd91..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap.new +++ /dev/null @@ -1,94 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec_bound.py ---- -## AST - -``` -Module( - ModModule { - range: 0..23, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..10, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..10, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 7..10, - name: Identifier { - id: "T", - range: 9..10, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 10..10, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..15, - value: Name( - ExprName { - range: 12..15, - id: "int", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 19..22, - value: Name( - ExprName { - range: 19..22, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[**T: int] = int - | ^ Syntax Error: Expected ']', found ':' - | - - - | -1 | type X[**T: int] = int - | ^ Syntax Error: Expected a statement - | - - - | -1 | type X[**T: int] = int - | ^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap.new deleted file mode 100644 index 887ad11218..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap.new +++ /dev/null @@ -1,315 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec_invalid_default_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..140, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..24, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..18, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 7..17, - name: Identifier { - id: "P", - range: 9..10, - }, - default: Some( - Starred( - ExprStarred { - range: 13..17, - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 21..24, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 25..52, - name: Name( - ExprName { - range: 30..31, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 31..46, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 32..45, - name: Identifier { - id: "P", - range: 34..35, - }, - default: Some( - Yield( - ExprYield { - range: 38..45, - value: Some( - Name( - ExprName { - range: 44..45, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 49..52, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 53..85, - name: Name( - ExprName { - range: 58..59, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 59..79, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 60..78, - name: Identifier { - id: "P", - range: 62..63, - }, - default: Some( - YieldFrom( - ExprYieldFrom { - range: 66..78, - value: Name( - ExprName { - range: 77..78, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 82..85, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 86..114, - name: Name( - ExprName { - range: 91..92, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 92..108, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 93..100, - name: Identifier { - id: "P", - range: 95..96, - }, - default: Some( - Name( - ExprName { - range: 99..100, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - TypeVar( - TypeParamTypeVar { - range: 104..107, - name: Identifier { - id: "int", - range: 104..107, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 111..114, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 115..139, - name: Name( - ExprName { - range: 120..121, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 121..133, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 122..132, - name: Identifier { - id: "P", - range: 124..125, - }, - default: Some( - Starred( - ExprStarred { - range: 128..132, - value: Name( - ExprName { - range: 129..132, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 136..139, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[**P = *int] = int - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | type X[**P = yield x] = int -3 | type X[**P = yield from x] = int - | - - - | -1 | type X[**P = *int] = int -2 | type X[**P = yield x] = int - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | type X[**P = yield from x] = int -4 | type X[**P = x := int] = int - | - - - | -1 | type X[**P = *int] = int -2 | type X[**P = yield x] = int -3 | type X[**P = yield from x] = int - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | type X[**P = x := int] = int -5 | type X[**P = *int] = int - | - - - | -2 | type X[**P = yield x] = int -3 | type X[**P = yield from x] = int -4 | type X[**P = x := int] = int - | ^^ Syntax Error: Expected ',', found ':=' -5 | type X[**P = *int] = int - | - - - | -3 | type X[**P = yield from x] = int -4 | type X[**P = x := int] = int -5 | type X[**P = *int] = int - | ^^^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap.new deleted file mode 100644 index 09083d9454..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap.new +++ /dev/null @@ -1,113 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec_missing_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..44, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..19, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..13, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 7..12, - name: Identifier { - id: "P", - range: 9..10, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 16..19, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 20..43, - name: Name( - ExprName { - range: 25..26, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 26..37, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 27..32, - name: Identifier { - id: "P", - range: 29..30, - }, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 34..36, - name: Identifier { - id: "T2", - range: 34..36, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 40..43, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[**P =] = int - | ^ Syntax Error: Expected an expression -2 | type X[**P =, T2] = int - | - - - | -1 | type X[**P =] = int -2 | type X[**P =, T2] = int - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap.new deleted file mode 100644 index 4d1908e67a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap.new +++ /dev/null @@ -1,380 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_invalid_default_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..163, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..22, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..16, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 7..15, - name: Identifier { - id: "T", - range: 7..8, - }, - bound: None, - default: Some( - Starred( - ExprStarred { - range: 11..15, - value: Name( - ExprName { - range: 12..15, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 19..22, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 23..48, - name: Name( - ExprName { - range: 28..29, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 29..42, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 30..41, - name: Identifier { - id: "T", - range: 30..31, - }, - bound: None, - default: Some( - Yield( - ExprYield { - range: 34..41, - value: Some( - Name( - ExprName { - range: 40..41, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 45..48, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 49..76, - name: Name( - ExprName { - range: 54..55, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 55..70, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 56..69, - name: Identifier { - id: "T", - range: 56..57, - }, - bound: None, - default: Some( - Yield( - ExprYield { - range: 61..68, - value: Some( - Name( - ExprName { - range: 67..68, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 73..76, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 77..107, - name: Name( - ExprName { - range: 82..83, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 83..101, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 84..100, - name: Identifier { - id: "T", - range: 84..85, - }, - bound: None, - default: Some( - YieldFrom( - ExprYieldFrom { - range: 88..100, - value: Name( - ExprName { - range: 99..100, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 104..107, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 108..134, - name: Name( - ExprName { - range: 113..114, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 114..128, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 115..120, - name: Identifier { - id: "T", - range: 115..116, - }, - bound: None, - default: Some( - Name( - ExprName { - range: 119..120, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - TypeVar( - TypeParamTypeVar { - range: 124..127, - name: Identifier { - id: "int", - range: 124..127, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 131..134, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 135..162, - name: Name( - ExprName { - range: 140..141, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 141..156, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 142..155, - name: Identifier { - id: "T", - range: 142..143, - }, - bound: Some( - Name( - ExprName { - range: 145..148, - id: "int", - ctx: Load, - }, - ), - ), - default: Some( - Starred( - ExprStarred { - range: 151..155, - value: Name( - ExprName { - range: 152..155, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 159..162, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[T = *int] = int - | ^^^^ Syntax Error: Starred expression cannot be used here -2 | type X[T = yield x] = int -3 | type X[T = (yield x)] = int - | - - - | -1 | type X[T = *int] = int -2 | type X[T = yield x] = int - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | type X[T = (yield x)] = int -4 | type X[T = yield from x] = int - | - - - | -2 | type X[T = yield x] = int -3 | type X[T = (yield x)] = int -4 | type X[T = yield from x] = int - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | type X[T = x := int] = int -6 | type X[T: int = *int] = int - | - - - | -3 | type X[T = (yield x)] = int -4 | type X[T = yield from x] = int -5 | type X[T = x := int] = int - | ^^ Syntax Error: Expected ',', found ':=' -6 | type X[T: int = *int] = int - | - - - | -4 | type X[T = yield from x] = int -5 | type X[T = x := int] = int -6 | type X[T: int = *int] = int - | ^^^^ Syntax Error: Starred expression cannot be used here - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap.new deleted file mode 100644 index 9eebfb0e0a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap.new +++ /dev/null @@ -1,170 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_missing_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..64, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..17, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..11, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 7..10, - name: Identifier { - id: "T", - range: 7..8, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 18..40, - name: Name( - ExprName { - range: 23..24, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 24..34, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 25..33, - name: Identifier { - id: "T", - range: 25..26, - }, - bound: Some( - Name( - ExprName { - range: 28..31, - id: "int", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 37..40, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 41..63, - name: Name( - ExprName { - range: 46..47, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 47..57, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 48..52, - name: Identifier { - id: "T1", - range: 48..50, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 54..56, - name: Identifier { - id: "T2", - range: 54..56, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 60..63, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[T =] = int - | ^ Syntax Error: Expected an expression -2 | type X[T: int =] = int -3 | type X[T1 =, T2] = int - | - - - | -1 | type X[T =] = int -2 | type X[T: int =] = int - | ^ Syntax Error: Expected an expression -3 | type X[T1 =, T2] = int - | - - - | -1 | type X[T =] = int -2 | type X[T: int =] = int -3 | type X[T1 =, T2] = int - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap.new deleted file mode 100644 index 123a0fa134..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap.new +++ /dev/null @@ -1,94 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_tuple_bound.py ---- -## AST - -``` -Module( - ModModule { - range: 0..22, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..9, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..9, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 7..9, - name: Identifier { - id: "T", - range: 8..9, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 9..9, - id: "", - ctx: Invalid, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..14, - value: Name( - ExprName { - range: 11..14, - id: "int", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..21, - value: Name( - ExprName { - range: 18..21, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[*T: int] = int - | ^ Syntax Error: Expected ']', found ':' - | - - - | -1 | type X[*T: int] = int - | ^ Syntax Error: Expected a statement - | - - - | -1 | type X[*T: int] = int - | ^ Syntax Error: Expected a statement - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap.new deleted file mode 100644 index 38d65d9f42..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap.new +++ /dev/null @@ -1,322 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_tuple_invalid_default_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..147, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..24, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..18, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 7..17, - name: Identifier { - id: "Ts", - range: 8..10, - }, - default: Some( - Starred( - ExprStarred { - range: 13..17, - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 21..24, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 25..56, - name: Name( - ExprName { - range: 30..31, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 31..50, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 32..49, - name: Identifier { - id: "Ts", - range: 33..35, - }, - default: Some( - Starred( - ExprStarred { - range: 38..49, - value: BoolOp( - ExprBoolOp { - range: 39..49, - op: Or, - values: [ - Name( - ExprName { - range: 39..42, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 46..49, - id: "str", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 53..56, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 57..84, - name: Name( - ExprName { - range: 62..63, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 63..78, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 64..77, - name: Identifier { - id: "Ts", - range: 65..67, - }, - default: Some( - Yield( - ExprYield { - range: 70..77, - value: Some( - Name( - ExprName { - range: 76..77, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 81..84, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 85..117, - name: Name( - ExprName { - range: 90..91, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 91..111, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 92..110, - name: Identifier { - id: "Ts", - range: 93..95, - }, - default: Some( - YieldFrom( - ExprYieldFrom { - range: 98..110, - value: Name( - ExprName { - range: 109..110, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 114..117, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 118..146, - name: Name( - ExprName { - range: 123..124, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 124..140, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 125..132, - name: Identifier { - id: "Ts", - range: 126..128, - }, - default: Some( - Name( - ExprName { - range: 131..132, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - TypeVar( - TypeParamTypeVar { - range: 136..139, - name: Identifier { - id: "int", - range: 136..139, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 143..146, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[*Ts = *int] = int -2 | type X[*Ts = *int or str] = int - | ^^^^^^^^^^ Syntax Error: Boolean expression cannot be used here -3 | type X[*Ts = yield x] = int -4 | type X[*Ts = yield from x] = int - | - - - | -1 | type X[*Ts = *int] = int -2 | type X[*Ts = *int or str] = int -3 | type X[*Ts = yield x] = int - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -4 | type X[*Ts = yield from x] = int -5 | type X[*Ts = x := int] = int - | - - - | -2 | type X[*Ts = *int or str] = int -3 | type X[*Ts = yield x] = int -4 | type X[*Ts = yield from x] = int - | ^^^^^^^^^^^^ Syntax Error: Yield expression cannot be used here -5 | type X[*Ts = x := int] = int - | - - - | -3 | type X[*Ts = yield x] = int -4 | type X[*Ts = yield from x] = int -5 | type X[*Ts = x := int] = int - | ^^ Syntax Error: Expected ',', found ':=' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap.new deleted file mode 100644 index a5c151e6dd..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap.new +++ /dev/null @@ -1,113 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_tuple_missing_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..44, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..19, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..13, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 7..12, - name: Identifier { - id: "Ts", - range: 8..10, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 16..19, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 20..43, - name: Name( - ExprName { - range: 25..26, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 26..37, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 27..32, - name: Identifier { - id: "Ts", - range: 28..30, - }, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 34..36, - name: Identifier { - id: "T2", - range: 34..36, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 40..43, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | type X[*Ts =] = int - | ^ Syntax Error: Expected an expression -2 | type X[*Ts =, T2] = int - | - - - | -1 | type X[*Ts =] = int -2 | type X[*Ts =, T2] = int - | ^ Syntax Error: Expected an expression - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap.new deleted file mode 100644 index 420665cc1e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap.new +++ /dev/null @@ -1,103 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/type_params_empty.py ---- -## AST - -``` -Module( - ModModule { - range: 0..52, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..21, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: Some( - TypeParams { - range: 7..9, - type_params: [], - }, - ), - parameters: Parameters { - range: 9..11, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 17..21, - }, - ), - ], - }, - ), - TypeAlias( - StmtTypeAlias { - range: 22..51, - name: Name( - ExprName { - range: 27..36, - id: "ListOrSet", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 36..38, - type_params: [], - }, - ), - value: BinOp( - ExprBinOp { - range: 41..51, - left: Name( - ExprName { - range: 41..45, - id: "list", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 48..51, - id: "set", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | def foo[](): - | ^ Syntax Error: Type parameter list cannot be empty -2 | pass -3 | type ListOrSet[] = list | set - | - - - | -1 | def foo[](): -2 | pass -3 | type ListOrSet[] = list | set - | ^ Syntax Error: Type parameter list cannot be empty - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap.new deleted file mode 100644 index 104a9827ce..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap.new +++ /dev/null @@ -1,361 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/unterminated_fstring_newline_recovery.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: FString( - ExprFString { - range: 0..7, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..7, - elements: [], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..13, - value: BinOp( - ExprBinOp { - range: 8..13, - left: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 12..13, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 14..24, - value: FString( - ExprFString { - range: 14..24, - value: FStringValue { - inner: Single( - FString( - FString { - range: 14..24, - elements: [ - Literal( - FStringLiteralElement { - range: 16..22, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 22..24, - expression: Name( - ExprName { - range: 23..24, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 25..30, - value: BinOp( - ExprBinOp { - range: 25..30, - left: NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 29..30, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 31..42, - value: FString( - ExprFString { - range: 31..42, - value: FStringValue { - inner: Single( - FString( - FString { - range: 31..42, - elements: [ - Literal( - FStringLiteralElement { - range: 33..39, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 39..42, - expression: Name( - ExprName { - range: 40..41, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 42..42, - elements: [], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 43..48, - value: BinOp( - ExprBinOp { - range: 43..48, - left: NumberLiteral( - ExprNumberLiteral { - range: 43..44, - value: Int( - 3, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 47..48, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..60, - value: FString( - ExprFString { - range: 49..60, - value: FStringValue { - inner: Single( - FString( - FString { - range: 49..60, - elements: [ - Literal( - FStringLiteralElement { - range: 51..57, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 57..60, - expression: Name( - ExprName { - range: 58..59, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 61..66, - value: BinOp( - ExprBinOp { - range: 61..66, - left: NumberLiteral( - ExprNumberLiteral { - range: 61..62, - value: Int( - 4, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 4, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` -## Errors - - | -1 | f"hello - | ^^^^^ Syntax Error: f-string: unterminated string -2 | 1 + 1 -3 | f"hello {x - | - - - | -1 | f"hello - | ^ Syntax Error: Expected FStringEnd, found newline -2 | 1 + 1 -3 | f"hello {x -4 | 2 + 2 - | - - - | -1 | f"hello -2 | 1 + 1 -3 | f"hello {x - | Syntax Error: f-string: unterminated string -4 | 2 + 2 -5 | f"hello {x: - | - - - | -2 | 1 + 1 -3 | f"hello {x -4 | 2 + 2 - | ^ Syntax Error: f-string: expecting '}' -5 | f"hello {x: -6 | 3 + 3 - | - - - | -1 | f"hello -2 | 1 + 1 -3 | f"hello {x - | Syntax Error: Expected FStringEnd, found Unknown -4 | 2 + 2 -5 | f"hello {x: - | - - - | -3 | f"hello {x -4 | 2 + 2 -5 | f"hello {x: - | Syntax Error: f-string: unterminated string -6 | 3 + 3 -7 | f"hello {x} - | - - - | -5 | f"hello {x: -6 | 3 + 3 -7 | f"hello {x} - | Syntax Error: f-string: unterminated string -8 | 4 + 4 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap.new deleted file mode 100644 index cfeb864cdf..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap.new +++ /dev/null @@ -1,192 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_invalid_test_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..70, - body: [ - While( - StmtWhile { - range: 0..13, - test: Starred( - ExprStarred { - range: 6..8, - value: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 10..13, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 10..13, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 14..32, - test: Yield( - ExprYield { - range: 20..27, - value: Some( - Name( - ExprName { - range: 26..27, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 33..40, - test: Name( - ExprName { - range: 39..40, - id: "a", - ctx: Load, - }, - ), - body: [], - orelse: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 42..48, - target: Name( - ExprName { - range: 42..43, - id: "b", - ctx: Store, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 45..48, - }, - ), - value: None, - simple: true, - }, - ), - While( - StmtWhile { - range: 49..61, - test: Named( - ExprNamed { - range: 55..61, - target: Name( - ExprName { - range: 55..56, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 60..61, - value: Int( - 1, - ), - }, - ), - }, - ), - body: [], - orelse: [], - }, - ), - AnnAssign( - StmtAnnAssign { - range: 63..69, - target: Name( - ExprName { - range: 63..64, - id: "b", - ctx: Store, - }, - ), - annotation: EllipsisLiteral( - ExprEllipsisLiteral { - range: 66..69, - }, - ), - value: None, - simple: true, - }, - ), - ], - }, -) -``` -## Errors - - | -1 | while *x: ... - | ^^ Syntax Error: Starred expression cannot be used here -2 | while yield x: ... -3 | while a, b: ... - | - - - | -1 | while *x: ... -2 | while yield x: ... - | ^^^^^^^ Syntax Error: Yield expression cannot be used here -3 | while a, b: ... -4 | while a := 1, b: ... - | - - - | -1 | while *x: ... -2 | while yield x: ... -3 | while a, b: ... - | ^ Syntax Error: Expected ':', found ',' -4 | while a := 1, b: ... - | - - - | -2 | while yield x: ... -3 | while a, b: ... -4 | while a := 1, b: ... - | ^ Syntax Error: Expected ':', found ',' - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap.new deleted file mode 100644 index 6c83c59bca..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap.new +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_missing_colon.py ---- -## AST - -``` -Module( - ModModule { - range: 0..40, - body: [ - While( - StmtWhile { - range: 0..39, - test: Compare( - ExprCompare { - range: 12..18, - left: Name( - ExprName { - range: 12..13, - id: "a", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 16..18, - value: Int( - 30, - ), - }, - ), - ], - }, - ), - body: [ - Pass( - StmtPass { - range: 35..39, - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | while ( -2 | a < 30 # comment -3 | ) - | ^ Syntax Error: Expected ':', found newline -4 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap.new deleted file mode 100644 index 46a5434907..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap.new +++ /dev/null @@ -1,94 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_missing_test.py ---- -## AST - -``` -Module( - ModModule { - range: 0..30, - body: [ - While( - StmtWhile { - range: 0..11, - test: Name( - ExprName { - range: 5..5, - id: "", - ctx: Invalid, - }, - ), - body: [ - Expr( - StmtExpr { - range: 8..11, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 8..11, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 12..29, - test: Name( - ExprName { - range: 17..17, - id: "", - ctx: Invalid, - }, - ), - body: [ - Assign( - StmtAssign { - range: 24..29, - targets: [ - Name( - ExprName { - range: 24..25, - id: "a", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | while : ... - | ^ Syntax Error: Expected an expression -2 | while : -3 | a = 1 - | - - - | -1 | while : ... -2 | while : - | ^ Syntax Error: Expected an expression -3 | a = 1 - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap.new deleted file mode 100644 index d0387be628..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap.new +++ /dev/null @@ -1,61 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/with_items_parenthesized_missing_colon.py ---- -## AST - -``` -Module( - ModModule { - range: 0..57, - body: [ - With( - StmtWith { - range: 28..56, - is_async: false, - items: [ - WithItem { - range: 34..39, - context_expr: Name( - ExprName { - range: 34..39, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 41..46, - context_expr: Name( - ExprName { - range: 41..46, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Pass( - StmtPass { - range: 52..56, - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | # `)` followed by a newline -2 | with (item1, item2) - | ^ Syntax Error: Expected ':', found newline -3 | pass - | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap.new b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap.new deleted file mode 100644 index c888be366f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap.new +++ /dev/null @@ -1,335 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 122 -input_file: crates/ruff_python_parser/resources/inline/err/with_items_parenthesized_missing_comma.py ---- -## AST - -``` -Module( - ModModule { - range: 0..160, - body: [ - With( - StmtWith { - range: 0..23, - is_async: false, - items: [ - WithItem { - range: 6..11, - context_expr: Name( - ExprName { - range: 6..11, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 12..17, - context_expr: Name( - ExprName { - range: 12..17, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 20..23, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 20..23, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 24..53, - is_async: false, - items: [ - WithItem { - range: 30..41, - context_expr: Name( - ExprName { - range: 30..35, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 39..41, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 42..47, - context_expr: Name( - ExprName { - range: 42..47, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 50..53, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 50..53, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 54..91, - is_async: false, - items: [ - WithItem { - range: 60..65, - context_expr: Name( - ExprName { - range: 60..65, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 67..72, - context_expr: Name( - ExprName { - range: 67..72, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 73..78, - context_expr: Name( - ExprName { - range: 73..78, - id: "item3", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 80..85, - context_expr: Name( - ExprName { - range: 80..85, - id: "item4", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 88..91, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 88..91, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 92..135, - is_async: false, - items: [ - WithItem { - range: 98..103, - context_expr: Name( - ExprName { - range: 98..103, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 105..116, - context_expr: Name( - ExprName { - range: 105..110, - id: "item2", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 114..116, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 117..122, - context_expr: Name( - ExprName { - range: 117..122, - id: "item3", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 124..129, - context_expr: Name( - ExprName { - range: 124..129, - id: "item4", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 132..135, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 132..135, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 136..159, - is_async: false, - items: [ - WithItem { - range: 141..154, - context_expr: Tuple( - ExprTuple { - range: 141..154, - elts: [ - Name( - ExprName { - range: 142..147, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 149..154, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 156..159, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 156..159, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` -## Errors - - | -1 | with (item1 item2): ... - | ^^^^^ Syntax Error: Expected ',', found name -2 | with (item1 as f1 item2): ... -3 | with (item1, item2 item3, item4): ... - | - - - | -1 | with (item1 item2): ... -2 | with (item1 as f1 item2): ... - | ^^^^^ Syntax Error: Expected ',', found name -3 | with (item1, item2 item3, item4): ... -4 | with (item1, item2 as f1 item3, item4): ... - | - - - | -1 | with (item1 item2): ... -2 | with (item1 as f1 item2): ... -3 | with (item1, item2 item3, item4): ... - | ^^^^^ Syntax Error: Expected ',', found name -4 | with (item1, item2 as f1 item3, item4): ... -5 | with (item1, item2: ... - | - - - | -2 | with (item1 as f1 item2): ... -3 | with (item1, item2 item3, item4): ... -4 | with (item1, item2 as f1 item3, item4): ... - | ^^^^^ Syntax Error: Expected ',', found name -5 | with (item1, item2: ... - | - - - | -3 | with (item1, item2 item3, item4): ... -4 | with (item1, item2 as f1 item3, item4): ... -5 | with (item1, item2: ... - | ^ Syntax Error: Expected ')', found ':' - | diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap.new deleted file mode 100644 index 461882ce41..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap.new +++ /dev/null @@ -1,373 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/ambiguous_lpar_with_items_binary_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..337, - body: [ - With( - StmtWith { - range: 124..143, - is_async: false, - items: [ - WithItem { - range: 129..138, - context_expr: BoolOp( - ExprBoolOp { - range: 129..138, - op: And, - values: [ - Name( - ExprName { - range: 130..131, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 137..138, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 140..143, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 140..143, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 144..166, - is_async: false, - items: [ - WithItem { - range: 149..161, - context_expr: Compare( - ExprCompare { - range: 149..161, - left: Name( - ExprName { - range: 150..151, - id: "a", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 160..161, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 163..166, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 163..166, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 196..220, - is_async: false, - items: [ - WithItem { - range: 201..215, - context_expr: BoolOp( - ExprBoolOp { - range: 201..215, - op: Or, - values: [ - Name( - ExprName { - range: 202..203, - id: "a", - ctx: Load, - }, - ), - BoolOp( - ExprBoolOp { - range: 208..215, - op: And, - values: [ - Name( - ExprName { - range: 208..209, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 214..215, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - ], - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 217..220, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 217..220, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 221..245, - is_async: false, - items: [ - WithItem { - range: 226..240, - context_expr: BoolOp( - ExprBoolOp { - range: 226..240, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 226..235, - op: And, - values: [ - Name( - ExprName { - range: 227..228, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 234..235, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 239..240, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 242..245, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 242..245, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 246..272, - is_async: false, - items: [ - WithItem { - range: 251..267, - context_expr: BinOp( - ExprBinOp { - range: 251..267, - left: BinOp( - ExprBinOp { - range: 251..263, - left: BinOp( - ExprBinOp { - range: 252..257, - left: Name( - ExprName { - range: 252..253, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 256..257, - id: "b", - ctx: Load, - }, - ), - }, - ), - op: LShift, - right: Name( - ExprName { - range: 262..263, - id: "c", - ctx: Load, - }, - ), - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 266..267, - id: "d", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 269..272, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 269..272, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 312..336, - is_async: false, - items: [ - WithItem { - range: 317..331, - context_expr: BinOp( - ExprBinOp { - range: 317..331, - left: Subscript( - ExprSubscript { - range: 317..323, - value: Name( - ExprName { - range: 318..319, - id: "a", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 321..322, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 326..331, - left: Name( - ExprName { - range: 326..327, - id: "b", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 330..331, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 333..336, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 333..336, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap.new deleted file mode 100644 index 4cee4c7fe8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap.new +++ /dev/null @@ -1,280 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/ambiguous_lpar_with_items_if_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..153, - body: [ - With( - StmtWith { - range: 0..28, - is_async: false, - items: [ - WithItem { - range: 5..23, - context_expr: If( - ExprIf { - range: 5..23, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 12..16, - value: true, - }, - ), - body: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 22..23, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 29..71, - is_async: false, - items: [ - WithItem { - range: 34..66, - context_expr: If( - ExprIf { - range: 34..66, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 55..59, - value: true, - }, - ), - body: Generator( - ExprGenerator { - range: 34..51, - elt: Name( - ExprName { - range: 35..36, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 37..50, - target: Name( - ExprName { - range: 41..42, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 46..50, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - orelse: Name( - ExprName { - range: 65..66, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 68..71, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 68..71, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 72..120, - is_async: false, - items: [ - WithItem { - range: 77..115, - context_expr: If( - ExprIf { - range: 77..115, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 104..108, - value: true, - }, - ), - body: Generator( - ExprGenerator { - range: 77..100, - elt: Name( - ExprName { - range: 78..79, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 80..99, - target: Name( - ExprName { - range: 90..91, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 95..99, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: true, - }, - ], - parenthesized: true, - }, - ), - orelse: Name( - ExprName { - range: 114..115, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 117..120, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 117..120, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 121..152, - is_async: false, - items: [ - WithItem { - range: 126..147, - context_expr: If( - ExprIf { - range: 126..147, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 136..140, - value: true, - }, - ), - body: Subscript( - ExprSubscript { - range: 126..132, - value: Name( - ExprName { - range: 127..128, - id: "x", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 130..131, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 146..147, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 149..152, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 149..152, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap.new deleted file mode 100644 index 2f2d5ca177..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/ann_assign_stmt_simple_target.py ---- -## AST - -``` -Module( - ModModule { - range: 0..45, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..6, - target: Name( - ExprName { - range: 0..1, - id: "a", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 3..6, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 17..25, - target: Name( - ExprName { - range: 18..19, - id: "a", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 22..25, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 26..34, - target: Attribute( - ExprAttribute { - range: 26..29, - value: Name( - ExprName { - range: 26..27, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 28..29, - }, - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 31..34, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 35..44, - target: Subscript( - ExprSubscript { - range: 35..39, - value: Name( - ExprName { - range: 35..36, - id: "a", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 37..38, - value: Int( - 0, - ), - }, - ), - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 41..44, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: false, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap.new deleted file mode 100644 index 60ed452949..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap.new +++ /dev/null @@ -1,144 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/assign_targets_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..39, - body: [ - Assign( - StmtAssign { - range: 0..13, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 4..5, - id: "y", - ctx: Store, - }, - ), - Name( - ExprName { - range: 8..9, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 12..13, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 15..19, - value: Tuple( - ExprTuple { - range: 15..19, - elts: [ - Name( - ExprName { - range: 15..16, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 18..19, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 20..33, - targets: [ - Name( - ExprName { - range: 20..21, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 24..25, - id: "y", - ctx: Store, - }, - ), - Name( - ExprName { - range: 28..29, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 32..33, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 34..38, - value: Tuple( - ExprTuple { - range: 34..38, - elts: [ - Name( - ExprName { - range: 34..35, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 37..38, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap.new deleted file mode 100644 index e7733905b6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap.new +++ /dev/null @@ -1,49 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/async_for_statement.py ---- -## AST - -``` -Module( - ModModule { - range: 0..30, - body: [ - For( - StmtFor { - range: 0..29, - is_async: true, - target: Name( - ExprName { - range: 10..16, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 20..24, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 26..29, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 26..29, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap.new deleted file mode 100644 index fca5112f4d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap.new +++ /dev/null @@ -1,49 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/async_function_definition.py ---- -## AST - -``` -Module( - ModModule { - range: 0..21, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..20, - is_async: true, - decorator_list: [], - name: Identifier { - id: "foo", - range: 10..13, - }, - type_params: None, - parameters: Parameters { - range: 13..15, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 17..20, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 17..20, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap.new deleted file mode 100644 index b354c1069b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap.new +++ /dev/null @@ -1,47 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/async_with_statement.py ---- -## AST - -``` -Module( - ModModule { - range: 0..21, - body: [ - With( - StmtWith { - range: 0..20, - is_async: true, - items: [ - WithItem { - range: 11..15, - context_expr: Name( - ExprName { - range: 11..15, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 17..20, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 17..20, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap.new deleted file mode 100644 index caddabb85d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap.new +++ /dev/null @@ -1,70 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/class_def_arguments.py ---- -## AST - -``` -Module( - ModModule { - range: 0..32, - body: [ - ClassDef( - StmtClassDef { - range: 0..14, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 6..9, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 11..14, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 11..14, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 15..31, - decorator_list: [], - name: Identifier { - id: "Foo", - range: 21..24, - }, - type_params: None, - arguments: Some( - Arguments { - range: 24..26, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 28..31, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 28..31, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap.new deleted file mode 100644 index e70f92620e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap.new +++ /dev/null @@ -1,60 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/decorator_async_function.py ---- -## AST - -``` -Module( - ModModule { - range: 0..32, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..31, - is_async: true, - decorator_list: [ - Decorator { - range: 0..10, - expression: Name( - ExprName { - range: 1..10, - id: "decorator", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 21..24, - }, - type_params: None, - parameters: Parameters { - range: 24..26, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 28..31, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 28..31, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap.new deleted file mode 100644 index c90f62c460..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap.new +++ /dev/null @@ -1,114 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/del_targets_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..29, - body: [ - Delete( - StmtDelete { - range: 0..8, - targets: [ - Name( - ExprName { - range: 4..5, - id: "a", - ctx: Del, - }, - ), - Name( - ExprName { - range: 7..8, - id: "b", - ctx: Del, - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 10..14, - value: Tuple( - ExprTuple { - range: 10..14, - elts: [ - Name( - ExprName { - range: 10..11, - id: "c", - ctx: Load, - }, - ), - Name( - ExprName { - range: 13..14, - id: "d", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Delete( - StmtDelete { - range: 15..23, - targets: [ - Name( - ExprName { - range: 19..20, - id: "a", - ctx: Del, - }, - ), - Name( - ExprName { - range: 22..23, - id: "b", - ctx: Del, - }, - ), - ], - }, - ), - Expr( - StmtExpr { - range: 24..28, - value: Tuple( - ExprTuple { - range: 24..28, - elts: [ - Name( - ExprName { - range: 24..25, - id: "c", - ctx: Load, - }, - ), - Name( - ExprName { - range: 27..28, - id: "d", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap.new deleted file mode 100644 index f1c51871da..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap.new +++ /dev/null @@ -1,46 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/dotted_name_normalized_spaces.py ---- -## AST - -``` -Module( - ModModule { - range: 0..32, - body: [ - Import( - StmtImport { - range: 0..12, - names: [ - Alias { - range: 7..12, - name: Identifier { - id: "a.b.c", - range: 7..12, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 13..31, - names: [ - Alias { - range: 20..31, - name: Identifier { - id: "a.b.c", - range: 20..31, - }, - asname: None, - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap.new deleted file mode 100644 index bec5ee7eba..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap.new +++ /dev/null @@ -1,134 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/except_stmt_as_name_soft_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..100, - body: [ - Try( - StmtTry { - range: 0..99, - body: [ - Expr( - StmtExpr { - range: 5..8, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 5..8, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 9..39, - type_: Some( - Name( - ExprName { - range: 16..25, - id: "Exception", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "match", - range: 29..34, - }, - ), - body: [ - Expr( - StmtExpr { - range: 36..39, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 36..39, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 40..69, - type_: Some( - Name( - ExprName { - range: 47..56, - id: "Exception", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "case", - range: 60..64, - }, - ), - body: [ - Expr( - StmtExpr { - range: 66..69, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 66..69, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 70..99, - type_: Some( - Name( - ExprName { - range: 77..86, - id: "Exception", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "type", - range: 90..94, - }, - ), - body: [ - Expr( - StmtExpr { - range: 96..99, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 96..99, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap.new deleted file mode 100644 index 0171f63594..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap.new +++ /dev/null @@ -1,1726 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/arguments.py ---- -## AST - -``` -Module( - ModModule { - range: 0..805, - body: [ - Expr( - StmtExpr { - range: 102..108, - value: Call( - ExprCall { - range: 102..108, - func: Name( - ExprName { - range: 102..106, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 106..108, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 109..119, - value: Call( - ExprCall { - range: 109..119, - func: Name( - ExprName { - range: 109..113, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 113..119, - args: [ - Name( - ExprName { - range: 114..115, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 117..118, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 120..131, - value: Call( - ExprCall { - range: 120..131, - func: Name( - ExprName { - range: 120..124, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 124..131, - args: [ - Name( - ExprName { - range: 125..126, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 128..129, - id: "y", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 150..164, - value: Call( - ExprCall { - range: 150..164, - func: Name( - ExprName { - range: 150..154, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 154..164, - args: [], - keywords: [ - Keyword { - range: 155..158, - arg: Some( - Identifier { - id: "x", - range: 155..156, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 157..158, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 160..163, - arg: Some( - Identifier { - id: "y", - range: 160..161, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 162..163, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 165..173, - value: Call( - ExprCall { - range: 165..173, - func: Name( - ExprName { - range: 165..169, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 169..173, - args: [ - Starred( - ExprStarred { - range: 170..172, - value: Name( - ExprName { - range: 171..172, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 174..183, - value: Call( - ExprCall { - range: 174..183, - func: Name( - ExprName { - range: 174..178, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 178..183, - args: [], - keywords: [ - Keyword { - range: 179..182, - arg: None, - value: Name( - ExprName { - range: 181..182, - id: "x", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 193..205, - value: Call( - ExprCall { - range: 193..205, - func: Name( - ExprName { - range: 193..197, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 197..205, - args: [ - Name( - ExprName { - range: 198..199, - id: "x", - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 201..204, - arg: Some( - Identifier { - id: "y", - range: 201..202, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 203..204, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 206..217, - value: Call( - ExprCall { - range: 206..217, - func: Name( - ExprName { - range: 206..210, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 210..217, - args: [ - Name( - ExprName { - range: 211..212, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 214..216, - value: Name( - ExprName { - range: 215..216, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 218..230, - value: Call( - ExprCall { - range: 218..230, - func: Name( - ExprName { - range: 218..222, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 222..230, - args: [ - Name( - ExprName { - range: 223..224, - id: "x", - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 226..229, - arg: None, - value: Name( - ExprName { - range: 228..229, - id: "y", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 231..244, - value: Call( - ExprCall { - range: 231..244, - func: Name( - ExprName { - range: 231..235, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 235..244, - args: [ - Starred( - ExprStarred { - range: 241..243, - value: Name( - ExprName { - range: 242..243, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 236..239, - arg: Some( - Identifier { - id: "x", - range: 236..237, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 238..239, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 245..259, - value: Call( - ExprCall { - range: 245..259, - func: Name( - ExprName { - range: 245..249, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 249..259, - args: [], - keywords: [ - Keyword { - range: 250..253, - arg: Some( - Identifier { - id: "x", - range: 250..251, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 252..253, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 255..258, - arg: None, - value: Name( - ExprName { - range: 257..258, - id: "y", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 260..273, - value: Call( - ExprCall { - range: 260..273, - func: Name( - ExprName { - range: 260..264, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 264..273, - args: [ - Starred( - ExprStarred { - range: 265..267, - value: Name( - ExprName { - range: 266..267, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 269..272, - arg: None, - value: Name( - ExprName { - range: 271..272, - id: "y", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 274..288, - value: Call( - ExprCall { - range: 274..288, - func: Name( - ExprName { - range: 274..278, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 278..288, - args: [ - Starred( - ExprStarred { - range: 279..281, - value: Name( - ExprName { - range: 280..281, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 283..284, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 286..287, - id: "z", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 289..308, - value: Call( - ExprCall { - range: 289..308, - func: Name( - ExprName { - range: 289..293, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 293..308, - args: [], - keywords: [ - Keyword { - range: 294..297, - arg: None, - value: Name( - ExprName { - range: 296..297, - id: "x", - ctx: Load, - }, - ), - }, - Keyword { - range: 299..302, - arg: Some( - Identifier { - id: "y", - range: 299..300, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 301..302, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 304..307, - arg: Some( - Identifier { - id: "z", - range: 304..305, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 306..307, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 309..335, - value: Call( - ExprCall { - range: 309..335, - func: Name( - ExprName { - range: 309..313, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 313..335, - args: [ - Starred( - ExprStarred { - range: 314..317, - value: Name( - ExprName { - range: 315..317, - id: "x1", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 319..322, - value: Name( - ExprName { - range: 320..322, - id: "x2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 324..328, - arg: None, - value: Name( - ExprName { - range: 326..328, - id: "y1", - ctx: Load, - }, - ), - }, - Keyword { - range: 330..334, - arg: None, - value: Name( - ExprName { - range: 332..334, - id: "y2", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 336..355, - value: Call( - ExprCall { - range: 336..355, - func: Name( - ExprName { - range: 336..340, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 340..355, - args: [], - keywords: [ - Keyword { - range: 341..344, - arg: Some( - Identifier { - id: "x", - range: 341..342, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 343..344, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 346..349, - arg: None, - value: Name( - ExprName { - range: 348..349, - id: "y", - ctx: Load, - }, - ), - }, - Keyword { - range: 351..354, - arg: Some( - Identifier { - id: "z", - range: 351..352, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 353..354, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 378..402, - value: Call( - ExprCall { - range: 378..402, - func: Name( - ExprName { - range: 378..382, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 382..402, - args: [], - keywords: [ - Keyword { - range: 383..401, - arg: Some( - Identifier { - id: "x", - range: 383..384, - }, - ), - value: If( - ExprIf { - range: 385..401, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 390..394, - value: true, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 385..386, - value: Int( - 1, - ), - }, - ), - orelse: NumberLiteral( - ExprNumberLiteral { - range: 400..401, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 403..418, - value: Call( - ExprCall { - range: 403..418, - func: Name( - ExprName { - range: 403..407, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 407..418, - args: [], - keywords: [ - Keyword { - range: 408..417, - arg: Some( - Identifier { - id: "x", - range: 408..409, - }, - ), - value: Await( - ExprAwait { - range: 410..417, - value: Name( - ExprName { - range: 416..417, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 419..438, - value: Call( - ExprCall { - range: 419..438, - func: Name( - ExprName { - range: 419..423, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 423..438, - args: [], - keywords: [ - Keyword { - range: 424..437, - arg: Some( - Identifier { - id: "x", - range: 424..425, - }, - ), - value: Lambda( - ExprLambda { - range: 426..437, - parameters: Some( - Parameters { - range: 433..434, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 433..434, - parameter: Parameter { - range: 433..434, - name: Identifier { - id: "y", - range: 433..434, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 436..437, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 439..455, - value: Call( - ExprCall { - range: 439..455, - func: Name( - ExprName { - range: 439..443, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 443..455, - args: [], - keywords: [ - Keyword { - range: 444..454, - arg: Some( - Identifier { - id: "x", - range: 444..445, - }, - ), - value: Named( - ExprNamed { - range: 447..453, - target: Name( - ExprName { - range: 447..448, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 452..453, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 476..491, - value: Call( - ExprCall { - range: 476..491, - func: Name( - ExprName { - range: 476..480, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 480..491, - args: [ - Yield( - ExprYield { - range: 482..489, - value: Some( - Name( - ExprName { - range: 488..489, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 492..512, - value: Call( - ExprCall { - range: 492..512, - func: Name( - ExprName { - range: 492..496, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 496..512, - args: [ - YieldFrom( - ExprYieldFrom { - range: 498..510, - value: Name( - ExprName { - range: 509..510, - id: "x", - ctx: Load, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 533..545, - value: Call( - ExprCall { - range: 533..545, - func: Name( - ExprName { - range: 533..537, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 537..545, - args: [ - Named( - ExprNamed { - range: 538..544, - target: Name( - ExprName { - range: 538..539, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 543..544, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 546..572, - value: Call( - ExprCall { - range: 546..572, - func: Name( - ExprName { - range: 546..550, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 550..572, - args: [ - Generator( - ExprGenerator { - range: 551..571, - elt: Named( - ExprNamed { - range: 551..557, - target: Name( - ExprName { - range: 551..552, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 556..557, - value: Int( - 1, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 558..571, - target: Name( - ExprName { - range: 562..563, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 567..571, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 596..610, - value: Call( - ExprCall { - range: 596..610, - func: Name( - ExprName { - range: 596..600, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 600..610, - args: [ - Starred( - ExprStarred { - range: 601..609, - value: BoolOp( - ExprBoolOp { - range: 602..609, - op: And, - values: [ - Name( - ExprName { - range: 602..603, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 608..609, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 611..623, - value: Call( - ExprCall { - range: 611..623, - func: Name( - ExprName { - range: 611..615, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 615..623, - args: [ - Starred( - ExprStarred { - range: 616..622, - value: BinOp( - ExprBinOp { - range: 617..622, - left: Name( - ExprName { - range: 617..618, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 621..622, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 624..638, - value: Call( - ExprCall { - range: 624..638, - func: Name( - ExprName { - range: 624..628, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 628..638, - args: [ - Starred( - ExprStarred { - range: 629..637, - value: Await( - ExprAwait { - range: 630..637, - value: Name( - ExprName { - range: 636..637, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 639..657, - value: Call( - ExprCall { - range: 639..657, - func: Name( - ExprName { - range: 639..643, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 643..657, - args: [ - Starred( - ExprStarred { - range: 644..656, - value: Lambda( - ExprLambda { - range: 645..656, - parameters: Some( - Parameters { - range: 652..653, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 652..653, - parameter: Parameter { - range: 652..653, - name: Identifier { - id: "x", - range: 652..653, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 655..656, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 658..681, - value: Call( - ExprCall { - range: 658..681, - func: Name( - ExprName { - range: 658..662, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 662..681, - args: [ - Starred( - ExprStarred { - range: 663..680, - value: If( - ExprIf { - range: 664..680, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 669..673, - value: true, - }, - ), - body: Name( - ExprName { - range: 664..665, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 679..680, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 700..709, - value: Call( - ExprCall { - range: 700..709, - func: Name( - ExprName { - range: 700..704, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 704..709, - args: [], - keywords: [ - Keyword { - range: 705..708, - arg: None, - value: Name( - ExprName { - range: 707..708, - id: "x", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 710..725, - value: Call( - ExprCall { - range: 710..725, - func: Name( - ExprName { - range: 710..714, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 714..725, - args: [], - keywords: [ - Keyword { - range: 715..724, - arg: None, - value: BoolOp( - ExprBoolOp { - range: 717..724, - op: And, - values: [ - Name( - ExprName { - range: 717..718, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 723..724, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 726..741, - value: Call( - ExprCall { - range: 726..741, - func: Name( - ExprName { - range: 726..730, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 730..741, - args: [], - keywords: [ - Keyword { - range: 731..740, - arg: None, - value: Await( - ExprAwait { - range: 733..740, - value: Name( - ExprName { - range: 739..740, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 742..766, - value: Call( - ExprCall { - range: 742..766, - func: Name( - ExprName { - range: 742..746, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 746..766, - args: [], - keywords: [ - Keyword { - range: 747..765, - arg: None, - value: If( - ExprIf { - range: 749..765, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 754..758, - value: true, - }, - ), - body: Name( - ExprName { - range: 749..750, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 764..765, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 767..784, - value: Call( - ExprCall { - range: 767..784, - func: Name( - ExprName { - range: 767..771, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 771..784, - args: [], - keywords: [ - Keyword { - range: 772..783, - arg: None, - value: Yield( - ExprYield { - range: 775..782, - value: Some( - Name( - ExprName { - range: 781..782, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 785..804, - value: Call( - ExprCall { - range: 785..804, - func: Name( - ExprName { - range: 785..789, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 789..804, - args: [], - keywords: [ - Keyword { - range: 790..803, - arg: None, - value: Lambda( - ExprLambda { - range: 792..803, - parameters: Some( - Parameters { - range: 799..800, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 799..800, - parameter: Parameter { - range: 799..800, - name: Identifier { - id: "x", - range: 799..800, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 802..803, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap.new deleted file mode 100644 index 504db03953..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap.new +++ /dev/null @@ -1,228 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/attribute.py ---- -## AST - -``` -Module( - ModModule { - range: 0..90, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Attribute( - ExprAttribute { - range: 0..10, - value: Name( - ExprName { - range: 0..5, - id: "value", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 6..10, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..23, - value: Call( - ExprCall { - range: 11..23, - func: Attribute( - ExprAttribute { - range: 11..21, - value: Name( - ExprName { - range: 11..16, - id: "value", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 17..21, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 21..23, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 24..36, - value: Attribute( - ExprAttribute { - range: 24..36, - value: Call( - ExprCall { - range: 24..31, - func: Name( - ExprName { - range: 24..29, - id: "value", - ctx: Load, - }, - ), - arguments: Arguments { - range: 29..31, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "attr", - range: 32..36, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 37..55, - value: Attribute( - ExprAttribute { - range: 37..55, - value: Call( - ExprCall { - range: 37..51, - func: Attribute( - ExprAttribute { - range: 37..49, - value: Call( - ExprCall { - range: 37..44, - func: Name( - ExprName { - range: 37..42, - id: "value", - ctx: Load, - }, - ), - arguments: Arguments { - range: 42..44, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "attr", - range: 45..49, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 49..51, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "foo", - range: 52..55, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 56..70, - value: Attribute( - ExprAttribute { - range: 56..70, - value: Attribute( - ExprAttribute { - range: 56..66, - value: Name( - ExprName { - range: 56..61, - id: "value", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 62..66, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "foo", - range: 67..70, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 71..89, - value: Attribute( - ExprAttribute { - range: 71..89, - value: Call( - ExprCall { - range: 71..85, - func: Attribute( - ExprAttribute { - range: 71..83, - value: Name( - ExprName { - range: 72..77, - id: "value", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 79..83, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 83..85, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "foo", - range: 86..89, - }, - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap.new deleted file mode 100644 index 47745f02f1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap.new +++ /dev/null @@ -1,513 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/await.py ---- -## AST - -``` -Module( - ModModule { - range: 0..211, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: Await( - ExprAwait { - range: 0..7, - value: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..19, - value: BinOp( - ExprBinOp { - range: 8..19, - left: Await( - ExprAwait { - range: 8..15, - value: Name( - ExprName { - range: 14..15, - id: "x", - ctx: Load, - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 20..33, - value: BoolOp( - ExprBoolOp { - range: 20..33, - op: And, - values: [ - Await( - ExprAwait { - range: 20..27, - value: Name( - ExprName { - range: 26..27, - id: "a", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 32..33, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 34..43, - value: Await( - ExprAwait { - range: 34..43, - value: Call( - ExprCall { - range: 40..43, - func: Name( - ExprName { - range: 40..41, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 41..43, - args: [], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 44..56, - value: Await( - ExprAwait { - range: 44..56, - value: List( - ExprList { - range: 50..56, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 54..55, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 57..69, - value: Await( - ExprAwait { - range: 57..69, - value: Set( - ExprSet { - range: 63..69, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 64..65, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 67..68, - value: Int( - 4, - ), - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 70..82, - value: Await( - ExprAwait { - range: 70..82, - value: Dict( - ExprDict { - range: 76..82, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 77..78, - id: "i", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 80..81, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 83..93, - value: Tuple( - ExprTuple { - range: 83..93, - elts: [ - Await( - ExprAwait { - range: 83..90, - value: NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 7, - ), - }, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 92..93, - value: Int( - 8, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 94..107, - value: Await( - ExprAwait { - range: 94..107, - value: Tuple( - ExprTuple { - range: 100..107, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 101..102, - value: Int( - 9, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 104..106, - value: Int( - 10, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 108..120, - value: Compare( - ExprCompare { - range: 108..120, - left: Await( - ExprAwait { - range: 108..115, - value: NumberLiteral( - ExprNumberLiteral { - range: 114..115, - value: Int( - 1, - ), - }, - ), - }, - ), - ops: [ - Eq, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 121..146, - value: If( - ExprIf { - range: 121..146, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 132..136, - value: true, - }, - ), - body: Await( - ExprAwait { - range: 121..128, - value: Name( - ExprName { - range: 127..128, - id: "x", - ctx: Load, - }, - ), - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - range: 142..146, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 147..158, - value: Await( - ExprAwait { - range: 147..158, - value: Tuple( - ExprTuple { - range: 153..158, - elts: [ - Starred( - ExprStarred { - range: 154..156, - value: Name( - ExprName { - range: 155..156, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 159..178, - value: Await( - ExprAwait { - range: 159..178, - value: Lambda( - ExprLambda { - range: 166..177, - parameters: Some( - Parameters { - range: 173..174, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 173..174, - parameter: Parameter { - range: 173..174, - name: Identifier { - id: "x", - range: 173..174, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 176..177, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 179..192, - value: BinOp( - ExprBinOp { - range: 179..192, - left: Await( - ExprAwait { - range: 179..186, - value: Name( - ExprName { - range: 185..186, - id: "x", - ctx: Load, - }, - ), - }, - ), - op: Pow, - right: UnaryOp( - ExprUnaryOp { - range: 190..192, - op: USub, - operand: Name( - ExprName { - range: 191..192, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 193..211, - value: BinOp( - ExprBinOp { - range: 193..211, - left: Await( - ExprAwait { - range: 193..200, - value: Name( - ExprName { - range: 199..200, - id: "x", - ctx: Load, - }, - ), - }, - ), - op: Pow, - right: Await( - ExprAwait { - range: 204..211, - value: Name( - ExprName { - range: 210..211, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap.new deleted file mode 100644 index 12a3cb5eb1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap.new +++ /dev/null @@ -1,1047 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/bin_op.py ---- -## AST - -``` -Module( - ModModule { - range: 0..397, - body: [ - Expr( - StmtExpr { - range: 9..14, - value: BinOp( - ExprBinOp { - range: 9..14, - left: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 15..20, - value: BinOp( - ExprBinOp { - range: 15..20, - left: NumberLiteral( - ExprNumberLiteral { - range: 15..16, - value: Int( - 1, - ), - }, - ), - op: Sub, - right: NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..26, - value: BinOp( - ExprBinOp { - range: 21..26, - left: NumberLiteral( - ExprNumberLiteral { - range: 21..22, - value: Int( - 1, - ), - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 27..32, - value: BinOp( - ExprBinOp { - range: 27..32, - left: NumberLiteral( - ExprNumberLiteral { - range: 27..28, - value: Int( - 1, - ), - }, - ), - op: Div, - right: NumberLiteral( - ExprNumberLiteral { - range: 31..32, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 33..39, - value: BinOp( - ExprBinOp { - range: 33..39, - left: NumberLiteral( - ExprNumberLiteral { - range: 33..34, - value: Int( - 1, - ), - }, - ), - op: FloorDiv, - right: NumberLiteral( - ExprNumberLiteral { - range: 38..39, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 40..45, - value: BinOp( - ExprBinOp { - range: 40..45, - left: NumberLiteral( - ExprNumberLiteral { - range: 40..41, - value: Int( - 1, - ), - }, - ), - op: Mod, - right: NumberLiteral( - ExprNumberLiteral { - range: 44..45, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 46..52, - value: BinOp( - ExprBinOp { - range: 46..52, - left: NumberLiteral( - ExprNumberLiteral { - range: 46..47, - value: Int( - 1, - ), - }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 53..58, - value: BinOp( - ExprBinOp { - range: 53..58, - left: NumberLiteral( - ExprNumberLiteral { - range: 53..54, - value: Int( - 1, - ), - }, - ), - op: BitOr, - right: NumberLiteral( - ExprNumberLiteral { - range: 57..58, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 59..64, - value: BinOp( - ExprBinOp { - range: 59..64, - left: NumberLiteral( - ExprNumberLiteral { - range: 59..60, - value: Int( - 1, - ), - }, - ), - op: BitXor, - right: NumberLiteral( - ExprNumberLiteral { - range: 63..64, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 65..70, - value: BinOp( - ExprBinOp { - range: 65..70, - left: NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 1, - ), - }, - ), - op: BitAnd, - right: NumberLiteral( - ExprNumberLiteral { - range: 69..70, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 71..77, - value: BinOp( - ExprBinOp { - range: 71..77, - left: NumberLiteral( - ExprNumberLiteral { - range: 71..72, - value: Int( - 1, - ), - }, - ), - op: RShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 76..77, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 78..84, - value: BinOp( - ExprBinOp { - range: 78..84, - left: NumberLiteral( - ExprNumberLiteral { - range: 78..79, - value: Int( - 1, - ), - }, - ), - op: LShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 85..90, - value: BinOp( - ExprBinOp { - range: 85..90, - left: NumberLiteral( - ExprNumberLiteral { - range: 85..86, - value: Int( - 1, - ), - }, - ), - op: MatMult, - right: NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 110..123, - value: BinOp( - ExprBinOp { - range: 110..123, - left: BinOp( - ExprBinOp { - range: 110..119, - left: BinOp( - ExprBinOp { - range: 110..115, - left: NumberLiteral( - ExprNumberLiteral { - range: 110..111, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 114..115, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Sub, - right: NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 3, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 4, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 124..146, - value: BinOp( - ExprBinOp { - range: 124..146, - left: BinOp( - ExprBinOp { - range: 124..142, - left: BinOp( - ExprBinOp { - range: 124..138, - left: BinOp( - ExprBinOp { - range: 124..133, - left: BinOp( - ExprBinOp { - range: 124..129, - left: NumberLiteral( - ExprNumberLiteral { - range: 124..125, - value: Int( - 1, - ), - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 128..129, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Div, - right: NumberLiteral( - ExprNumberLiteral { - range: 132..133, - value: Int( - 3, - ), - }, - ), - }, - ), - op: FloorDiv, - right: NumberLiteral( - ExprNumberLiteral { - range: 137..138, - value: Int( - 4, - ), - }, - ), - }, - ), - op: MatMult, - right: NumberLiteral( - ExprNumberLiteral { - range: 141..142, - value: Int( - 5, - ), - }, - ), - }, - ), - op: Mod, - right: NumberLiteral( - ExprNumberLiteral { - range: 145..146, - value: Int( - 6, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 147..168, - value: BinOp( - ExprBinOp { - range: 147..168, - left: BinOp( - ExprBinOp { - range: 147..163, - left: BinOp( - ExprBinOp { - range: 147..158, - left: BinOp( - ExprBinOp { - range: 147..153, - left: NumberLiteral( - ExprNumberLiteral { - range: 147..148, - value: Int( - 1, - ), - }, - ), - op: LShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 152..153, - value: Int( - 2, - ), - }, - ), - }, - ), - op: RShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 157..158, - value: Int( - 3, - ), - }, - ), - }, - ), - op: RShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 162..163, - value: Int( - 4, - ), - }, - ), - }, - ), - op: LShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 167..168, - value: Int( - 5, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 193..202, - value: BinOp( - ExprBinOp { - range: 193..202, - left: NumberLiteral( - ExprNumberLiteral { - range: 193..194, - value: Int( - 1, - ), - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 197..202, - left: NumberLiteral( - ExprNumberLiteral { - range: 197..198, - value: Int( - 2, - ), - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 203..212, - value: BinOp( - ExprBinOp { - range: 203..212, - left: BinOp( - ExprBinOp { - range: 203..208, - left: NumberLiteral( - ExprNumberLiteral { - range: 203..204, - value: Int( - 1, - ), - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 207..208, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 211..212, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 213..244, - value: BinOp( - ExprBinOp { - range: 213..244, - left: BinOp( - ExprBinOp { - range: 213..235, - left: BinOp( - ExprBinOp { - range: 213..231, - left: BinOp( - ExprBinOp { - range: 213..223, - left: BinOp( - ExprBinOp { - range: 213..219, - left: NumberLiteral( - ExprNumberLiteral { - range: 213..214, - value: Int( - 1, - ), - }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 218..219, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 222..223, - value: Int( - 3, - ), - }, - ), - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 226..231, - left: NumberLiteral( - ExprNumberLiteral { - range: 226..227, - value: Int( - 4, - ), - }, - ), - op: MatMult, - right: NumberLiteral( - ExprNumberLiteral { - range: 230..231, - value: Int( - 5, - ), - }, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 234..235, - value: Int( - 6, - ), - }, - ), - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 238..244, - left: NumberLiteral( - ExprNumberLiteral { - range: 238..239, - value: Int( - 7, - ), - }, - ), - op: FloorDiv, - right: NumberLiteral( - ExprNumberLiteral { - range: 243..244, - value: Int( - 8, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 270..306, - value: BinOp( - ExprBinOp { - range: 270..306, - left: NumberLiteral( - ExprNumberLiteral { - range: 270..271, - value: Int( - 1, - ), - }, - ), - op: BitOr, - right: BinOp( - ExprBinOp { - range: 274..306, - left: BinOp( - ExprBinOp { - range: 274..279, - left: NumberLiteral( - ExprNumberLiteral { - range: 274..275, - value: Int( - 2, - ), - }, - ), - op: BitAnd, - right: NumberLiteral( - ExprNumberLiteral { - range: 278..279, - value: Int( - 3, - ), - }, - ), - }, - ), - op: BitXor, - right: BinOp( - ExprBinOp { - range: 282..306, - left: BinOp( - ExprBinOp { - range: 282..301, - left: BinOp( - ExprBinOp { - range: 282..291, - left: NumberLiteral( - ExprNumberLiteral { - range: 282..283, - value: Int( - 4, - ), - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 286..291, - left: NumberLiteral( - ExprNumberLiteral { - range: 286..287, - value: Int( - 5, - ), - }, - ), - op: MatMult, - right: NumberLiteral( - ExprNumberLiteral { - range: 290..291, - value: Int( - 6, - ), - }, - ), - }, - ), - }, - ), - op: LShift, - right: BinOp( - ExprBinOp { - range: 295..301, - left: NumberLiteral( - ExprNumberLiteral { - range: 295..296, - value: Int( - 7, - ), - }, - ), - op: FloorDiv, - right: NumberLiteral( - ExprNumberLiteral { - range: 300..301, - value: Int( - 8, - ), - }, - ), - }, - ), - }, - ), - op: RShift, - right: NumberLiteral( - ExprNumberLiteral { - range: 305..306, - value: Int( - 9, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 324..339, - value: BinOp( - ExprBinOp { - range: 324..339, - left: BinOp( - ExprBinOp { - range: 324..335, - left: NumberLiteral( - ExprNumberLiteral { - range: 324..325, - value: Int( - 1, - ), - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 329..334, - left: NumberLiteral( - ExprNumberLiteral { - range: 329..330, - value: Int( - 2, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 333..334, - value: Int( - 3, - ), - }, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 338..339, - value: Int( - 4, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 340..359, - value: BinOp( - ExprBinOp { - range: 340..359, - left: BinOp( - ExprBinOp { - range: 340..345, - left: NumberLiteral( - ExprNumberLiteral { - range: 340..341, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 344..345, - value: Int( - 2, - ), - }, - ), - }, - ), - op: Add, - right: BinOp( - ExprBinOp { - range: 349..358, - left: BinOp( - ExprBinOp { - range: 349..354, - left: NumberLiteral( - ExprNumberLiteral { - range: 349..350, - value: Int( - 3, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 353..354, - value: Int( - 4, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 357..358, - value: Int( - 5, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 390..396, - value: BinOp( - ExprBinOp { - range: 390..396, - left: Name( - ExprName { - range: 390..391, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: UnaryOp( - ExprUnaryOp { - range: 393..396, - op: UAdd, - operand: Name( - ExprName { - range: 395..396, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap.new deleted file mode 100644 index 91215dd29e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap.new +++ /dev/null @@ -1,403 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/bool_op.py ---- -## AST - -``` -Module( - ModModule { - range: 0..142, - body: [ - Expr( - StmtExpr { - range: 0..7, - value: BoolOp( - ExprBoolOp { - range: 0..7, - op: And, - values: [ - Name( - ExprName { - range: 0..1, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 6..7, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 8..21, - value: BoolOp( - ExprBoolOp { - range: 8..21, - op: And, - values: [ - Name( - ExprName { - range: 8..9, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 14..15, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 20..21, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..28, - value: BoolOp( - ExprBoolOp { - range: 22..28, - op: Or, - values: [ - Name( - ExprName { - range: 22..23, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 27..28, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 29..40, - value: BoolOp( - ExprBoolOp { - range: 29..40, - op: Or, - values: [ - Name( - ExprName { - range: 29..30, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 34..35, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 39..40, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 41..53, - value: BoolOp( - ExprBoolOp { - range: 41..53, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 41..48, - op: And, - values: [ - Name( - ExprName { - range: 41..42, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 47..48, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 52..53, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 54..88, - value: BoolOp( - ExprBoolOp { - range: 54..88, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 54..67, - op: And, - values: [ - Name( - ExprName { - range: 54..55, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 60..61, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 66..67, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 71..72, - id: "d", - ctx: Load, - }, - ), - BoolOp( - ExprBoolOp { - range: 76..83, - op: And, - values: [ - Name( - ExprName { - range: 76..77, - id: "e", - ctx: Load, - }, - ), - Name( - ExprName { - range: 82..83, - id: "f", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 87..88, - id: "g", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 89..105, - value: BoolOp( - ExprBoolOp { - range: 89..105, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 89..100, - op: And, - values: [ - Name( - ExprName { - range: 89..90, - id: "a", - ctx: Load, - }, - ), - UnaryOp( - ExprUnaryOp { - range: 95..100, - op: Not, - operand: Name( - ExprName { - range: 99..100, - id: "b", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - Name( - ExprName { - range: 104..105, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 106..124, - value: Yield( - ExprYield { - range: 106..124, - value: Some( - BoolOp( - ExprBoolOp { - range: 112..124, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 112..119, - op: And, - values: [ - Name( - ExprName { - range: 112..113, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 118..119, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 123..124, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 125..141, - value: BoolOp( - ExprBoolOp { - range: 125..141, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 125..136, - op: And, - values: [ - UnaryOp( - ExprUnaryOp { - range: 125..130, - op: Not, - operand: Name( - ExprName { - range: 129..130, - id: "a", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 135..136, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 140..141, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap.new deleted file mode 100644 index a859123843..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap.new +++ /dev/null @@ -1,590 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/call.py ---- -## AST - -``` -Module( - ModModule { - range: 0..349, - body: [ - Expr( - StmtExpr { - range: 114..120, - value: Call( - ExprCall { - range: 114..120, - func: Name( - ExprName { - range: 114..118, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 118..120, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 121..132, - value: Call( - ExprCall { - range: 121..132, - func: Attribute( - ExprAttribute { - range: 121..130, - value: Name( - ExprName { - range: 121..125, - id: "attr", - ctx: Load, - }, - ), - attr: Identifier { - id: "expr", - range: 126..130, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 130..132, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..150, - value: Call( - ExprCall { - range: 133..150, - func: Subscript( - ExprSubscript { - range: 133..148, - value: Name( - ExprName { - range: 133..142, - id: "subscript", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 143..147, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 143..144, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 146..147, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - arguments: Arguments { - range: 148..150, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 151..162, - value: Call( - ExprCall { - range: 151..162, - func: Subscript( - ExprSubscript { - range: 151..160, - value: Name( - ExprName { - range: 151..156, - id: "slice", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 157..159, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - arguments: Arguments { - range: 160..162, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 163..174, - value: Call( - ExprCall { - range: 163..174, - func: List( - ExprList { - range: 163..172, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 164..165, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 167..168, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 170..171, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - arguments: Arguments { - range: 172..174, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 175..186, - value: Call( - ExprCall { - range: 175..186, - func: Tuple( - ExprTuple { - range: 175..184, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 176..177, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 179..180, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 182..183, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - arguments: Arguments { - range: 184..186, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 187..206, - value: Call( - ExprCall { - range: 187..206, - func: Generator( - ExprGenerator { - range: 187..204, - elt: Name( - ExprName { - range: 188..189, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 190..203, - target: Name( - ExprName { - range: 194..195, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 199..203, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - arguments: Arguments { - range: 204..206, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 207..218, - value: Call( - ExprCall { - range: 207..218, - func: Set( - ExprSet { - range: 207..216, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 208..209, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 211..212, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 214..215, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - arguments: Arguments { - range: 216..218, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 219..233, - value: Call( - ExprCall { - range: 219..233, - func: Dict( - ExprDict { - range: 219..231, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 220..221, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 223..224, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 226..227, - value: Int( - 3, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 229..230, - value: Int( - 4, - ), - }, - ), - }, - ], - }, - ), - arguments: Arguments { - range: 231..233, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 234..245, - value: Call( - ExprCall { - range: 234..245, - func: Yield( - ExprYield { - range: 235..242, - value: Some( - Name( - ExprName { - range: 241..242, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - arguments: Arguments { - range: 243..245, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 306..312, - value: Call( - ExprCall { - range: 306..312, - func: BooleanLiteral( - ExprBooleanLiteral { - range: 306..310, - value: true, - }, - ), - arguments: Arguments { - range: 310..312, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 313..320, - value: Call( - ExprCall { - range: 313..320, - func: BooleanLiteral( - ExprBooleanLiteral { - range: 313..318, - value: false, - }, - ), - arguments: Arguments { - range: 318..320, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 321..327, - value: Call( - ExprCall { - range: 321..327, - func: NoneLiteral( - ExprNoneLiteral { - range: 321..325, - }, - ), - arguments: Arguments { - range: 325..327, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 328..338, - value: Call( - ExprCall { - range: 328..338, - func: StringLiteral( - ExprStringLiteral { - range: 328..336, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 328..336, - value: "string", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - arguments: Arguments { - range: 336..338, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 339..342, - value: Call( - ExprCall { - range: 339..342, - func: NumberLiteral( - ExprNumberLiteral { - range: 339..340, - value: Int( - 1, - ), - }, - ), - arguments: Arguments { - range: 340..342, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 343..348, - value: Call( - ExprCall { - range: 343..348, - func: NumberLiteral( - ExprNumberLiteral { - range: 343..346, - value: Float( - 1.0, - ), - }, - ), - arguments: Arguments { - range: 346..348, - args: [], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap.new deleted file mode 100644 index 7517ff9952..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap.new +++ /dev/null @@ -1,698 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/compare.py ---- -## AST - -``` -Module( - ModModule { - range: 0..542, - body: [ - Expr( - StmtExpr { - range: 9..15, - value: Compare( - ExprCompare { - range: 9..15, - left: Name( - ExprName { - range: 9..10, - id: "a", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 14..15, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..21, - value: Compare( - ExprCompare { - range: 16..21, - left: Name( - ExprName { - range: 16..17, - id: "b", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - Name( - ExprName { - range: 20..21, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..27, - value: Compare( - ExprCompare { - range: 22..27, - left: Name( - ExprName { - range: 22..23, - id: "b", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 26..27, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..34, - value: Compare( - ExprCompare { - range: 28..34, - left: Name( - ExprName { - range: 28..29, - id: "a", - ctx: Load, - }, - ), - ops: [ - GtE, - ], - comparators: [ - Name( - ExprName { - range: 33..34, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 35..41, - value: Compare( - ExprCompare { - range: 35..41, - left: Name( - ExprName { - range: 35..36, - id: "a", - ctx: Load, - }, - ), - ops: [ - LtE, - ], - comparators: [ - Name( - ExprName { - range: 40..41, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 42..48, - value: Compare( - ExprCompare { - range: 42..48, - left: Name( - ExprName { - range: 42..43, - id: "a", - ctx: Load, - }, - ), - ops: [ - NotEq, - ], - comparators: [ - Name( - ExprName { - range: 47..48, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..55, - value: Compare( - ExprCompare { - range: 49..55, - left: Name( - ExprName { - range: 49..50, - id: "a", - ctx: Load, - }, - ), - ops: [ - Is, - ], - comparators: [ - Name( - ExprName { - range: 54..55, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 56..62, - value: Compare( - ExprCompare { - range: 56..62, - left: Name( - ExprName { - range: 56..57, - id: "a", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 61..62, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 63..73, - value: Compare( - ExprCompare { - range: 63..73, - left: Name( - ExprName { - range: 63..64, - id: "a", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 72..73, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 74..84, - value: Compare( - ExprCompare { - range: 74..84, - left: Name( - ExprName { - range: 74..75, - id: "a", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 83..84, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 110..156, - value: Compare( - ExprCompare { - range: 110..156, - left: Name( - ExprName { - range: 110..111, - id: "a", - ctx: Load, - }, - ), - ops: [ - NotIn, - IsNot, - NotIn, - NotIn, - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 119..120, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 128..129, - id: "c", - ctx: Load, - }, - ), - Name( - ExprName { - range: 137..138, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 146..147, - id: "e", - ctx: Load, - }, - ), - Name( - ExprName { - range: 155..156, - id: "f", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 177..203, - value: Compare( - ExprCompare { - range: 177..203, - left: BinOp( - ExprBinOp { - range: 177..182, - left: Name( - ExprName { - range: 177..178, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 181..182, - id: "b", - ctx: Load, - }, - ), - }, - ), - ops: [ - Lt, - NotIn, - ], - comparators: [ - BinOp( - ExprBinOp { - range: 185..190, - left: Name( - ExprName { - range: 185..186, - id: "c", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 189..190, - id: "d", - ctx: Load, - }, - ), - }, - ), - BinOp( - ExprBinOp { - range: 198..203, - left: Name( - ExprName { - range: 198..199, - id: "e", - ctx: Load, - }, - ), - op: BitAnd, - right: Name( - ExprName { - range: 202..203, - id: "f", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 379..393, - value: UnaryOp( - ExprUnaryOp { - range: 379..393, - op: Not, - operand: Compare( - ExprCompare { - range: 383..393, - left: Name( - ExprName { - range: 383..384, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 392..393, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 395..416, - value: BoolOp( - ExprBoolOp { - range: 395..416, - op: Or, - values: [ - Name( - ExprName { - range: 395..396, - id: "x", - ctx: Load, - }, - ), - BoolOp( - ExprBoolOp { - range: 400..416, - op: And, - values: [ - Compare( - ExprCompare { - range: 400..410, - left: Name( - ExprName { - range: 400..401, - id: "y", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 409..410, - id: "z", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 415..416, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 417..429, - value: Compare( - ExprCompare { - range: 417..429, - left: Name( - ExprName { - range: 417..418, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Await( - ExprAwait { - range: 422..429, - value: Name( - ExprName { - range: 428..429, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 430..446, - value: Compare( - ExprCompare { - range: 430..446, - left: Name( - ExprName { - range: 430..431, - id: "x", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Await( - ExprAwait { - range: 439..446, - value: Name( - ExprName { - range: 445..446, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 489..541, - value: Compare( - ExprCompare { - range: 489..541, - left: Name( - ExprName { - range: 489..490, - id: "a", - ctx: Load, - }, - ), - ops: [ - Lt, - Eq, - Gt, - Is, - NotIn, - IsNot, - LtE, - GtE, - NotEq, - ], - comparators: [ - Name( - ExprName { - range: 493..494, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 498..499, - id: "c", - ctx: Load, - }, - ), - Name( - ExprName { - range: 502..503, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 507..508, - id: "e", - ctx: Load, - }, - ), - Name( - ExprName { - range: 516..517, - id: "f", - ctx: Load, - }, - ), - Name( - ExprName { - range: 525..526, - id: "g", - ctx: Load, - }, - ), - Name( - ExprName { - range: 530..531, - id: "h", - ctx: Load, - }, - ), - Name( - ExprName { - range: 535..536, - id: "i", - ctx: Load, - }, - ), - Name( - ExprName { - range: 540..541, - id: "j", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap.new deleted file mode 100644 index 4eb2784604..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap.new +++ /dev/null @@ -1,1231 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/dictionary.py ---- -## AST - -``` -Module( - ModModule { - range: 0..622, - body: [ - Expr( - StmtExpr { - range: 9..11, - value: Dict( - ExprDict { - range: 9..11, - items: [], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..18, - value: Dict( - ExprDict { - range: 12..18, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 19..43, - value: Dict( - ExprDict { - range: 19..43, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 26..27, - id: "a", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 29..30, - value: Int( - 1, - ), - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 32..33, - id: "b", - ctx: Load, - }, - ), - ), - value: StringLiteral( - ExprStringLiteral { - range: 35..42, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 35..42, - value: "hello", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 66..69, - value: Dict( - ExprDict { - range: 66..69, - items: [], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 70..100, - value: Dict( - ExprDict { - range: 70..100, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 76..77, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 90..91, - value: Int( - 3, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 4, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 111..132, - value: Dict( - ExprDict { - range: 111..132, - items: [ - DictItem { - key: Some( - Dict( - ExprDict { - range: 112..118, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 113..114, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 116..117, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - ), - value: Dict( - ExprDict { - range: 120..131, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 121..122, - value: Int( - 3, - ), - }, - ), - ), - value: Dict( - ExprDict { - range: 124..130, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 125..126, - value: Int( - 4, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 128..129, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - }, - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 155..171, - value: Dict( - ExprDict { - range: 155..171, - items: [ - DictItem { - key: Some( - Lambda( - ExprLambda { - range: 156..167, - parameters: Some( - Parameters { - range: 163..164, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 163..164, - parameter: Parameter { - range: 163..164, - name: Identifier { - id: "x", - range: 163..164, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 166..167, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 169..170, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 172..202, - value: Dict( - ExprDict { - range: 172..202, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 173..176, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 173..176, - value: "A", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: Lambda( - ExprLambda { - range: 178..192, - parameters: Some( - Parameters { - range: 185..186, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 185..186, - parameter: Parameter { - range: 185..186, - name: Identifier { - id: "p", - range: 185..186, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NoneLiteral( - ExprNoneLiteral { - range: 188..192, - }, - ), - }, - ), - }, - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 194..197, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 194..197, - value: "B", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: Name( - ExprName { - range: 199..200, - id: "C", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 224..237, - value: Dict( - ExprDict { - range: 224..237, - items: [ - DictItem { - key: Some( - Named( - ExprNamed { - range: 226..232, - target: Name( - ExprName { - range: 226..227, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 231..232, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - value: Name( - ExprName { - range: 235..236, - id: "y", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 238..258, - value: Dict( - ExprDict { - range: 238..258, - items: [ - DictItem { - key: Some( - Named( - ExprNamed { - range: 240..246, - target: Name( - ExprName { - range: 240..241, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 245..246, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - value: Named( - ExprNamed { - range: 250..256, - target: Name( - ExprName { - range: 250..251, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 255..256, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 284..289, - value: Dict( - ExprDict { - range: 284..289, - items: [ - DictItem { - key: None, - value: Name( - ExprName { - range: 287..288, - id: "d", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 290..301, - value: Dict( - ExprDict { - range: 290..301, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 291..292, - id: "a", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 294..295, - id: "b", - ctx: Load, - }, - ), - }, - DictItem { - key: None, - value: Name( - ExprName { - range: 299..300, - id: "d", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 302..312, - value: Dict( - ExprDict { - range: 302..312, - items: [ - DictItem { - key: None, - value: Name( - ExprName { - range: 305..306, - id: "a", - ctx: Load, - }, - ), - }, - DictItem { - key: None, - value: Name( - ExprName { - range: 310..311, - id: "b", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 313..338, - value: Dict( - ExprDict { - range: 313..338, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 314..317, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 314..317, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: StringLiteral( - ExprStringLiteral { - range: 319..322, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 319..322, - value: "b", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - DictItem { - key: None, - value: Name( - ExprName { - range: 326..327, - id: "c", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 329..332, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 329..332, - value: "d", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: StringLiteral( - ExprStringLiteral { - range: 334..337, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 334..337, - value: "e", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 339..367, - value: Dict( - ExprDict { - range: 339..367, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 340..341, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 343..344, - value: Int( - 2, - ), - }, - ), - }, - DictItem { - key: None, - value: Dict( - ExprDict { - range: 348..366, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 349..357, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 349..357, - value: "nested", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: StringLiteral( - ExprStringLiteral { - range: 359..365, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 359..365, - value: "dict", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 368..393, - value: Dict( - ExprDict { - range: 368..393, - items: [ - DictItem { - key: Some( - BinOp( - ExprBinOp { - range: 369..374, - left: Name( - ExprName { - range: 369..370, - id: "x", - ctx: Load, - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 373..374, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - value: BinOp( - ExprBinOp { - range: 376..382, - left: Name( - ExprName { - range: 376..377, - id: "y", - ctx: Load, - }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 381..382, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - DictItem { - key: None, - value: Call( - ExprCall { - range: 386..392, - func: Name( - ExprName { - range: 386..390, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 390..392, - args: [], - keywords: [], - }, - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 460..471, - value: Dict( - ExprDict { - range: 460..471, - items: [ - DictItem { - key: None, - value: UnaryOp( - ExprUnaryOp { - range: 464..469, - op: Not, - operand: Name( - ExprName { - range: 468..469, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 494..515, - value: Dict( - ExprDict { - range: 494..515, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 495..496, - value: Int( - 1, - ), - }, - ), - ), - value: If( - ExprIf { - range: 498..514, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 503..507, - value: true, - }, - ), - body: Name( - ExprName { - range: 498..499, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 513..514, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 516..575, - value: DictComp( - ExprDictComp { - range: 516..575, - key: If( - ExprIf { - range: 517..533, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 522..526, - value: true, - }, - ), - body: Name( - ExprName { - range: 517..518, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 532..533, - id: "y", - ctx: Load, - }, - ), - }, - ), - value: Name( - ExprName { - range: 535..536, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 537..555, - target: Name( - ExprName { - range: 541..542, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 546..555, - func: Name( - ExprName { - range: 546..551, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 551..555, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 552..554, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - Comprehension { - range: 556..574, - target: Name( - ExprName { - range: 560..561, - id: "y", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 565..574, - func: Name( - ExprName { - range: 565..570, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 570..574, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 571..573, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 576..600, - value: Dict( - ExprDict { - range: 576..600, - items: [ - DictItem { - key: Some( - Set( - ExprSet { - range: 577..583, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 578..579, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 581..582, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 585..586, - value: Int( - 3, - ), - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 588..589, - id: "x", - ctx: Load, - }, - ), - ), - value: Dict( - ExprDict { - range: 591..598, - items: [ - DictItem { - key: Some( - NumberLiteral( - ExprNumberLiteral { - range: 592..593, - value: Int( - 1, - ), - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 595..596, - value: Int( - 2, - ), - }, - ), - }, - ], - }, - ), - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 601..621, - value: Dict( - ExprDict { - range: 601..621, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 603..604, - id: "x", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 608..609, - id: "y", - ctx: Load, - }, - ), - }, - DictItem { - key: Some( - Name( - ExprName { - range: 613..614, - id: "z", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 618..619, - id: "a", - ctx: Load, - }, - ), - }, - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap.new deleted file mode 100644 index e4e593371a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap.new +++ /dev/null @@ -1,1000 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/dictionary_comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..589, - body: [ - Expr( - StmtExpr { - range: 0..22, - value: SetComp( - ExprSetComp { - range: 0..22, - elt: Name( - ExprName { - range: 1..2, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3..21, - target: Name( - ExprName { - range: 7..8, - id: "y", - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 12..21, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 23..42, - value: DictComp( - ExprDictComp { - range: 23..42, - key: Name( - ExprName { - range: 24..26, - id: "x1", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 28..30, - id: "x2", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 31..41, - target: Name( - ExprName { - range: 35..36, - id: "y", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 40..41, - id: "z", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 43..73, - value: DictComp( - ExprDictComp { - range: 43..73, - key: BinOp( - ExprBinOp { - range: 44..49, - left: Name( - ExprName { - range: 44..45, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 48..49, - value: Int( - 1, - ), - }, - ), - }, - ), - value: StringLiteral( - ExprStringLiteral { - range: 51..54, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 51..54, - value: "x", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - generators: [ - Comprehension { - range: 55..72, - target: Name( - ExprName { - range: 59..60, - id: "i", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 64..72, - func: Name( - ExprName { - range: 64..69, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 69..72, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 70..71, - value: Int( - 5, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 74..122, - value: DictComp( - ExprDictComp { - range: 74..122, - key: Name( - ExprName { - range: 75..76, - id: "b", - ctx: Load, - }, - ), - value: BinOp( - ExprBinOp { - range: 78..83, - left: Name( - ExprName { - range: 78..79, - id: "c", - ctx: Load, - }, - ), - op: Mult, - right: NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 2, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 84..121, - target: Name( - ExprName { - range: 88..89, - id: "c", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 93..94, - id: "d", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 98..104, - left: Name( - ExprName { - range: 98..99, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 103..104, - id: "w", - ctx: Load, - }, - ), - ], - }, - ), - BoolOp( - ExprBoolOp { - range: 108..116, - op: And, - values: [ - Name( - ExprName { - range: 108..109, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 114..116, - id: "yy", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 120..121, - id: "z", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 123..176, - value: DictComp( - ExprDictComp { - range: 123..176, - key: Name( - ExprName { - range: 124..125, - id: "a", - ctx: Load, - }, - ), - value: BinOp( - ExprBinOp { - range: 127..133, - left: Name( - ExprName { - range: 127..128, - id: "a", - ctx: Load, - }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 132..133, - value: Int( - 2, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 134..155, - target: Name( - ExprName { - range: 138..139, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 143..144, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 148..155, - op: And, - values: [ - Name( - ExprName { - range: 148..149, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 154..155, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 156..175, - target: Name( - ExprName { - range: 160..161, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 165..166, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 170..175, - left: Name( - ExprName { - range: 170..171, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 174..175, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 177..231, - value: DictComp( - ExprDictComp { - range: 177..231, - key: Name( - ExprName { - range: 178..179, - id: "a", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 181..182, - id: "b", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 183..204, - target: Name( - ExprName { - range: 187..188, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 192..193, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 197..204, - op: And, - values: [ - Name( - ExprName { - range: 197..198, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 203..204, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 205..230, - target: Name( - ExprName { - range: 215..216, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 220..221, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 225..230, - left: Name( - ExprName { - range: 225..226, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 229..230, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: true, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 232..252, - value: DictComp( - ExprDictComp { - range: 232..252, - key: Name( - ExprName { - range: 233..234, - id: "a", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 236..237, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 238..251, - target: Tuple( - ExprTuple { - range: 242..246, - elts: [ - Name( - ExprName { - range: 242..243, - id: "b", - ctx: Store, - }, - ), - Name( - ExprName { - range: 245..246, - id: "c", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - iter: Name( - ExprName { - range: 250..251, - id: "d", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 391..416, - value: DictComp( - ExprDictComp { - range: 391..416, - key: Name( - ExprName { - range: 392..393, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 395..396, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 397..415, - target: Name( - ExprName { - range: 401..402, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 407..414, - value: Some( - Name( - ExprName { - range: 413..414, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 417..447, - value: DictComp( - ExprDictComp { - range: 417..447, - key: Name( - ExprName { - range: 418..419, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 421..422, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 423..446, - target: Name( - ExprName { - range: 427..428, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 433..445, - value: Name( - ExprName { - range: 444..445, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 448..477, - value: DictComp( - ExprDictComp { - range: 448..477, - key: Name( - ExprName { - range: 449..450, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 452..453, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 454..476, - target: Name( - ExprName { - range: 458..459, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 464..475, - parameters: Some( - Parameters { - range: 471..472, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 471..472, - parameter: Parameter { - range: 471..472, - name: Identifier { - id: "y", - range: 471..472, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 474..475, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 478..511, - value: DictComp( - ExprDictComp { - range: 478..511, - key: Name( - ExprName { - range: 479..480, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 482..483, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 484..510, - target: Name( - ExprName { - range: 488..489, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 493..497, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 502..509, - value: Some( - Name( - ExprName { - range: 508..509, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 512..550, - value: DictComp( - ExprDictComp { - range: 512..550, - key: Name( - ExprName { - range: 513..514, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 516..517, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 518..549, - target: Name( - ExprName { - range: 522..523, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 527..531, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 536..548, - value: Name( - ExprName { - range: 547..548, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 551..588, - value: DictComp( - ExprDictComp { - range: 551..588, - key: Name( - ExprName { - range: 552..553, - id: "x", - ctx: Load, - }, - ), - value: Name( - ExprName { - range: 555..556, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 557..587, - target: Name( - ExprName { - range: 561..562, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 566..570, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 575..586, - parameters: Some( - Parameters { - range: 582..583, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 582..583, - parameter: Parameter { - range: 582..583, - name: Identifier { - id: "y", - range: 582..583, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 585..586, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap.new deleted file mode 100644 index a423e07d4f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap.new +++ /dev/null @@ -1,2703 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/f_string.py ---- -## AST - -``` -Module( - ModModule { - range: 0..979, - body: [ - Expr( - StmtExpr { - range: 18..21, - value: FString( - ExprFString { - range: 18..21, - value: FStringValue { - inner: Single( - FString( - FString { - range: 18..21, - elements: [], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..25, - value: FString( - ExprFString { - range: 22..25, - value: FStringValue { - inner: Single( - FString( - FString { - range: 22..25, - elements: [], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 26..29, - value: FString( - ExprFString { - range: 26..29, - value: FStringValue { - inner: Single( - FString( - FString { - range: 26..29, - elements: [], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 30..37, - value: FString( - ExprFString { - range: 30..37, - value: FStringValue { - inner: Single( - FString( - FString { - range: 30..37, - elements: [], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 38..45, - value: FString( - ExprFString { - range: 38..45, - value: FStringValue { - inner: Single( - FString( - FString { - range: 38..45, - elements: [], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 47..56, - value: FString( - ExprFString { - range: 47..56, - value: FStringValue { - inner: Single( - FString( - FString { - range: 47..56, - elements: [ - Expression( - FStringExpressionElement { - range: 49..55, - expression: StringLiteral( - ExprStringLiteral { - range: 50..54, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 50..54, - value: " f", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 57..67, - value: FString( - ExprFString { - range: 57..67, - value: FStringValue { - inner: Single( - FString( - FString { - range: 57..67, - elements: [ - Expression( - FStringExpressionElement { - range: 59..66, - expression: Name( - ExprName { - range: 60..63, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: Str, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 68..75, - value: FString( - ExprFString { - range: 68..75, - value: FStringValue { - inner: Single( - FString( - FString { - range: 68..75, - elements: [ - Expression( - FStringExpressionElement { - range: 70..74, - expression: Tuple( - ExprTuple { - range: 71..73, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 71..72, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 76..86, - value: FString( - ExprFString { - range: 76..86, - value: FStringValue { - inner: Single( - FString( - FString { - range: 76..86, - elements: [ - Expression( - FStringExpressionElement { - range: 78..85, - expression: Compare( - ExprCompare { - range: 79..83, - left: NumberLiteral( - ExprNumberLiteral { - range: 79..80, - value: Int( - 3, - ), - }, - ), - ops: [ - NotEq, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 4, - ), - }, - ), - ], - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 84..84, - elements: [], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 87..102, - value: FString( - ExprFString { - range: 87..102, - value: FStringValue { - inner: Single( - FString( - FString { - range: 87..102, - elements: [ - Expression( - FStringExpressionElement { - range: 89..101, - expression: NumberLiteral( - ExprNumberLiteral { - range: 90..91, - value: Int( - 3, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 92..100, - elements: [ - Expression( - FStringExpressionElement { - range: 92..97, - expression: StringLiteral( - ExprStringLiteral { - range: 93..96, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 93..96, - value: "}", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 97..100, - value: ">10", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 103..118, - value: FString( - ExprFString { - range: 103..118, - value: FStringValue { - inner: Single( - FString( - FString { - range: 103..118, - elements: [ - Expression( - FStringExpressionElement { - range: 105..117, - expression: NumberLiteral( - ExprNumberLiteral { - range: 106..107, - value: Int( - 3, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 108..116, - elements: [ - Expression( - FStringExpressionElement { - range: 108..113, - expression: StringLiteral( - ExprStringLiteral { - range: 109..112, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 109..112, - value: "{", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 113..116, - value: ">10", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 119..133, - value: FString( - ExprFString { - range: 119..133, - value: FStringValue { - inner: Single( - FString( - FString { - range: 119..133, - elements: [ - Expression( - FStringExpressionElement { - range: 121..132, - expression: Name( - ExprName { - range: 124..127, - id: "foo", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: " ", - trailing: " = ", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 134..154, - value: FString( - ExprFString { - range: 134..154, - value: FStringValue { - inner: Single( - FString( - FString { - range: 134..154, - elements: [ - Expression( - FStringExpressionElement { - range: 136..153, - expression: Name( - ExprName { - range: 139..142, - id: "foo", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: " ", - trailing: " = ", - }, - ), - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 147..152, - elements: [ - Literal( - FStringLiteralElement { - range: 147..152, - value: ".3f ", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 155..173, - value: FString( - ExprFString { - range: 155..173, - value: FStringValue { - inner: Single( - FString( - FString { - range: 155..173, - elements: [ - Expression( - FStringExpressionElement { - range: 157..172, - expression: Name( - ExprName { - range: 160..163, - id: "foo", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: " ", - trailing: " = ", - }, - ), - conversion: Str, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 174..190, - value: FString( - ExprFString { - range: 174..190, - value: FStringValue { - inner: Single( - FString( - FString { - range: 174..190, - elements: [ - Expression( - FStringExpressionElement { - range: 176..189, - expression: Tuple( - ExprTuple { - range: 179..183, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 179..180, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 182..183, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - debug_text: Some( - DebugText { - leading: " ", - trailing: " = ", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 191..217, - value: FString( - ExprFString { - range: 191..217, - value: FStringValue { - inner: Single( - FString( - FString { - range: 191..217, - elements: [ - Expression( - FStringExpressionElement { - range: 193..216, - expression: FString( - ExprFString { - range: 194..210, - value: FStringValue { - inner: Single( - FString( - FString { - range: 194..210, - elements: [ - Expression( - FStringExpressionElement { - range: 196..209, - expression: NumberLiteral( - ExprNumberLiteral { - range: 197..203, - value: Float( - 3.1415, - ), - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 205..208, - elements: [ - Literal( - FStringLiteralElement { - range: 205..208, - value: ".1f", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 211..215, - elements: [ - Literal( - FStringLiteralElement { - range: 211..215, - value: "*^20", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 219..253, - value: Dict( - ExprDict { - range: 219..253, - items: [ - DictItem { - key: Some( - FString( - ExprFString { - range: 220..248, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 220..226, - value: "foo ", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 227..242, - elements: [ - Literal( - FStringLiteralElement { - range: 229..233, - value: "bar ", - }, - ), - Expression( - FStringExpressionElement { - range: 233..240, - expression: BinOp( - ExprBinOp { - range: 234..239, - left: Name( - ExprName { - range: 234..235, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 238..239, - id: "y", - ctx: Load, - }, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 240..241, - value: " ", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 243..248, - value: "baz", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 250..252, - value: Int( - 10, - ), - }, - ), - }, - ], - }, - ), - }, - ), - Match( - StmtMatch { - range: 254..345, - subject: Name( - ExprName { - range: 260..263, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 269..293, - pattern: MatchValue( - PatternMatchValue { - range: 274..279, - value: StringLiteral( - ExprStringLiteral { - range: 274..279, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 274..279, - value: "one", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 289..293, - }, - ), - ], - }, - MatchCase { - range: 298..345, - pattern: MatchValue( - PatternMatchValue { - range: 303..331, - value: StringLiteral( - ExprStringLiteral { - range: 303..331, - value: StringLiteralValue { - inner: Concatenated( - ConcatenatedStringLiteral { - strings: [ - StringLiteral { - range: 303..316, - value: "implicitly ", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - StringLiteral { - range: 317..331, - value: "concatenated", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ], - value: "implicitly concatenated", - }, - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 341..345, - }, - ), - ], - }, - ], - }, - ), - Expr( - StmtExpr { - range: 347..364, - value: FString( - ExprFString { - range: 347..364, - value: FStringValue { - inner: Single( - FString( - FString { - range: 347..364, - elements: [ - Literal( - FStringLiteralElement { - range: 349..350, - value: "\\", - }, - ), - Expression( - FStringExpressionElement { - range: 350..355, - expression: Name( - ExprName { - range: 351..354, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 355..356, - value: "\\", - }, - ), - Expression( - FStringExpressionElement { - range: 356..363, - expression: Name( - ExprName { - range: 357..360, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 361..362, - elements: [ - Literal( - FStringLiteralElement { - range: 361..362, - value: "\\", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 365..379, - value: FString( - ExprFString { - range: 365..379, - value: FStringValue { - inner: Single( - FString( - FString { - range: 365..379, - elements: [ - Literal( - FStringLiteralElement { - range: 367..378, - value: "\\{foo\\}", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 380..420, - value: FString( - ExprFString { - range: 380..420, - value: FStringValue { - inner: Single( - FString( - FString { - range: 380..420, - elements: [ - Expression( - FStringExpressionElement { - range: 384..417, - expression: Name( - ExprName { - range: 390..393, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 394..416, - elements: [ - Literal( - FStringLiteralElement { - range: 394..416, - value: "x\n y\n z\n", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: true, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 421..439, - value: FString( - ExprFString { - range: 421..439, - value: FStringValue { - inner: Single( - FString( - FString { - range: 421..439, - elements: [ - Expression( - FStringExpressionElement { - range: 423..438, - expression: Name( - ExprName { - range: 428..431, - id: "foo", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: " ( ", - trailing: " ) = ", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 441..486, - value: FString( - ExprFString { - range: 441..486, - value: FStringValue { - inner: Single( - FString( - FString { - range: 441..486, - elements: [ - Literal( - FStringLiteralElement { - range: 443..450, - value: "normal ", - }, - ), - Expression( - FStringExpressionElement { - range: 450..455, - expression: Name( - ExprName { - range: 451..454, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 455..468, - value: " {another} ", - }, - ), - Expression( - FStringExpressionElement { - range: 468..473, - expression: Name( - ExprName { - range: 469..472, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 473..476, - value: " {", - }, - ), - Expression( - FStringExpressionElement { - range: 476..483, - expression: Name( - ExprName { - range: 477..482, - id: "three", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 483..485, - value: "}", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 487..529, - value: FString( - ExprFString { - range: 487..529, - value: FStringValue { - inner: Single( - FString( - FString { - range: 487..529, - elements: [ - Literal( - FStringLiteralElement { - range: 489..496, - value: "normal ", - }, - ), - Expression( - FStringExpressionElement { - range: 496..503, - expression: Name( - ExprName { - range: 497..500, - id: "foo", - ctx: Load, - }, - ), - debug_text: None, - conversion: Ascii, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 503..504, - value: " ", - }, - ), - Expression( - FStringExpressionElement { - range: 504..511, - expression: Name( - ExprName { - range: 505..508, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: Str, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 511..512, - value: " ", - }, - ), - Expression( - FStringExpressionElement { - range: 512..519, - expression: Name( - ExprName { - range: 513..516, - id: "baz", - ctx: Load, - }, - ), - debug_text: None, - conversion: Repr, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 519..520, - value: " ", - }, - ), - Expression( - FStringExpressionElement { - range: 520..528, - expression: Name( - ExprName { - range: 521..527, - id: "foobar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 530..549, - value: FString( - ExprFString { - range: 530..549, - value: FStringValue { - inner: Single( - FString( - FString { - range: 530..549, - elements: [ - Literal( - FStringLiteralElement { - range: 532..539, - value: "normal ", - }, - ), - Expression( - FStringExpressionElement { - range: 539..548, - expression: Name( - ExprName { - range: 540..541, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 542..547, - elements: [ - Literal( - FStringLiteralElement { - range: 542..547, - value: "y + 2", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 550..568, - value: FString( - ExprFString { - range: 550..568, - value: FStringValue { - inner: Single( - FString( - FString { - range: 550..568, - elements: [ - Expression( - FStringExpressionElement { - range: 552..567, - expression: Name( - ExprName { - range: 553..554, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 555..566, - elements: [ - Expression( - FStringExpressionElement { - range: 555..566, - expression: Call( - ExprCall { - range: 556..565, - func: Attribute( - ExprAttribute { - range: 556..563, - value: Set( - ExprSet { - range: 556..559, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 557..558, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - attr: Identifier { - id: "pop", - range: 560..563, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 563..565, - args: [], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 569..588, - value: FString( - ExprFString { - range: 569..588, - value: FStringValue { - inner: Single( - FString( - FString { - range: 569..588, - elements: [ - Expression( - FStringExpressionElement { - range: 571..587, - expression: Lambda( - ExprLambda { - range: 573..585, - parameters: Some( - Parameters { - range: 580..581, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 580..581, - parameter: Parameter { - range: 580..581, - name: Identifier { - id: "x", - range: 580..581, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Set( - ExprSet { - range: 582..585, - elts: [ - Name( - ExprName { - range: 583..584, - id: "x", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 589..597, - value: FString( - ExprFString { - range: 589..597, - value: FStringValue { - inner: Single( - FString( - FString { - range: 589..597, - elements: [ - Expression( - FStringExpressionElement { - range: 591..596, - expression: Name( - ExprName { - range: 592..593, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: " =", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 598..611, - value: FString( - ExprFString { - range: 598..611, - value: FStringValue { - inner: Single( - FString( - FString { - range: 598..611, - elements: [ - Expression( - FStringExpressionElement { - range: 600..610, - expression: Name( - ExprName { - range: 605..606, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: " ", - trailing: " = ", - }, - ), - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 612..621, - value: FString( - ExprFString { - range: 612..621, - value: FStringValue { - inner: Single( - FString( - FString { - range: 612..621, - elements: [ - Expression( - FStringExpressionElement { - range: 614..620, - expression: Name( - ExprName { - range: 615..616, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: "=", - }, - ), - conversion: Ascii, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 622..636, - value: FString( - ExprFString { - range: 622..636, - value: FStringValue { - inner: Single( - FString( - FString { - range: 622..636, - elements: [ - Expression( - FStringExpressionElement { - range: 624..635, - expression: Name( - ExprName { - range: 625..626, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 627..634, - elements: [ - Literal( - FStringLiteralElement { - range: 627..634, - value: ".3f!r =", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 637..653, - value: FString( - ExprFString { - range: 637..653, - value: FStringValue { - inner: Single( - FString( - FString { - range: 637..653, - elements: [ - Expression( - FStringExpressionElement { - range: 639..652, - expression: Name( - ExprName { - range: 640..641, - id: "x", - ctx: Load, - }, - ), - debug_text: Some( - DebugText { - leading: "", - trailing: " = ", - }, - ), - conversion: Repr, - format_spec: Some( - FStringFormatSpec { - range: 648..651, - elements: [ - Literal( - FStringLiteralElement { - range: 648..651, - value: ".3f", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 654..667, - value: FString( - ExprFString { - range: 654..667, - value: FStringValue { - inner: Single( - FString( - FString { - range: 654..667, - elements: [ - Expression( - FStringExpressionElement { - range: 656..666, - expression: Name( - ExprName { - range: 657..658, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 659..665, - elements: [ - Literal( - FStringLiteralElement { - range: 659..665, - value: ".3f=!r", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 668..682, - value: FString( - ExprFString { - range: 668..682, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 668..675, - value: "hello", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 676..682, - elements: [ - Expression( - FStringExpressionElement { - range: 678..681, - expression: Name( - ExprName { - range: 679..680, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 683..696, - value: FString( - ExprFString { - range: 683..696, - value: FStringValue { - inner: Concatenated( - [ - FString( - FString { - range: 683..689, - elements: [ - Expression( - FStringExpressionElement { - range: 685..688, - expression: Name( - ExprName { - range: 686..687, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 690..696, - elements: [ - Expression( - FStringExpressionElement { - range: 692..695, - expression: Name( - ExprName { - range: 693..694, - id: "y", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 697..711, - value: FString( - ExprFString { - range: 697..711, - value: FStringValue { - inner: Concatenated( - [ - FString( - FString { - range: 697..703, - elements: [ - Expression( - FStringExpressionElement { - range: 699..702, - expression: Name( - ExprName { - range: 700..701, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 704..711, - value: "world", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 712..756, - value: FString( - ExprFString { - range: 712..756, - value: FStringValue { - inner: Single( - FString( - FString { - range: 712..756, - elements: [ - Literal( - FStringLiteralElement { - range: 714..739, - value: "Invalid args in command: ", - }, - ), - Expression( - FStringExpressionElement { - range: 739..755, - expression: Tuple( - ExprTuple { - range: 740..754, - elts: [ - Name( - ExprName { - range: 740..747, - id: "command", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 749..754, - value: Name( - ExprName { - range: 750..754, - id: "args", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 757..775, - value: FString( - ExprFString { - range: 757..775, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 757..762, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 763..769, - elements: [ - Expression( - FStringExpressionElement { - range: 765..768, - expression: Name( - ExprName { - range: 766..767, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 770..775, - value: "bar", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 776..825, - value: FString( - ExprFString { - range: 782..823, - value: FStringValue { - inner: Concatenated( - [ - FString( - FString { - range: 782..786, - elements: [ - Literal( - FStringLiteralElement { - range: 784..785, - value: "a", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 791..795, - elements: [ - Literal( - FStringLiteralElement { - range: 793..794, - value: "b", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 800..803, - value: "c", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 808..813, - elements: [ - Literal( - FStringLiteralElement { - range: 811..812, - value: "d", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Raw { - uppercase_r: false, - }, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 818..823, - elements: [ - Literal( - FStringLiteralElement { - range: 821..822, - value: "e", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Raw { - uppercase_r: false, - }, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 850..879, - value: FString( - ExprFString { - range: 850..879, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 850..856, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Unicode, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 857..865, - elements: [ - Expression( - FStringExpressionElement { - range: 859..864, - expression: Name( - ExprName { - range: 860..863, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 866..871, - value: "baz", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 872..879, - value: " some", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 880..909, - value: FString( - ExprFString { - range: 880..909, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 880..885, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 886..894, - elements: [ - Expression( - FStringExpressionElement { - range: 888..893, - expression: Name( - ExprName { - range: 889..892, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 895..901, - value: "baz", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Unicode, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 902..909, - value: " some", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 910..939, - value: FString( - ExprFString { - range: 910..939, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 910..915, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 916..924, - elements: [ - Expression( - FStringExpressionElement { - range: 918..923, - expression: Name( - ExprName { - range: 919..922, - id: "bar", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 925..930, - value: "baz", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 931..939, - value: " some", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Unicode, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 940..978, - value: FString( - ExprFString { - range: 940..978, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 940..946, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Unicode, - triple_quoted: false, - }, - }, - ), - FString( - FString { - range: 947..966, - elements: [ - Literal( - FStringLiteralElement { - range: 949..953, - value: "bar ", - }, - ), - Expression( - FStringExpressionElement { - range: 953..958, - expression: Name( - ExprName { - range: 954..957, - id: "baz", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 958..965, - value: " really", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 967..973, - value: "bar", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Unicode, - triple_quoted: false, - }, - }, - ), - Literal( - StringLiteral { - range: 974..978, - value: "no", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - ], - ), - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap.new deleted file mode 100644 index 90cc91cdec..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap.new +++ /dev/null @@ -1,698 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/generator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..482, - body: [ - Expr( - StmtExpr { - range: 0..22, - value: Generator( - ExprGenerator { - range: 0..22, - elt: Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3..21, - target: Name( - ExprName { - range: 7..13, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 17..21, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 23..51, - value: Generator( - ExprGenerator { - range: 23..51, - elt: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 26..50, - target: Name( - ExprName { - range: 36..42, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 46..50, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: true, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 52..100, - value: Generator( - ExprGenerator { - range: 52..100, - elt: Name( - ExprName { - range: 53..54, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 55..99, - target: Name( - ExprName { - range: 59..65, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 69..73, - id: "iter", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 77..83, - left: Name( - ExprName { - range: 77..78, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 82..83, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - BoolOp( - ExprBoolOp { - range: 87..94, - op: And, - values: [ - Name( - ExprName { - range: 87..88, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 93..94, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 98..99, - id: "c", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 101..166, - value: Generator( - ExprGenerator { - range: 101..166, - elt: Name( - ExprName { - range: 102..103, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 104..135, - target: Name( - ExprName { - range: 108..115, - id: "target1", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 119..124, - id: "iter1", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 128..135, - op: And, - values: [ - Name( - ExprName { - range: 128..129, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 134..135, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 136..165, - target: Name( - ExprName { - range: 140..147, - id: "target2", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 151..156, - id: "iter2", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 160..165, - left: Name( - ExprName { - range: 160..161, - id: "a", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 164..165, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 167..238, - value: Generator( - ExprGenerator { - range: 167..238, - elt: Name( - ExprName { - range: 168..169, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 170..201, - target: Name( - ExprName { - range: 174..181, - id: "target1", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 185..190, - id: "iter1", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 194..201, - op: And, - values: [ - Name( - ExprName { - range: 194..195, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 200..201, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 202..237, - target: Name( - ExprName { - range: 212..219, - id: "target2", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 223..228, - id: "iter2", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 232..237, - left: Name( - ExprName { - range: 232..233, - id: "a", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 236..237, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: true, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 259..282, - value: Generator( - ExprGenerator { - range: 259..282, - elt: Named( - ExprNamed { - range: 260..270, - target: Name( - ExprName { - range: 260..261, - id: "x", - ctx: Store, - }, - ), - value: BinOp( - ExprBinOp { - range: 265..270, - left: Name( - ExprName { - range: 265..266, - id: "y", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 269..270, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 271..281, - target: Name( - ExprName { - range: 275..276, - id: "y", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 280..281, - id: "z", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 300..326, - value: Generator( - ExprGenerator { - range: 300..326, - elt: If( - ExprIf { - range: 301..314, - test: Name( - ExprName { - range: 306..307, - id: "y", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 301..302, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 313..314, - id: "y", - ctx: Load, - }, - ), - }, - ), - generators: [ - Comprehension { - range: 315..325, - target: Name( - ExprName { - range: 319..320, - id: "y", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 324..325, - id: "z", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 340..481, - value: Call( - ExprCall { - range: 340..481, - func: Attribute( - ExprAttribute { - range: 340..348, - value: StringLiteral( - ExprStringLiteral { - range: 340..343, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 340..343, - value: " ", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - attr: Identifier { - id: "join", - range: 344..348, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 348..481, - args: [ - Generator( - ExprGenerator { - range: 354..479, - elt: Name( - ExprName { - range: 354..357, - id: "sql", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 362..479, - target: Name( - ExprName { - range: 366..369, - id: "sql", - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 373..479, - elts: [ - If( - ExprIf { - range: 383..420, - test: Name( - ExprName { - range: 405..410, - id: "limit", - ctx: Load, - }, - ), - body: BinOp( - ExprBinOp { - range: 383..401, - left: StringLiteral( - ExprStringLiteral { - range: 383..393, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 383..393, - value: "LIMIT %d", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - op: Mod, - right: Name( - ExprName { - range: 396..401, - id: "limit", - ctx: Load, - }, - ), - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - range: 416..420, - }, - ), - }, - ), - If( - ExprIf { - range: 430..472, - test: Name( - ExprName { - range: 456..462, - id: "offset", - ctx: Load, - }, - ), - body: BinOp( - ExprBinOp { - range: 431..451, - left: StringLiteral( - ExprStringLiteral { - range: 431..442, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 431..442, - value: "OFFSET %d", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - op: Mod, - right: Name( - ExprName { - range: 445..451, - id: "offset", - ctx: Load, - }, - ), - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - range: 468..472, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap.new deleted file mode 100644 index 1c3527c88c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap.new +++ /dev/null @@ -1,614 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/if.py ---- -## AST - -``` -Module( - ModModule { - range: 0..423, - body: [ - Expr( - StmtExpr { - range: 0..16, - value: If( - ExprIf { - range: 0..16, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 5..9, - value: true, - }, - ), - body: Name( - ExprName { - range: 0..1, - id: "a", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 15..16, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 17..35, - value: If( - ExprIf { - range: 17..35, - test: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - body: Call( - ExprCall { - range: 17..20, - func: Name( - ExprName { - range: 17..18, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 18..20, - args: [], - keywords: [], - }, - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - range: 31..35, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 36..61, - value: If( - ExprIf { - range: 36..61, - test: Name( - ExprName { - range: 41..42, - id: "b", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 36..37, - id: "a", - ctx: Load, - }, - ), - orelse: If( - ExprIf { - range: 48..61, - test: Name( - ExprName { - range: 53..54, - id: "d", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 48..49, - id: "c", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 60..61, - id: "e", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 62..84, - value: If( - ExprIf { - range: 62..84, - test: Compare( - ExprCompare { - range: 71..76, - left: NumberLiteral( - ExprNumberLiteral { - range: 71..72, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 75..76, - value: Int( - 0, - ), - }, - ), - ], - }, - ), - body: BinOp( - ExprBinOp { - range: 62..67, - left: NumberLiteral( - ExprNumberLiteral { - range: 62..63, - value: Int( - 1, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 66..67, - id: "x", - ctx: Load, - }, - ), - }, - ), - orelse: UnaryOp( - ExprUnaryOp { - range: 82..84, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 85..108, - value: If( - ExprIf { - range: 85..108, - test: Name( - ExprName { - range: 96..97, - id: "x", - ctx: Load, - }, - ), - body: BoolOp( - ExprBoolOp { - range: 85..92, - op: And, - values: [ - Name( - ExprName { - range: 85..86, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 91..92, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - orelse: BooleanLiteral( - ExprBooleanLiteral { - range: 103..108, - value: false, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 109..127, - value: If( - ExprIf { - range: 109..127, - test: Name( - ExprName { - range: 119..120, - id: "y", - ctx: Load, - }, - ), - body: Compare( - ExprCompare { - range: 109..115, - left: Name( - ExprName { - range: 109..110, - id: "x", - ctx: Load, - }, - ), - ops: [ - LtE, - ], - comparators: [ - Name( - ExprName { - range: 114..115, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - orelse: Name( - ExprName { - range: 126..127, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 128..154, - value: If( - ExprIf { - range: 128..154, - test: BoolOp( - ExprBoolOp { - range: 136..143, - op: And, - values: [ - Name( - ExprName { - range: 136..137, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 142..143, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - body: BooleanLiteral( - ExprBooleanLiteral { - range: 128..132, - value: true, - }, - ), - orelse: BooleanLiteral( - ExprBooleanLiteral { - range: 149..154, - value: false, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 155..171, - value: Tuple( - ExprTuple { - range: 155..171, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 155..156, - value: Int( - 1, - ), - }, - ), - If( - ExprIf { - range: 158..171, - test: Name( - ExprName { - range: 163..164, - id: "a", - ctx: Load, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), - }, - ), - orelse: Name( - ExprName { - range: 170..171, - id: "c", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 214..240, - value: If( - ExprIf { - range: 214..240, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 219..223, - value: true, - }, - ), - body: Name( - ExprName { - range: 214..215, - id: "x", - ctx: Load, - }, - ), - orelse: Lambda( - ExprLambda { - range: 229..240, - parameters: Some( - Parameters { - range: 236..237, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 236..237, - parameter: Parameter { - range: 236..237, - name: Identifier { - id: "y", - range: 236..237, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 239..240, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 302..323, - value: If( - ExprIf { - range: 302..323, - test: Yield( - ExprYield { - range: 308..315, - value: Some( - Name( - ExprName { - range: 314..315, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - body: Name( - ExprName { - range: 302..303, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 322..323, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 324..350, - value: If( - ExprIf { - range: 324..350, - test: YieldFrom( - ExprYieldFrom { - range: 330..342, - value: Name( - ExprName { - range: 341..342, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: Name( - ExprName { - range: 324..325, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 349..350, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 351..376, - value: If( - ExprIf { - range: 351..376, - test: Lambda( - ExprLambda { - range: 357..368, - parameters: Some( - Parameters { - range: 364..365, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 364..365, - parameter: Parameter { - range: 364..365, - name: Identifier { - id: "x", - range: 364..365, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 367..368, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: Name( - ExprName { - range: 351..352, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 375..376, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 408..423, - value: If( - ExprIf { - range: 409..422, - test: Name( - ExprName { - range: 414..415, - id: "y", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 409..410, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 421..422, - id: "z", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap.new deleted file mode 100644 index 794f58e6ae..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap.new +++ /dev/null @@ -1,1522 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/lambda.py ---- -## AST - -``` -Module( - ModModule { - range: 0..530, - body: [ - Expr( - StmtExpr { - range: 0..9, - value: Lambda( - ExprLambda { - range: 0..9, - parameters: None, - body: Name( - ExprName { - range: 8..9, - id: "a", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 10..19, - value: Lambda( - ExprLambda { - range: 10..19, - parameters: None, - body: NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 20..31, - value: Lambda( - ExprLambda { - range: 20..31, - parameters: Some( - Parameters { - range: 27..28, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 27..28, - parameter: Parameter { - range: 27..28, - name: Identifier { - id: "x", - range: 27..28, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 30..31, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 32..48, - value: Lambda( - ExprLambda { - range: 32..48, - parameters: Some( - Parameters { - range: 39..43, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 39..40, - parameter: Parameter { - range: 39..40, - name: Identifier { - id: "x", - range: 39..40, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 42..43, - parameter: Parameter { - range: 42..43, - name: Identifier { - id: "y", - range: 42..43, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 45..48, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..66, - value: Lambda( - ExprLambda { - range: 49..66, - parameters: Some( - Parameters { - range: 56..63, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 56..57, - parameter: Parameter { - range: 56..57, - name: Identifier { - id: "a", - range: 56..57, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 59..60, - parameter: Parameter { - range: 59..60, - name: Identifier { - id: "b", - range: 59..60, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 62..63, - parameter: Parameter { - range: 62..63, - name: Identifier { - id: "c", - range: 62..63, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 67..90, - value: Lambda( - ExprLambda { - range: 67..90, - parameters: Some( - Parameters { - range: 74..87, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 74..75, - parameter: Parameter { - range: 74..75, - name: Identifier { - id: "a", - range: 74..75, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 77..81, - parameter: Parameter { - range: 77..78, - name: Identifier { - id: "b", - range: 77..78, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 79..81, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 83..87, - parameter: Parameter { - range: 83..84, - name: Identifier { - id: "c", - range: 83..84, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 85..87, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 91..109, - value: Lambda( - ExprLambda { - range: 91..109, - parameters: Some( - Parameters { - range: 98..102, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 98..99, - parameter: Parameter { - range: 98..99, - name: Identifier { - id: "x", - range: 98..99, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 101..102, - parameter: Parameter { - range: 101..102, - name: Identifier { - id: "y", - range: 101..102, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: BinOp( - ExprBinOp { - range: 104..109, - left: Name( - ExprName { - range: 104..105, - id: "x", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 108..109, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 110..130, - value: Lambda( - ExprLambda { - range: 110..130, - parameters: Some( - Parameters { - range: 117..123, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 117..118, - parameter: Parameter { - range: 117..118, - name: Identifier { - id: "y", - range: 117..118, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 120..123, - parameter: Parameter { - range: 120..121, - name: Identifier { - id: "z", - range: 120..121, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 122..123, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: BinOp( - ExprBinOp { - range: 125..130, - left: Name( - ExprName { - range: 125..126, - id: "z", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 129..130, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 131..143, - value: Lambda( - ExprLambda { - range: 131..143, - parameters: Some( - Parameters { - range: 138..140, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 138..140, - name: Identifier { - id: "a", - range: 139..140, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 142..143, - id: "a", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 144..166, - value: Lambda( - ExprLambda { - range: 144..166, - parameters: Some( - Parameters { - range: 151..161, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 151..153, - name: Identifier { - id: "a", - range: 152..153, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 155..156, - parameter: Parameter { - range: 155..156, - name: Identifier { - id: "z", - range: 155..156, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 158..161, - parameter: Parameter { - range: 158..159, - name: Identifier { - id: "x", - range: 158..159, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 160..161, - value: Int( - 0, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 163..166, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 167..187, - value: Lambda( - ExprLambda { - range: 167..187, - parameters: Some( - Parameters { - range: 174..184, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 177..178, - parameter: Parameter { - range: 177..178, - name: Identifier { - id: "a", - range: 177..178, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 180..181, - parameter: Parameter { - range: 180..181, - name: Identifier { - id: "b", - range: 180..181, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 183..184, - parameter: Parameter { - range: 183..184, - name: Identifier { - id: "c", - range: 183..184, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 186..187, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 188..214, - value: Lambda( - ExprLambda { - range: 188..214, - parameters: Some( - Parameters { - range: 195..211, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 198..199, - parameter: Parameter { - range: 198..199, - name: Identifier { - id: "a", - range: 198..199, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 201..205, - parameter: Parameter { - range: 201..202, - name: Identifier { - id: "b", - range: 201..202, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 203..205, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 207..211, - parameter: Parameter { - range: 207..208, - name: Identifier { - id: "c", - range: 207..208, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 209..211, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 213..214, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 215..241, - value: Lambda( - ExprLambda { - range: 215..241, - parameters: Some( - Parameters { - range: 222..238, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 222..223, - parameter: Parameter { - range: 222..223, - name: Identifier { - id: "a", - range: 222..223, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 225..226, - parameter: Parameter { - range: 225..226, - name: Identifier { - id: "b", - range: 225..226, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 228..229, - parameter: Parameter { - range: 228..229, - name: Identifier { - id: "c", - range: 228..229, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 234..235, - parameter: Parameter { - range: 234..235, - name: Identifier { - id: "d", - range: 234..235, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 237..238, - parameter: Parameter { - range: 237..238, - name: Identifier { - id: "e", - range: 237..238, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 240..241, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 242..262, - value: Lambda( - ExprLambda { - range: 242..262, - parameters: Some( - Parameters { - range: 249..257, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 249..257, - name: Identifier { - id: "kwargs", - range: 251..257, - }, - annotation: None, - }, - ), - }, - ), - body: Call( - ExprCall { - range: 259..262, - func: Name( - ExprName { - range: 259..260, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 260..262, - args: [], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 263..294, - value: Lambda( - ExprLambda { - range: 263..294, - parameters: Some( - Parameters { - range: 270..285, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 270..275, - name: Identifier { - id: "args", - range: 271..275, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 277..285, - name: Identifier { - id: "kwargs", - range: 279..285, - }, - annotation: None, - }, - ), - }, - ), - body: BinOp( - ExprBinOp { - range: 287..294, - left: Call( - ExprCall { - range: 287..290, - func: Name( - ExprName { - range: 287..288, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 288..290, - args: [], - keywords: [], - }, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 293..294, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 295..334, - value: Lambda( - ExprLambda { - range: 295..334, - parameters: Some( - Parameters { - range: 302..325, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 302..307, - name: Identifier { - id: "args", - range: 303..307, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 309..310, - parameter: Parameter { - range: 309..310, - name: Identifier { - id: "a", - range: 309..310, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 312..315, - parameter: Parameter { - range: 312..313, - name: Identifier { - id: "b", - range: 312..313, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 314..315, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 317..325, - name: Identifier { - id: "kwargs", - range: 319..325, - }, - annotation: None, - }, - ), - }, - ), - body: BinOp( - ExprBinOp { - range: 327..334, - left: Call( - ExprCall { - range: 327..330, - func: Name( - ExprName { - range: 327..328, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 328..330, - args: [], - keywords: [], - }, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 333..334, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 335..351, - value: Lambda( - ExprLambda { - range: 335..351, - parameters: Some( - Parameters { - range: 342..346, - posonlyargs: [ - ParameterWithDefault { - range: 342..343, - parameter: Parameter { - range: 342..343, - name: Identifier { - id: "a", - range: 342..343, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 348..351, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 352..371, - value: Lambda( - ExprLambda { - range: 352..371, - parameters: Some( - Parameters { - range: 359..366, - posonlyargs: [ - ParameterWithDefault { - range: 359..360, - parameter: Parameter { - range: 359..360, - name: Identifier { - id: "a", - range: 359..360, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 365..366, - parameter: Parameter { - range: 365..366, - name: Identifier { - id: "b", - range: 365..366, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 368..371, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 372..391, - value: Lambda( - ExprLambda { - range: 372..391, - parameters: Some( - Parameters { - range: 379..386, - posonlyargs: [ - ParameterWithDefault { - range: 379..382, - parameter: Parameter { - range: 379..380, - name: Identifier { - id: "a", - range: 379..380, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 381..382, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 388..391, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 392..417, - value: Lambda( - ExprLambda { - range: 392..417, - parameters: Some( - Parameters { - range: 399..412, - posonlyargs: [ - ParameterWithDefault { - range: 399..400, - parameter: Parameter { - range: 399..400, - name: Identifier { - id: "a", - range: 399..400, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 402..403, - parameter: Parameter { - range: 402..403, - name: Identifier { - id: "b", - range: 402..403, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 411..412, - parameter: Parameter { - range: 411..412, - name: Identifier { - id: "c", - range: 411..412, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 414..417, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 418..440, - value: Lambda( - ExprLambda { - range: 418..440, - parameters: Some( - Parameters { - range: 425..435, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 425..429, - parameter: Parameter { - range: 425..427, - name: Identifier { - id: "kw", - range: 425..427, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 428..429, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 434..435, - parameter: Parameter { - range: 434..435, - name: Identifier { - id: "a", - range: 434..435, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: EllipsisLiteral( - ExprEllipsisLiteral { - range: 437..440, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 441..467, - value: Lambda( - ExprLambda { - range: 441..467, - parameters: Some( - Parameters { - range: 448..464, - posonlyargs: [ - ParameterWithDefault { - range: 448..449, - parameter: Parameter { - range: 448..449, - name: Identifier { - id: "a", - range: 448..449, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 451..455, - parameter: Parameter { - range: 451..452, - name: Identifier { - id: "b", - range: 451..452, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 453..455, - value: Int( - 20, - ), - }, - ), - ), - }, - ], - args: [ - ParameterWithDefault { - range: 460..464, - parameter: Parameter { - range: 460..461, - name: Identifier { - id: "c", - range: 460..461, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 462..464, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 466..467, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 468..497, - value: Lambda( - ExprLambda { - range: 468..497, - parameters: Some( - Parameters { - range: 475..494, - posonlyargs: [ - ParameterWithDefault { - range: 475..476, - parameter: Parameter { - range: 475..476, - name: Identifier { - id: "a", - range: 475..476, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 478..479, - parameter: Parameter { - range: 478..479, - name: Identifier { - id: "b", - range: 478..479, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 484..485, - parameter: Parameter { - range: 484..485, - name: Identifier { - id: "c", - range: 484..485, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 490..491, - parameter: Parameter { - range: 490..491, - name: Identifier { - id: "d", - range: 490..491, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 493..494, - parameter: Parameter { - range: 493..494, - name: Identifier { - id: "e", - range: 493..494, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 496..497, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 498..530, - value: Lambda( - ExprLambda { - range: 498..530, - parameters: Some( - Parameters { - range: 505..527, - posonlyargs: [ - ParameterWithDefault { - range: 505..506, - parameter: Parameter { - range: 505..506, - name: Identifier { - id: "a", - range: 505..506, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 508..509, - parameter: Parameter { - range: 508..509, - name: Identifier { - id: "b", - range: 508..509, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 514..515, - parameter: Parameter { - range: 514..515, - name: Identifier { - id: "c", - range: 514..515, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 517..519, - name: Identifier { - id: "d", - range: 518..519, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 521..522, - parameter: Parameter { - range: 521..522, - name: Identifier { - id: "e", - range: 521..522, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: Some( - Parameter { - range: 524..527, - name: Identifier { - id: "f", - range: 526..527, - }, - annotation: None, - }, - ), - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 529..530, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap.new deleted file mode 100644 index 112bf2de0c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap.new +++ /dev/null @@ -1,811 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/list.py ---- -## AST - -``` -Module( - ModModule { - range: 0..384, - body: [ - Expr( - StmtExpr { - range: 15..17, - value: List( - ExprList { - range: 15..17, - elts: [], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..21, - value: List( - ExprList { - range: 18..21, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..26, - value: List( - ExprList { - range: 22..26, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 27..36, - value: List( - ExprList { - range: 27..36, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 31..32, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 37..47, - value: List( - ExprList { - range: 37..47, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 38..39, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 41..42, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 44..45, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 75..78, - value: List( - ExprList { - range: 75..78, - elts: [], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 79..92, - value: List( - ExprList { - range: 79..92, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 93..114, - value: List( - ExprList { - range: 93..114, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 99..100, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 110..111, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 125..132, - value: List( - ExprList { - range: 125..132, - elts: [ - List( - ExprList { - range: 126..131, - elts: [ - List( - ExprList { - range: 127..130, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 128..129, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..149, - value: List( - ExprList { - range: 133..149, - elts: [ - List( - ExprList { - range: 134..140, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 135..136, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 138..139, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - List( - ExprList { - range: 142..148, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 143..144, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 146..147, - value: Int( - 4, - ), - }, - ), - ], - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 170..178, - value: List( - ExprList { - range: 170..178, - elts: [ - Named( - ExprNamed { - range: 171..177, - target: Name( - ExprName { - range: 171..172, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 176..177, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 179..188, - value: List( - ExprList { - range: 179..188, - elts: [ - Named( - ExprNamed { - range: 180..186, - target: Name( - ExprName { - range: 180..181, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 185..186, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 189..203, - value: List( - ExprList { - range: 189..203, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 190..191, - value: Int( - 1, - ), - }, - ), - Named( - ExprNamed { - range: 193..199, - target: Name( - ExprName { - range: 193..194, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 198..199, - value: Int( - 2, - ), - }, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 223..233, - value: List( - ExprList { - range: 223..233, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 224..225, - value: Int( - 1, - ), - }, - ), - Starred( - ExprStarred { - range: 227..229, - value: Name( - ExprName { - range: 228..229, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 231..232, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 234..248, - value: List( - ExprList { - range: 234..248, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 235..236, - value: Int( - 1, - ), - }, - ), - Starred( - ExprStarred { - range: 238..244, - value: BinOp( - ExprBinOp { - range: 239..244, - left: Name( - ExprName { - range: 239..240, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 243..244, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 246..247, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 271..334, - value: List( - ExprList { - range: 271..334, - elts: [ - BinOp( - ExprBinOp { - range: 272..277, - left: NumberLiteral( - ExprNumberLiteral { - range: 272..273, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 276..277, - value: Int( - 2, - ), - }, - ), - }, - ), - List( - ExprList { - range: 279..291, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 280..281, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 283..284, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 286..287, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 289..290, - value: Int( - 4, - ), - }, - ), - ], - ctx: Load, - }, - ), - Tuple( - ExprTuple { - range: 293..306, - elts: [ - Name( - ExprName { - range: 294..295, - id: "a", - ctx: Load, - }, - ), - BinOp( - ExprBinOp { - range: 297..302, - left: Name( - ExprName { - range: 297..298, - id: "b", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 301..302, - id: "c", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 304..305, - id: "d", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - Set( - ExprSet { - range: 308..317, - elts: [ - Name( - ExprName { - range: 309..310, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 312..313, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 315..316, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - Dict( - ExprDict { - range: 319..325, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 320..321, - id: "a", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 323..324, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - Named( - ExprNamed { - range: 327..333, - target: Name( - ExprName { - range: 327..328, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 332..333, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 335..383, - value: List( - ExprList { - range: 335..383, - elts: [ - Call( - ExprCall { - range: 336..382, - func: Name( - ExprName { - range: 336..341, - id: "call1", - ctx: Load, - }, - ), - arguments: Arguments { - range: 341..382, - args: [ - Generator( - ExprGenerator { - range: 342..381, - elt: Call( - ExprCall { - range: 342..361, - func: Name( - ExprName { - range: 342..347, - id: "call2", - ctx: Load, - }, - ), - arguments: Arguments { - range: 347..361, - args: [ - Call( - ExprCall { - range: 348..360, - func: Attribute( - ExprAttribute { - range: 348..358, - value: Name( - ExprName { - range: 348..353, - id: "value", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 354..358, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 358..360, - args: [], - keywords: [], - }, - }, - ), - ], - keywords: [], - }, - }, - ), - generators: [ - Comprehension { - range: 362..381, - target: Name( - ExprName { - range: 366..373, - id: "element", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 377..381, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, - ), - ], - keywords: [], - }, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap.new deleted file mode 100644 index a7a0f6e28b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap.new +++ /dev/null @@ -1,1291 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/list_comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..776, - body: [ - Assign( - StmtAssign { - range: 0..26, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: ListComp( - ExprListComp { - range: 4..26, - elt: Name( - ExprName { - range: 5..6, - id: "y", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 7..25, - target: Name( - ExprName { - range: 11..12, - id: "y", - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 16..25, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 17..18, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..49, - value: ListComp( - ExprListComp { - range: 28..49, - elt: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 31..48, - target: Name( - ExprName { - range: 35..36, - id: "i", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 40..48, - func: Name( - ExprName { - range: 40..45, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 45..48, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 46..47, - value: Int( - 5, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 50..91, - value: ListComp( - ExprListComp { - range: 50..91, - elt: Name( - ExprName { - range: 51..52, - id: "b", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 53..90, - target: Name( - ExprName { - range: 57..58, - id: "c", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 62..63, - id: "d", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 67..73, - left: Name( - ExprName { - range: 67..68, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 72..73, - id: "w", - ctx: Load, - }, - ), - ], - }, - ), - BoolOp( - ExprBoolOp { - range: 77..85, - op: And, - values: [ - Name( - ExprName { - range: 77..78, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 83..85, - id: "yy", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 89..90, - id: "z", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 92..137, - value: ListComp( - ExprListComp { - range: 92..137, - elt: Name( - ExprName { - range: 93..94, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 95..116, - target: Name( - ExprName { - range: 99..100, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 104..105, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 109..116, - op: And, - values: [ - Name( - ExprName { - range: 109..110, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 115..116, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 117..136, - target: Name( - ExprName { - range: 121..122, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 126..127, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 131..136, - left: Name( - ExprName { - range: 131..132, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 135..136, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 138..189, - value: ListComp( - ExprListComp { - range: 138..189, - elt: Name( - ExprName { - range: 139..140, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 141..162, - target: Name( - ExprName { - range: 145..146, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 150..151, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 155..162, - op: And, - values: [ - Name( - ExprName { - range: 155..156, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 161..162, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 163..188, - target: Name( - ExprName { - range: 173..174, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 178..179, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 183..188, - left: Name( - ExprName { - range: 183..184, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 187..188, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: true, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 190..209, - value: ListComp( - ExprListComp { - range: 190..209, - elt: NumberLiteral( - ExprNumberLiteral { - range: 191..192, - value: Int( - 1, - ), - }, - ), - generators: [ - Comprehension { - range: 193..208, - target: Name( - ExprName { - range: 197..198, - id: "i", - ctx: Store, - }, - ), - iter: Compare( - ExprCompare { - range: 202..208, - left: Name( - ExprName { - range: 202..203, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 207..208, - id: "a", - ctx: Load, - }, - ), - ], - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 210..227, - value: ListComp( - ExprListComp { - range: 210..227, - elt: Name( - ExprName { - range: 211..212, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 213..226, - target: Tuple( - ExprTuple { - range: 217..221, - elts: [ - Name( - ExprName { - range: 217..218, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 220..221, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - iter: Name( - ExprName { - range: 225..226, - id: "G", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 228..257, - value: ListComp( - ExprListComp { - range: 228..257, - elt: Await( - ExprAwait { - range: 234..241, - value: Name( - ExprName { - range: 240..241, - id: "x", - ctx: Load, - }, - ), - }, - ), - generators: [ - Comprehension { - range: 242..255, - target: Tuple( - ExprTuple { - range: 246..250, - elts: [ - Name( - ExprName { - range: 246..247, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 249..250, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - iter: Name( - ExprName { - range: 254..255, - id: "C", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 258..300, - value: ListComp( - ExprListComp { - range: 258..300, - elt: Name( - ExprName { - range: 259..260, - id: "i", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 261..299, - target: Name( - ExprName { - range: 265..266, - id: "i", - ctx: Store, - }, - ), - iter: Await( - ExprAwait { - range: 270..277, - value: Name( - ExprName { - range: 276..277, - id: "x", - ctx: Load, - }, - ), - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 281..299, - left: Name( - ExprName { - range: 281..287, - id: "entity", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - NoneLiteral( - ExprNoneLiteral { - range: 295..299, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 301..337, - value: ListComp( - ExprListComp { - range: 301..337, - elt: Name( - ExprName { - range: 302..303, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 304..336, - target: Name( - ExprName { - range: 308..309, - id: "x", - ctx: Store, - }, - ), - iter: If( - ExprIf { - range: 314..330, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 319..323, - value: true, - }, - ), - body: Name( - ExprName { - range: 314..315, - id: "l", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 329..330, - id: "L", - ctx: Load, - }, - ), - }, - ), - ifs: [ - Name( - ExprName { - range: 335..336, - id: "T", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 338..380, - value: ListComp( - ExprListComp { - range: 338..380, - elt: Name( - ExprName { - range: 339..340, - id: "i", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 341..379, - target: Name( - ExprName { - range: 345..346, - id: "i", - ctx: Store, - }, - ), - iter: If( - ExprIf { - range: 351..373, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 362..366, - value: true, - }, - ), - body: Await( - ExprAwait { - range: 351..358, - value: Name( - ExprName { - range: 357..358, - id: "x", - ctx: Load, - }, - ), - }, - ), - orelse: Name( - ExprName { - range: 372..373, - id: "X", - ctx: Load, - }, - ), - }, - ), - ifs: [ - Name( - ExprName { - range: 378..379, - id: "F", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 381..423, - value: ListComp( - ExprListComp { - range: 381..423, - elt: Name( - ExprName { - range: 382..383, - id: "i", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 384..422, - target: Name( - ExprName { - range: 388..389, - id: "i", - ctx: Store, - }, - ), - iter: Await( - ExprAwait { - range: 393..417, - value: If( - ExprIf { - range: 400..416, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 405..409, - value: true, - }, - ), - body: Name( - ExprName { - range: 400..401, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 415..416, - id: "X", - ctx: Load, - }, - ), - }, - ), - }, - ), - ifs: [ - Name( - ExprName { - range: 421..422, - id: "F", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 424..457, - value: ListComp( - ExprListComp { - range: 424..457, - elt: Name( - ExprName { - range: 425..426, - id: "f", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 427..456, - target: Name( - ExprName { - range: 431..432, - id: "f", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 436..456, - func: Name( - ExprName { - range: 436..437, - id: "c", - ctx: Load, - }, - ), - arguments: Arguments { - range: 437..456, - args: [ - If( - ExprIf { - range: 438..455, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 443..447, - value: true, - }, - ), - body: Name( - ExprName { - range: 438..439, - id: "x", - ctx: Load, - }, - ), - orelse: List( - ExprList { - range: 453..455, - elts: [], - ctx: Load, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 596..618, - value: ListComp( - ExprListComp { - range: 596..618, - elt: Name( - ExprName { - range: 597..598, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 599..617, - target: Name( - ExprName { - range: 603..604, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 609..616, - value: Some( - Name( - ExprName { - range: 615..616, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 619..646, - value: ListComp( - ExprListComp { - range: 619..646, - elt: Name( - ExprName { - range: 620..621, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 622..645, - target: Name( - ExprName { - range: 626..627, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 632..644, - value: Name( - ExprName { - range: 643..644, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 647..673, - value: ListComp( - ExprListComp { - range: 647..673, - elt: Name( - ExprName { - range: 648..649, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 650..672, - target: Name( - ExprName { - range: 654..655, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 660..671, - parameters: Some( - Parameters { - range: 667..668, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 667..668, - parameter: Parameter { - range: 667..668, - name: Identifier { - id: "y", - range: 667..668, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 670..671, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 674..704, - value: ListComp( - ExprListComp { - range: 674..704, - elt: Name( - ExprName { - range: 675..676, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 677..703, - target: Name( - ExprName { - range: 681..682, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 686..690, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 695..702, - value: Some( - Name( - ExprName { - range: 701..702, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 705..740, - value: ListComp( - ExprListComp { - range: 705..740, - elt: Name( - ExprName { - range: 706..707, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 708..739, - target: Name( - ExprName { - range: 712..713, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 717..721, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 726..738, - value: Name( - ExprName { - range: 737..738, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 741..775, - value: ListComp( - ExprListComp { - range: 741..775, - elt: Name( - ExprName { - range: 742..743, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 744..774, - target: Name( - ExprName { - range: 748..749, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 753..757, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 762..773, - parameters: Some( - Parameters { - range: 769..770, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 769..770, - parameter: Parameter { - range: 769..770, - name: Identifier { - id: "y", - range: 769..770, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 772..773, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap.new deleted file mode 100644 index 513c29c5d8..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/name.py ---- -## AST - -``` -Module( - ModModule { - range: 0..76, - body: [ - Expr( - StmtExpr { - range: 0..1, - value: Name( - ExprName { - range: 0..1, - id: "_", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 2..5, - value: Name( - ExprName { - range: 3..4, - id: "_", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 6..8, - value: Name( - ExprName { - range: 6..8, - id: "__", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 9..17, - value: Name( - ExprName { - range: 9..17, - id: "__init__", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..22, - value: Name( - ExprName { - range: 18..22, - id: "name", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 23..29, - value: Name( - ExprName { - range: 24..28, - id: "name", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 60..65, - value: Name( - ExprName { - range: 60..65, - id: "match", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 66..70, - value: Name( - ExprName { - range: 66..70, - id: "case", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 71..75, - value: Name( - ExprName { - range: 71..75, - id: "type", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap.new deleted file mode 100644 index d72d477b11..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap.new +++ /dev/null @@ -1,317 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/named.py ---- -## AST - -``` -Module( - ModModule { - range: 0..157, - body: [ - Expr( - StmtExpr { - range: 0..11, - value: Named( - ExprNamed { - range: 1..10, - target: Name( - ExprName { - range: 1..5, - id: "name", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..29, - value: Named( - ExprNamed { - range: 13..28, - target: Name( - ExprName { - range: 13..17, - id: "name", - ctx: Store, - }, - ), - value: BinOp( - ExprBinOp { - range: 22..27, - left: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 26..27, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 30..45, - value: Named( - ExprNamed { - range: 31..44, - target: Name( - ExprName { - range: 31..35, - id: "name", - ctx: Store, - }, - ), - value: BinOp( - ExprBinOp { - range: 39..44, - left: NumberLiteral( - ExprNumberLiteral { - range: 39..40, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 43..44, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 46..63, - value: Named( - ExprNamed { - range: 47..62, - target: Name( - ExprName { - range: 47..51, - id: "name", - ctx: Store, - }, - ), - value: Tuple( - ExprTuple { - range: 55..62, - elts: [ - Starred( - ExprStarred { - range: 56..58, - value: Name( - ExprName { - range: 57..58, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 60..61, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 64..90, - value: Named( - ExprNamed { - range: 65..89, - target: Name( - ExprName { - range: 65..69, - id: "name", - ctx: Store, - }, - ), - value: If( - ExprIf { - range: 73..89, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 78..82, - value: true, - }, - ), - body: Name( - ExprName { - range: 73..74, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 88..89, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 91..112, - value: Named( - ExprNamed { - range: 92..111, - target: Name( - ExprName { - range: 92..96, - id: "name", - ctx: Store, - }, - ), - value: Lambda( - ExprLambda { - range: 100..111, - parameters: Some( - Parameters { - range: 107..108, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 107..108, - parameter: Parameter { - range: 107..108, - name: Identifier { - id: "x", - range: 107..108, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 110..111, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 113..132, - value: Named( - ExprNamed { - range: 114..131, - target: Name( - ExprName { - range: 114..118, - id: "name", - ctx: Store, - }, - ), - value: Yield( - ExprYield { - range: 123..130, - value: Some( - Name( - ExprName { - range: 129..130, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..157, - value: Named( - ExprNamed { - range: 134..156, - target: Name( - ExprName { - range: 134..138, - id: "name", - ctx: Store, - }, - ), - value: YieldFrom( - ExprYieldFrom { - range: 143..155, - value: Name( - ExprName { - range: 154..155, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap.new deleted file mode 100644 index 5cc14031b7..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap.new +++ /dev/null @@ -1,1029 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/number_literal.py ---- -## AST - -``` -Module( - ModModule { - range: 0..700, - body: [ - Assign( - StmtAssign { - range: 0..13, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 4..13, - value: Int( - 123456789, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 14..24, - targets: [ - Name( - ExprName { - range: 14..15, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 18..24, - value: Int( - 123456, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 25..31, - targets: [ - Name( - ExprName { - range: 25..26, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 29..31, - value: Float( - 0.1, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 32..38, - targets: [ - Name( - ExprName { - range: 32..33, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 36..38, - value: Float( - 1.0, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 39..47, - targets: [ - Name( - ExprName { - range: 39..40, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 43..47, - value: Float( - 10.0, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 48..56, - targets: [ - Name( - ExprName { - range: 48..49, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 52..56, - value: Float( - 0.1, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 57..73, - targets: [ - Name( - ExprName { - range: 57..58, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 61..73, - value: Float( - 1.00000001, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 74..97, - targets: [ - Name( - ExprName { - range: 74..75, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 78..97, - value: Float( - 123456789.12345679, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 98..131, - targets: [ - Name( - ExprName { - range: 98..99, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 102..131, - value: Float( - inf, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 132..155, - targets: [ - Name( - ExprName { - range: 132..133, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 136..155, - value: Float( - inf, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 156..170, - targets: [ - Name( - ExprName { - range: 156..157, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 160..170, - value: Complex { - real: 0.0, - imag: 123456789.0, - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 171..195, - targets: [ - Name( - ExprName { - range: 171..172, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 175..195, - value: Complex { - real: 0.0, - imag: 123456789.12345679, - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 196..207, - targets: [ - Name( - ExprName { - range: 196..197, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 200..207, - value: Int( - 727756, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 208..218, - targets: [ - Name( - ExprName { - range: 208..209, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 212..218, - value: Int( - 11, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 219..228, - targets: [ - Name( - ExprName { - range: 219..220, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 223..228, - value: Int( - 511, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 229..244, - targets: [ - Name( - ExprName { - range: 229..230, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 233..244, - value: Float( - 6e-9, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 245..254, - targets: [ - Name( - ExprName { - range: 245..246, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 249..254, - value: Int( - 10000, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 255..265, - targets: [ - Name( - ExprName { - range: 255..256, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 259..265, - value: Int( - 133333, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 286..298, - targets: [ - Name( - ExprName { - range: 286..287, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 290..298, - value: NumberLiteral( - ExprNumberLiteral { - range: 290..292, - value: Float( - 1.0, - ), - }, - ), - attr: Identifier { - id: "imag", - range: 294..298, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 299..312, - targets: [ - Name( - ExprName { - range: 299..300, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 303..312, - value: NumberLiteral( - ExprNumberLiteral { - range: 303..307, - value: Float( - 10.0, - ), - }, - ), - attr: Identifier { - id: "imag", - range: 308..312, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 313..326, - targets: [ - Name( - ExprName { - range: 313..314, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 317..326, - value: NumberLiteral( - ExprNumberLiteral { - range: 317..321, - value: Float( - 0.1, - ), - }, - ), - attr: Identifier { - id: "real", - range: 322..326, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 327..356, - targets: [ - Name( - ExprName { - range: 327..328, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 331..356, - func: Attribute( - ExprAttribute { - range: 331..354, - value: NumberLiteral( - ExprNumberLiteral { - range: 331..350, - value: Float( - 123456789.12345679, - ), - }, - ), - attr: Identifier { - id: "hex", - range: 351..354, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 354..356, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 357..396, - targets: [ - Name( - ExprName { - range: 357..358, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 361..396, - value: NumberLiteral( - ExprNumberLiteral { - range: 361..390, - value: Float( - inf, - ), - }, - ), - attr: Identifier { - id: "real", - range: 392..396, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 397..433, - targets: [ - Name( - ExprName { - range: 397..398, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 401..433, - func: Attribute( - ExprAttribute { - range: 401..431, - value: NumberLiteral( - ExprNumberLiteral { - range: 401..420, - value: Float( - inf, - ), - }, - ), - attr: Identifier { - id: "conjugate", - range: 422..431, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 431..433, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 434..453, - targets: [ - Name( - ExprName { - range: 434..435, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 438..453, - value: NumberLiteral( - ExprNumberLiteral { - range: 438..448, - value: Complex { - real: 0.0, - imag: 123456789.0, - }, - }, - ), - attr: Identifier { - id: "real", - range: 449..453, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 454..507, - targets: [ - Name( - ExprName { - range: 454..455, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 458..507, - func: Attribute( - ExprAttribute { - range: 458..486, - value: NumberLiteral( - ExprNumberLiteral { - range: 458..478, - value: Complex { - real: 0.0, - imag: 123456789.12345679, - }, - }, - ), - attr: Identifier { - id: "__add__", - range: 479..486, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 486..507, - args: [ - Call( - ExprCall { - range: 487..506, - func: Attribute( - ExprAttribute { - range: 487..504, - value: NumberLiteral( - ExprNumberLiteral { - range: 487..493, - value: Int( - 11, - ), - }, - ), - attr: Identifier { - id: "bit_length", - range: 494..504, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 504..506, - args: [], - keywords: [], - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 508..531, - targets: [ - Name( - ExprName { - range: 508..509, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 512..531, - func: Attribute( - ExprAttribute { - range: 512..529, - value: NumberLiteral( - ExprNumberLiteral { - range: 512..519, - value: Int( - 727756, - ), - }, - ), - attr: Identifier { - id: "conjugate", - range: 520..529, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 529..531, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 532..555, - targets: [ - Name( - ExprName { - range: 532..533, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 536..555, - func: Attribute( - ExprAttribute { - range: 536..553, - value: NumberLiteral( - ExprNumberLiteral { - range: 536..542, - value: Int( - 11, - ), - }, - ), - attr: Identifier { - id: "conjugate", - range: 544..553, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 553..555, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 556..571, - targets: [ - Name( - ExprName { - range: 556..557, - id: "x", - ctx: Store, - }, - ), - ], - value: Attribute( - ExprAttribute { - range: 560..571, - value: NumberLiteral( - ExprNumberLiteral { - range: 560..565, - value: Int( - 511, - ), - }, - ), - attr: Identifier { - id: "real", - range: 567..571, - }, - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 572..595, - targets: [ - Name( - ExprName { - range: 572..573, - id: "x", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 576..595, - func: Attribute( - ExprAttribute { - range: 576..593, - value: NumberLiteral( - ExprNumberLiteral { - range: 576..587, - value: Float( - 6e-9, - ), - }, - ), - attr: Identifier { - id: "hex", - range: 590..593, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 593..595, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 596..610, - targets: [ - Name( - ExprName { - range: 596..597, - id: "x", - ctx: Store, - }, - ), - ], - value: UnaryOp( - ExprUnaryOp { - range: 600..610, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 601..610, - value: Complex { - real: 0.0, - imag: 100.0, - }, - }, - ), - }, - ), - }, - ), - If( - StmtIf { - range: 612..632, - test: Attribute( - ExprAttribute { - range: 615..623, - value: NumberLiteral( - ExprNumberLiteral { - range: 615..617, - value: Int( - 10, - ), - }, - ), - attr: Identifier { - id: "real", - range: 619..623, - }, - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 629..632, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 629..632, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - Assign( - StmtAssign { - range: 677..688, - targets: [ - Name( - ExprName { - range: 677..678, - id: "y", - ctx: Store, - }, - ), - ], - value: Subscript( - ExprSubscript { - range: 681..688, - value: NumberLiteral( - ExprNumberLiteral { - range: 681..684, - value: Int( - 100, - ), - }, - ), - slice: Name( - ExprName { - range: 685..687, - id: "no", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 689..700, - targets: [ - Name( - ExprName { - range: 689..690, - id: "y", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 693..700, - func: NumberLiteral( - ExprNumberLiteral { - range: 693..696, - value: Int( - 100, - ), - }, - ), - arguments: Arguments { - range: 696..700, - args: [ - Name( - ExprName { - range: 697..699, - id: "no", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap.new deleted file mode 100644 index e2d96cfc0c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap.new +++ /dev/null @@ -1,235 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/parenthesized.py ---- -## AST - -``` -Module( - ModModule { - range: 0..92, - body: [ - Expr( - StmtExpr { - range: 0..6, - value: Name( - ExprName { - range: 1..5, - id: "expr", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 7..15, - value: Call( - ExprCall { - range: 7..15, - func: Name( - ExprName { - range: 8..12, - id: "expr", - ctx: Load, - }, - ), - arguments: Arguments { - range: 13..15, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..28, - value: Call( - ExprCall { - range: 16..28, - func: Call( - ExprCall { - range: 16..26, - func: Call( - ExprCall { - range: 16..24, - func: Name( - ExprName { - range: 17..21, - id: "expr", - ctx: Load, - }, - ), - arguments: Arguments { - range: 22..24, - args: [], - keywords: [], - }, - }, - ), - arguments: Arguments { - range: 24..26, - args: [], - keywords: [], - }, - }, - ), - arguments: Arguments { - range: 26..28, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 30..44, - value: BoolOp( - ExprBoolOp { - range: 31..43, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 31..38, - op: And, - values: [ - Name( - ExprName { - range: 31..32, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 37..38, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 42..43, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 45..58, - value: Lambda( - ExprLambda { - range: 46..57, - parameters: Some( - Parameters { - range: 53..54, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 53..54, - parameter: Parameter { - range: 53..54, - name: Identifier { - id: "x", - range: 53..54, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 59..67, - value: Named( - ExprNamed { - range: 60..66, - target: Name( - ExprName { - range: 60..61, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 68..77, - value: Yield( - ExprYield { - range: 69..76, - value: Some( - Name( - ExprName { - range: 75..76, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 78..92, - value: YieldFrom( - ExprYieldFrom { - range: 79..91, - value: Name( - ExprName { - range: 90..91, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap.new deleted file mode 100644 index 823932b2d4..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap.new +++ /dev/null @@ -1,621 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/set.py ---- -## AST - -``` -Module( - ModModule { - range: 0..313, - body: [ - Expr( - StmtExpr { - range: 14..16, - value: Dict( - ExprDict { - range: 14..16, - items: [], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 17..20, - value: Set( - ExprSet { - range: 17..20, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 21..25, - value: Set( - ExprSet { - range: 21..25, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 22..23, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 26..35, - value: Set( - ExprSet { - range: 26..35, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 27..28, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 30..31, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 33..34, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 36..46, - value: Set( - ExprSet { - range: 36..46, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 37..38, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 40..41, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 43..44, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 74..77, - value: Dict( - ExprDict { - range: 74..77, - items: [], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 78..91, - value: Set( - ExprSet { - range: 78..91, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 88..89, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 92..113, - value: Set( - ExprSet { - range: 92..113, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 98..99, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 109..110, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 124..129, - value: Set( - ExprSet { - range: 124..129, - elts: [ - Set( - ExprSet { - range: 125..128, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 126..127, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 130..146, - value: Set( - ExprSet { - range: 130..146, - elts: [ - Set( - ExprSet { - range: 131..137, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 132..133, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 135..136, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - Set( - ExprSet { - range: 139..145, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 140..141, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 143..144, - value: Int( - 4, - ), - }, - ), - ], - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 167..175, - value: Set( - ExprSet { - range: 167..175, - elts: [ - Named( - ExprNamed { - range: 168..174, - target: Name( - ExprName { - range: 168..169, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 173..174, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 176..190, - value: Set( - ExprSet { - range: 176..190, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 177..178, - value: Int( - 1, - ), - }, - ), - Named( - ExprNamed { - range: 180..186, - target: Name( - ExprName { - range: 180..181, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 185..186, - value: Int( - 2, - ), - }, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 188..189, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 191..205, - value: Set( - ExprSet { - range: 191..205, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 192..193, - value: Int( - 1, - ), - }, - ), - Named( - ExprNamed { - range: 196..202, - target: Name( - ExprName { - range: 196..197, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 201..202, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 225..235, - value: Set( - ExprSet { - range: 225..235, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 226..227, - value: Int( - 1, - ), - }, - ), - Starred( - ExprStarred { - range: 229..231, - value: Name( - ExprName { - range: 230..231, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 233..234, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 236..250, - value: Set( - ExprSet { - range: 236..250, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 237..238, - value: Int( - 1, - ), - }, - ), - Starred( - ExprStarred { - range: 240..246, - value: BinOp( - ExprBinOp { - range: 241..246, - left: Name( - ExprName { - range: 241..242, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 245..246, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 248..249, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 273..312, - value: Set( - ExprSet { - range: 273..312, - elts: [ - BinOp( - ExprBinOp { - range: 274..279, - left: NumberLiteral( - ExprNumberLiteral { - range: 274..275, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 278..279, - value: Int( - 2, - ), - }, - ), - }, - ), - Tuple( - ExprTuple { - range: 281..287, - elts: [ - Name( - ExprName { - range: 282..283, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 285..286, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - Set( - ExprSet { - range: 289..298, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 290..291, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 293..294, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 296..297, - value: Int( - 3, - ), - }, - ), - ], - }, - ), - Dict( - ExprDict { - range: 300..311, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 301..302, - id: "a", - ctx: Load, - }, - ), - ), - value: Name( - ExprName { - range: 304..305, - id: "b", - ctx: Load, - }, - ), - }, - DictItem { - key: None, - value: Name( - ExprName { - range: 309..310, - id: "d", - ctx: Load, - }, - ), - }, - ], - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap.new deleted file mode 100644 index 4cd0c84214..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap.new +++ /dev/null @@ -1,742 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/set_comprehension.py ---- -## AST - -``` -Module( - ModModule { - range: 0..492, - body: [ - Expr( - StmtExpr { - range: 0..15, - value: SetComp( - ExprSetComp { - range: 0..15, - elt: Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3..14, - target: Name( - ExprName { - range: 7..8, - id: "i", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 12..14, - id: "ll", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 16..57, - value: SetComp( - ExprSetComp { - range: 16..57, - elt: Name( - ExprName { - range: 17..18, - id: "b", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 19..56, - target: Name( - ExprName { - range: 23..24, - id: "c", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 28..29, - id: "d", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 33..39, - left: Name( - ExprName { - range: 33..34, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 38..39, - id: "w", - ctx: Load, - }, - ), - ], - }, - ), - BoolOp( - ExprBoolOp { - range: 43..51, - op: And, - values: [ - Name( - ExprName { - range: 43..44, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 49..51, - id: "yy", - ctx: Load, - }, - ), - ], - }, - ), - Name( - ExprName { - range: 55..56, - id: "z", - ctx: Load, - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 58..103, - value: SetComp( - ExprSetComp { - range: 58..103, - elt: Name( - ExprName { - range: 59..60, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 61..82, - target: Name( - ExprName { - range: 65..66, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 70..71, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 75..82, - op: And, - values: [ - Name( - ExprName { - range: 75..76, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 81..82, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 83..102, - target: Name( - ExprName { - range: 87..88, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 92..93, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 97..102, - left: Name( - ExprName { - range: 97..98, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 101..102, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 104..155, - value: SetComp( - ExprSetComp { - range: 104..155, - elt: Name( - ExprName { - range: 105..106, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 107..128, - target: Name( - ExprName { - range: 111..112, - id: "b", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 116..117, - id: "c", - ctx: Load, - }, - ), - ifs: [ - BoolOp( - ExprBoolOp { - range: 121..128, - op: And, - values: [ - Name( - ExprName { - range: 121..122, - id: "d", - ctx: Load, - }, - ), - Name( - ExprName { - range: 127..128, - id: "e", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: false, - }, - Comprehension { - range: 129..154, - target: Name( - ExprName { - range: 139..140, - id: "f", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 144..145, - id: "j", - ctx: Load, - }, - ), - ifs: [ - Compare( - ExprCompare { - range: 149..154, - left: Name( - ExprName { - range: 149..150, - id: "k", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - Name( - ExprName { - range: 153..154, - id: "h", - ctx: Load, - }, - ), - ], - }, - ), - ], - is_async: true, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 156..173, - value: SetComp( - ExprSetComp { - range: 156..173, - elt: Name( - ExprName { - range: 157..158, - id: "a", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 159..172, - target: Tuple( - ExprTuple { - range: 163..167, - elts: [ - Name( - ExprName { - range: 163..164, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 166..167, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - iter: Name( - ExprName { - range: 171..172, - id: "G", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 312..334, - value: SetComp( - ExprSetComp { - range: 312..334, - elt: Name( - ExprName { - range: 313..314, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 315..333, - target: Name( - ExprName { - range: 319..320, - id: "x", - ctx: Store, - }, - ), - iter: Yield( - ExprYield { - range: 325..332, - value: Some( - Name( - ExprName { - range: 331..332, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 335..362, - value: SetComp( - ExprSetComp { - range: 335..362, - elt: Name( - ExprName { - range: 336..337, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 338..361, - target: Name( - ExprName { - range: 342..343, - id: "x", - ctx: Store, - }, - ), - iter: YieldFrom( - ExprYieldFrom { - range: 348..360, - value: Name( - ExprName { - range: 359..360, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 363..389, - value: SetComp( - ExprSetComp { - range: 363..389, - elt: Name( - ExprName { - range: 364..365, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 366..388, - target: Name( - ExprName { - range: 370..371, - id: "x", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 376..387, - parameters: Some( - Parameters { - range: 383..384, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 383..384, - parameter: Parameter { - range: 383..384, - name: Identifier { - id: "y", - range: 383..384, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 386..387, - id: "y", - ctx: Load, - }, - ), - }, - ), - ifs: [], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 390..420, - value: SetComp( - ExprSetComp { - range: 390..420, - elt: Name( - ExprName { - range: 391..392, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 393..419, - target: Name( - ExprName { - range: 397..398, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 402..406, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Yield( - ExprYield { - range: 411..418, - value: Some( - Name( - ExprName { - range: 417..418, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 421..456, - value: SetComp( - ExprSetComp { - range: 421..456, - elt: Name( - ExprName { - range: 422..423, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 424..455, - target: Name( - ExprName { - range: 428..429, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 433..437, - id: "data", - ctx: Load, - }, - ), - ifs: [ - YieldFrom( - ExprYieldFrom { - range: 442..454, - value: Name( - ExprName { - range: 453..454, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 457..491, - value: SetComp( - ExprSetComp { - range: 457..491, - elt: Name( - ExprName { - range: 458..459, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 460..490, - target: Name( - ExprName { - range: 464..465, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 469..473, - id: "data", - ctx: Load, - }, - ), - ifs: [ - Lambda( - ExprLambda { - range: 478..489, - parameters: Some( - Parameters { - range: 485..486, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 485..486, - parameter: Parameter { - range: 485..486, - name: Identifier { - id: "y", - range: 485..486, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 488..489, - id: "y", - ctx: Load, - }, - ), - }, - ), - ], - is_async: false, - }, - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap.new deleted file mode 100644 index de1e06c063..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap.new +++ /dev/null @@ -1,656 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/slice.py ---- -## AST - -``` -Module( - ModModule { - range: 0..211, - body: [ - Expr( - StmtExpr { - range: 23..27, - value: Subscript( - ExprSubscript { - range: 23..27, - value: Name( - ExprName { - range: 23..24, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 25..26, - lower: None, - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 28..33, - value: Subscript( - ExprSubscript { - range: 28..33, - value: Name( - ExprName { - range: 28..29, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 30..32, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 30..31, - value: Int( - 1, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 34..39, - value: Subscript( - ExprSubscript { - range: 34..39, - value: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 36..38, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 37..38, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 40..46, - value: Subscript( - ExprSubscript { - range: 40..46, - value: Name( - ExprName { - range: 40..41, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 42..45, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 42..43, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 44..45, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 47..52, - value: Subscript( - ExprSubscript { - range: 47..52, - value: Name( - ExprName { - range: 47..48, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 49..51, - lower: None, - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 53..59, - value: Subscript( - ExprSubscript { - range: 53..59, - value: Name( - ExprName { - range: 53..54, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 55..58, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 55..56, - value: Int( - 1, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 60..66, - value: Subscript( - ExprSubscript { - range: 60..66, - value: Name( - ExprName { - range: 60..61, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 62..65, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 63..64, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 67..74, - value: Subscript( - ExprSubscript { - range: 67..74, - value: Name( - ExprName { - range: 67..68, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 69..73, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 69..70, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 71..72, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 75..81, - value: Subscript( - ExprSubscript { - range: 75..81, - value: Name( - ExprName { - range: 75..76, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 77..80, - lower: None, - upper: None, - step: Some( - NumberLiteral( - ExprNumberLiteral { - range: 79..80, - value: Int( - 3, - ), - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 82..89, - value: Subscript( - ExprSubscript { - range: 82..89, - value: Name( - ExprName { - range: 82..83, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 84..88, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 84..85, - value: Int( - 1, - ), - }, - ), - ), - upper: None, - step: Some( - NumberLiteral( - ExprNumberLiteral { - range: 87..88, - value: Int( - 3, - ), - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 90..97, - value: Subscript( - ExprSubscript { - range: 90..97, - value: Name( - ExprName { - range: 90..91, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 92..96, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 93..94, - value: Int( - 2, - ), - }, - ), - ), - step: Some( - NumberLiteral( - ExprNumberLiteral { - range: 95..96, - value: Int( - 3, - ), - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 98..106, - value: Subscript( - ExprSubscript { - range: 98..106, - value: Name( - ExprName { - range: 98..99, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 100..105, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 100..101, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 102..103, - value: Int( - 2, - ), - }, - ), - ), - step: Some( - NumberLiteral( - ExprNumberLiteral { - range: 104..105, - value: Int( - 3, - ), - }, - ), - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 127..136, - value: Subscript( - ExprSubscript { - range: 127..136, - value: Name( - ExprName { - range: 127..128, - id: "x", - ctx: Load, - }, - ), - slice: Named( - ExprNamed { - range: 129..135, - target: Name( - ExprName { - range: 129..130, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 134..135, - value: Int( - 2, - ), - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 137..149, - value: Subscript( - ExprSubscript { - range: 137..149, - value: Name( - ExprName { - range: 137..138, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 139..148, - lower: Some( - Named( - ExprNamed { - range: 140..146, - target: Name( - ExprName { - range: 140..141, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 145..146, - value: Int( - 2, - ), - }, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 150..160, - value: Subscript( - ExprSubscript { - range: 150..160, - value: Name( - ExprName { - range: 150..151, - id: "x", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 152..159, - elts: [ - Named( - ExprNamed { - range: 152..158, - target: Name( - ExprName { - range: 152..153, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 157..158, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 202..210, - value: Subscript( - ExprSubscript { - range: 202..210, - value: Name( - ExprName { - range: 202..203, - id: "x", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 204..209, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 204..205, - value: Int( - 1, - ), - }, - ), - Slice( - ExprSlice { - range: 206..208, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 207..208, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap.new deleted file mode 100644 index d310ab195a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap.new +++ /dev/null @@ -1,355 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/starred.py ---- -## AST - -``` -Module( - ModModule { - range: 0..172, - body: [ - Expr( - StmtExpr { - range: 0..2, - value: Starred( - ExprStarred { - range: 0..2, - value: Name( - ExprName { - range: 1..2, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 3..11, - value: Starred( - ExprStarred { - range: 3..11, - value: BinOp( - ExprBinOp { - range: 5..10, - left: Name( - ExprName { - range: 5..6, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 1, - ), - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..19, - value: Starred( - ExprStarred { - range: 12..19, - value: Attribute( - ExprAttribute { - range: 13..19, - value: Name( - ExprName { - range: 13..14, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 15..19, - }, - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 21..57, - targets: [ - Name( - ExprName { - range: 21..32, - id: "array_slice", - ctx: Store, - }, - ), - ], - value: Subscript( - ExprSubscript { - range: 35..57, - value: Name( - ExprName { - range: 35..40, - id: "array", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 41..56, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 41..42, - value: Int( - 0, - ), - }, - ), - Starred( - ExprStarred { - range: 44..52, - value: Name( - ExprName { - range: 45..52, - id: "indexes", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - UnaryOp( - ExprUnaryOp { - range: 54..56, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 55..56, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 58..94, - targets: [ - Subscript( - ExprSubscript { - range: 58..80, - value: Name( - ExprName { - range: 58..63, - id: "array", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 64..79, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 64..65, - value: Int( - 0, - ), - }, - ), - Starred( - ExprStarred { - range: 67..75, - value: Name( - ExprName { - range: 68..75, - id: "indexes", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - UnaryOp( - ExprUnaryOp { - range: 77..79, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 78..79, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 83..94, - id: "array_slice", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 95..140, - value: Subscript( - ExprSubscript { - range: 95..140, - value: Name( - ExprName { - range: 95..100, - id: "array", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 101..139, - elts: [ - Starred( - ExprStarred { - range: 101..119, - value: Name( - ExprName { - range: 102..119, - id: "indexes_to_select", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 121..139, - value: Name( - ExprName { - range: 122..139, - id: "indexes_to_select", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 141..171, - value: Subscript( - ExprSubscript { - range: 141..171, - value: Name( - ExprName { - range: 141..146, - id: "array", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 147..170, - elts: [ - Slice( - ExprSlice { - range: 147..150, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 147..148, - value: Int( - 3, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 149..150, - value: Int( - 5, - ), - }, - ), - ), - step: None, - }, - ), - Starred( - ExprStarred { - range: 152..170, - value: Name( - ExprName { - range: 153..170, - id: "indexes_to_select", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap.new deleted file mode 100644 index cddc33cc34..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap.new +++ /dev/null @@ -1,784 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/subscript.py ---- -## AST - -``` -Module( - ModModule { - range: 0..266, - body: [ - Expr( - StmtExpr { - range: 0..10, - value: Subscript( - ExprSubscript { - range: 0..10, - value: Subscript( - ExprSubscript { - range: 0..7, - value: Name( - ExprName { - range: 0..4, - id: "data", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 11..21, - value: Subscript( - ExprSubscript { - range: 11..21, - value: Name( - ExprName { - range: 11..15, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 16..20, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 0, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 19..20, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..31, - value: Subscript( - ExprSubscript { - range: 22..31, - value: Name( - ExprName { - range: 22..26, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 27..30, - elts: [ - Slice( - ExprSlice { - range: 27..29, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 27..28, - value: Int( - 0, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 32..43, - value: Subscript( - ExprSubscript { - range: 32..43, - value: Name( - ExprName { - range: 32..36, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 37..42, - elts: [ - Slice( - ExprSlice { - range: 37..39, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 37..38, - value: Int( - 0, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 41..42, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 44..56, - value: Subscript( - ExprSubscript { - range: 44..56, - value: Name( - ExprName { - range: 44..48, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 49..55, - elts: [ - Slice( - ExprSlice { - range: 49..52, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 49..50, - value: Int( - 0, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 1, - ), - }, - ), - ), - step: None, - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 54..55, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 57..80, - value: Subscript( - ExprSubscript { - range: 57..80, - value: Name( - ExprName { - range: 57..61, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 62..79, - elts: [ - Slice( - ExprSlice { - range: 62..67, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 62..63, - value: Int( - 0, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 64..65, - value: Int( - 1, - ), - }, - ), - ), - step: Some( - NumberLiteral( - ExprNumberLiteral { - range: 66..67, - value: Int( - 2, - ), - }, - ), - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 69..70, - value: Int( - 3, - ), - }, - ), - Slice( - ExprSlice { - range: 72..79, - lower: Some( - Name( - ExprName { - range: 72..73, - id: "a", - ctx: Load, - }, - ), - ), - upper: Some( - BinOp( - ExprBinOp { - range: 74..79, - left: Name( - ExprName { - range: 74..75, - id: "b", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 78..79, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - step: None, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 81..93, - value: Subscript( - ExprSubscript { - range: 81..93, - value: Name( - ExprName { - range: 81..85, - id: "data", - ctx: Load, - }, - ), - slice: Named( - ExprNamed { - range: 86..92, - target: Name( - ExprName { - range: 86..87, - id: "a", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 91..92, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 94..106, - value: Subscript( - ExprSubscript { - range: 94..106, - value: Name( - ExprName { - range: 94..98, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 99..105, - elts: [ - Slice( - ExprSlice { - range: 99..100, - lower: None, - upper: None, - step: None, - }, - ), - Slice( - ExprSlice { - range: 102..105, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 103..105, - value: Int( - 11, - ), - }, - ), - ), - step: None, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 107..120, - value: Subscript( - ExprSubscript { - range: 107..120, - value: Name( - ExprName { - range: 107..111, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 112..119, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 112..113, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 115..116, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 121..132, - value: Subscript( - ExprSubscript { - range: 121..132, - value: Name( - ExprName { - range: 121..125, - id: "data", - ctx: Load, - }, - ), - slice: UnaryOp( - ExprUnaryOp { - range: 126..131, - op: Invert, - operand: Name( - ExprName { - range: 127..131, - id: "flag", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 133..148, - value: Subscript( - ExprSubscript { - range: 133..148, - value: Name( - ExprName { - range: 133..137, - id: "data", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 138..147, - lower: Some( - Named( - ExprNamed { - range: 139..145, - target: Name( - ExprName { - range: 139..140, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 144..145, - value: Int( - 0, - ), - }, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 149..165, - value: Subscript( - ExprSubscript { - range: 149..165, - value: Name( - ExprName { - range: 149..153, - id: "data", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 154..164, - lower: Some( - Named( - ExprNamed { - range: 155..161, - target: Name( - ExprName { - range: 155..156, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 160..161, - value: Int( - 0, - ), - }, - ), - }, - ), - ), - upper: Some( - Name( - ExprName { - range: 163..164, - id: "y", - ctx: Load, - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 226..234, - value: Subscript( - ExprSubscript { - range: 226..234, - value: Name( - ExprName { - range: 226..230, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 231..233, - elts: [ - Starred( - ExprStarred { - range: 231..233, - value: Name( - ExprName { - range: 232..233, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 235..249, - value: Subscript( - ExprSubscript { - range: 235..249, - value: Name( - ExprName { - range: 235..239, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 240..248, - elts: [ - Starred( - ExprStarred { - range: 240..248, - value: BoolOp( - ExprBoolOp { - range: 241..248, - op: And, - values: [ - Name( - ExprName { - range: 241..242, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 247..248, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 250..265, - value: Subscript( - ExprSubscript { - range: 250..265, - value: Name( - ExprName { - range: 250..254, - id: "data", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 255..264, - elts: [ - Starred( - ExprStarred { - range: 255..264, - value: Named( - ExprNamed { - range: 257..263, - target: Name( - ExprName { - range: 257..258, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 262..263, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap.new deleted file mode 100644 index da4b9fcf9d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap.new +++ /dev/null @@ -1,707 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/tuple.py ---- -## AST - -``` -Module( - ModModule { - range: 0..276, - body: [ - Expr( - StmtExpr { - range: 19..21, - value: Tuple( - ExprTuple { - range: 19..21, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 22..26, - value: Tuple( - ExprTuple { - range: 23..25, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 27..37, - value: Tuple( - ExprTuple { - range: 27..37, - elts: [ - Tuple( - ExprTuple { - range: 29..31, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - Tuple( - ExprTuple { - range: 34..36, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 38..42, - value: Tuple( - ExprTuple { - range: 38..42, - elts: [ - Name( - ExprName { - range: 39..40, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 43..49, - value: Tuple( - ExprTuple { - range: 43..49, - elts: [ - Name( - ExprName { - range: 44..45, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 47..48, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 50..57, - value: Tuple( - ExprTuple { - range: 50..57, - elts: [ - Name( - ExprName { - range: 51..52, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 54..55, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 58..66, - value: Tuple( - ExprTuple { - range: 59..65, - elts: [ - Name( - ExprName { - range: 60..61, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 63..64, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 90..92, - value: Tuple( - ExprTuple { - range: 90..92, - elts: [ - Name( - ExprName { - range: 90..91, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 93..97, - value: Tuple( - ExprTuple { - range: 93..97, - elts: [ - Name( - ExprName { - range: 93..94, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 96..97, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 98..103, - value: Tuple( - ExprTuple { - range: 98..103, - elts: [ - Name( - ExprName { - range: 98..99, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 101..102, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 126..129, - value: Tuple( - ExprTuple { - range: 126..129, - elts: [ - Starred( - ExprStarred { - range: 126..128, - value: Name( - ExprName { - range: 127..128, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 130..135, - value: Tuple( - ExprTuple { - range: 130..135, - elts: [ - Name( - ExprName { - range: 130..131, - id: "a", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 133..135, - value: Name( - ExprName { - range: 134..135, - id: "b", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 136..161, - value: Tuple( - ExprTuple { - range: 136..161, - elts: [ - Starred( - ExprStarred { - range: 136..142, - value: BinOp( - ExprBinOp { - range: 137..142, - left: Name( - ExprName { - range: 137..138, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 141..142, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 144..152, - value: Await( - ExprAwait { - range: 145..152, - value: Name( - ExprName { - range: 151..152, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Tuple( - ExprTuple { - range: 154..156, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - Starred( - ExprStarred { - range: 158..161, - value: Tuple( - ExprTuple { - range: 159..161, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 162..167, - value: Tuple( - ExprTuple { - range: 162..167, - elts: [ - Starred( - ExprStarred { - range: 163..165, - value: Name( - ExprName { - range: 164..165, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 168..175, - value: Tuple( - ExprTuple { - range: 168..175, - elts: [ - Name( - ExprName { - range: 169..170, - id: "a", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 172..174, - value: Name( - ExprName { - range: 173..174, - id: "b", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 176..203, - value: Tuple( - ExprTuple { - range: 176..203, - elts: [ - Starred( - ExprStarred { - range: 177..183, - value: BinOp( - ExprBinOp { - range: 178..183, - left: Name( - ExprName { - range: 178..179, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 182..183, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 185..193, - value: Await( - ExprAwait { - range: 186..193, - value: Name( - ExprName { - range: 192..193, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Tuple( - ExprTuple { - range: 195..197, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - Starred( - ExprStarred { - range: 199..202, - value: Tuple( - ExprTuple { - range: 200..202, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 224..233, - value: Tuple( - ExprTuple { - range: 224..233, - elts: [ - Named( - ExprNamed { - range: 225..231, - target: Name( - ExprName { - range: 225..226, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 230..231, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 234..245, - value: Tuple( - ExprTuple { - range: 234..245, - elts: [ - Name( - ExprName { - range: 235..236, - id: "x", - ctx: Load, - }, - ), - Named( - ExprNamed { - range: 238..244, - target: Name( - ExprName { - range: 238..239, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 243..244, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 246..260, - value: Tuple( - ExprTuple { - range: 246..260, - elts: [ - Name( - ExprName { - range: 247..248, - id: "x", - ctx: Load, - }, - ), - Named( - ExprNamed { - range: 250..256, - target: Name( - ExprName { - range: 250..251, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 255..256, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 258..259, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 261..275, - value: Tuple( - ExprTuple { - range: 261..275, - elts: [ - Name( - ExprName { - range: 261..262, - id: "x", - ctx: Load, - }, - ), - Named( - ExprNamed { - range: 265..271, - target: Name( - ExprName { - range: 265..266, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 270..271, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 274..275, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap.new deleted file mode 100644 index 46f0b9200f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap.new +++ /dev/null @@ -1,507 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/unary_op.py ---- -## AST - -``` -Module( - ModModule { - range: 0..276, - body: [ - Expr( - StmtExpr { - range: 9..11, - value: UnaryOp( - ExprUnaryOp { - range: 9..11, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..14, - value: UnaryOp( - ExprUnaryOp { - range: 12..14, - op: UAdd, - operand: NumberLiteral( - ExprNumberLiteral { - range: 13..14, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 15..17, - value: UnaryOp( - ExprUnaryOp { - range: 15..17, - op: Invert, - operand: NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 18..23, - value: UnaryOp( - ExprUnaryOp { - range: 18..23, - op: Not, - operand: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 36..40, - value: UnaryOp( - ExprUnaryOp { - range: 36..40, - op: USub, - operand: UnaryOp( - ExprUnaryOp { - range: 37..40, - op: USub, - operand: UnaryOp( - ExprUnaryOp { - range: 38..40, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 39..40, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 41..45, - value: UnaryOp( - ExprUnaryOp { - range: 41..45, - op: USub, - operand: UnaryOp( - ExprUnaryOp { - range: 42..45, - op: UAdd, - operand: UnaryOp( - ExprUnaryOp { - range: 43..45, - op: Invert, - operand: NumberLiteral( - ExprNumberLiteral { - range: 44..45, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 46..53, - value: UnaryOp( - ExprUnaryOp { - range: 46..53, - op: Not, - operand: UnaryOp( - ExprUnaryOp { - range: 49..53, - op: USub, - operand: UnaryOp( - ExprUnaryOp { - range: 50..53, - op: UAdd, - operand: UnaryOp( - ExprUnaryOp { - range: 51..53, - op: Invert, - operand: NumberLiteral( - ExprNumberLiteral { - range: 52..53, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 54..63, - value: UnaryOp( - ExprUnaryOp { - range: 54..63, - op: Not, - operand: UnaryOp( - ExprUnaryOp { - range: 58..63, - op: Not, - operand: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 84..93, - value: UnaryOp( - ExprUnaryOp { - range: 84..93, - op: USub, - operand: Await( - ExprAwait { - range: 86..93, - value: NumberLiteral( - ExprNumberLiteral { - range: 92..93, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 94..109, - value: UnaryOp( - ExprUnaryOp { - range: 94..109, - op: UAdd, - operand: BinOp( - ExprBinOp { - range: 96..109, - left: Await( - ExprAwait { - range: 96..103, - value: NumberLiteral( - ExprNumberLiteral { - range: 102..103, - value: Int( - 1, - ), - }, - ), - }, - ), - op: Pow, - right: UnaryOp( - ExprUnaryOp { - range: 107..109, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 108..109, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 110..117, - value: UnaryOp( - ExprUnaryOp { - range: 110..117, - op: Invert, - operand: Tuple( - ExprTuple { - range: 111..117, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 112..113, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 115..116, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 118..124, - value: BinOp( - ExprBinOp { - range: 118..124, - left: UnaryOp( - ExprUnaryOp { - range: 118..120, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 119..120, - value: Int( - 1, - ), - }, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 123..124, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 212..246, - value: BoolOp( - ExprBoolOp { - range: 212..246, - op: Or, - values: [ - BoolOp( - ExprBoolOp { - range: 212..223, - op: And, - values: [ - UnaryOp( - ExprUnaryOp { - range: 212..217, - op: Not, - operand: Name( - ExprName { - range: 216..217, - id: "a", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 222..223, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - BoolOp( - ExprBoolOp { - range: 227..246, - op: And, - values: [ - UnaryOp( - ExprUnaryOp { - range: 227..236, - op: Not, - operand: BinOp( - ExprBinOp { - range: 231..236, - left: Name( - ExprName { - range: 231..232, - id: "c", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 235..236, - id: "d", - ctx: Load, - }, - ), - }, - ), - }, - ), - UnaryOp( - ExprUnaryOp { - range: 241..246, - op: Not, - operand: Name( - ExprName { - range: 245..246, - id: "e", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 247..259, - value: UnaryOp( - ExprUnaryOp { - range: 247..259, - op: Not, - operand: Named( - ExprNamed { - range: 252..258, - target: Name( - ExprName { - range: 252..253, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 257..258, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 260..275, - value: UnaryOp( - ExprUnaryOp { - range: 260..275, - op: Not, - operand: BinOp( - ExprBinOp { - range: 264..275, - left: Name( - ExprName { - range: 264..265, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: UnaryOp( - ExprUnaryOp { - range: 269..274, - op: Not, - operand: Name( - ExprName { - range: 273..274, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap.new deleted file mode 100644 index 2337519f10..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap.new +++ /dev/null @@ -1,527 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/yield.py ---- -## AST - -``` -Module( - ModModule { - range: 0..188, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: Yield( - ExprYield { - range: 0..5, - value: None, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 6..13, - value: Yield( - ExprYield { - range: 6..13, - value: Some( - Name( - ExprName { - range: 12..13, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 14..25, - value: Yield( - ExprYield { - range: 14..25, - value: Some( - BinOp( - ExprBinOp { - range: 20..25, - left: Name( - ExprName { - range: 20..21, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 24..25, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 26..39, - value: Yield( - ExprYield { - range: 26..39, - value: Some( - BoolOp( - ExprBoolOp { - range: 32..39, - op: And, - values: [ - Name( - ExprName { - range: 32..33, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 40..52, - value: Yield( - ExprYield { - range: 40..52, - value: Some( - Call( - ExprCall { - range: 46..52, - func: Name( - ExprName { - range: 46..50, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 50..52, - args: [], - keywords: [], - }, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 53..65, - value: Yield( - ExprYield { - range: 53..65, - value: Some( - List( - ExprList { - range: 59..65, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 60..61, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 63..64, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 66..78, - value: Yield( - ExprYield { - range: 66..78, - value: Some( - Set( - ExprSet { - range: 72..78, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 73..74, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 76..77, - value: Int( - 4, - ), - }, - ), - ], - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 79..91, - value: Yield( - ExprYield { - range: 79..91, - value: Some( - Dict( - ExprDict { - range: 85..91, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 86..87, - id: "x", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 92..102, - value: Yield( - ExprYield { - range: 92..102, - value: Some( - Tuple( - ExprTuple { - range: 98..102, - elts: [ - Name( - ExprName { - range: 98..99, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 101..102, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 103..115, - value: Yield( - ExprYield { - range: 103..115, - value: Some( - Tuple( - ExprTuple { - range: 109..115, - elts: [ - Name( - ExprName { - range: 110..111, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 113..114, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 116..128, - value: Yield( - ExprYield { - range: 116..128, - value: Some( - Compare( - ExprCompare { - range: 122..128, - left: Name( - ExprName { - range: 122..123, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 127..128, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 129..143, - value: Yield( - ExprYield { - range: 129..143, - value: Some( - Named( - ExprNamed { - range: 136..142, - target: Name( - ExprName { - range: 136..137, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 141..142, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 144..152, - value: Yield( - ExprYield { - range: 144..152, - value: Some( - Starred( - ExprStarred { - range: 150..152, - value: Name( - ExprName { - range: 151..152, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 153..164, - value: Yield( - ExprYield { - range: 153..164, - value: Some( - Tuple( - ExprTuple { - range: 159..164, - elts: [ - Name( - ExprName { - range: 159..160, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 162..164, - value: Name( - ExprName { - range: 163..164, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 165..174, - value: Yield( - ExprYield { - range: 165..174, - value: Some( - Tuple( - ExprTuple { - range: 171..174, - elts: [ - Starred( - ExprStarred { - range: 171..173, - value: Name( - ExprName { - range: 172..173, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 175..187, - value: Yield( - ExprYield { - range: 175..187, - value: Some( - Starred( - ExprStarred { - range: 181..187, - value: BinOp( - ExprBinOp { - range: 182..187, - left: Name( - ExprName { - range: 182..183, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 186..187, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap.new deleted file mode 100644 index 2d62cd9ff0..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap.new +++ /dev/null @@ -1,375 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/expressions/yield_from.py ---- -## AST - -``` -Module( - ModModule { - range: 0..199, - body: [ - Expr( - StmtExpr { - range: 0..12, - value: YieldFrom( - ExprYieldFrom { - range: 0..12, - value: Name( - ExprName { - range: 11..12, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 13..29, - value: YieldFrom( - ExprYieldFrom { - range: 13..29, - value: BinOp( - ExprBinOp { - range: 24..29, - left: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 30..48, - value: YieldFrom( - ExprYieldFrom { - range: 30..48, - value: BoolOp( - ExprBoolOp { - range: 41..48, - op: And, - values: [ - Name( - ExprName { - range: 41..42, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 47..48, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..66, - value: YieldFrom( - ExprYieldFrom { - range: 49..66, - value: Call( - ExprCall { - range: 60..66, - func: Name( - ExprName { - range: 60..64, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 64..66, - args: [], - keywords: [], - }, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 67..84, - value: YieldFrom( - ExprYieldFrom { - range: 67..84, - value: List( - ExprList { - range: 78..84, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 79..80, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 85..102, - value: YieldFrom( - ExprYieldFrom { - range: 85..102, - value: Set( - ExprSet { - range: 96..102, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 3, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 100..101, - value: Int( - 4, - ), - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 103..120, - value: YieldFrom( - ExprYieldFrom { - range: 103..120, - value: Dict( - ExprDict { - range: 114..120, - items: [ - DictItem { - key: Some( - Name( - ExprName { - range: 115..116, - id: "x", - ctx: Load, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 5, - ), - }, - ), - }, - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 121..138, - value: YieldFrom( - ExprYieldFrom { - range: 121..138, - value: Tuple( - ExprTuple { - range: 132..138, - elts: [ - Name( - ExprName { - range: 133..134, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 136..137, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 139..156, - value: YieldFrom( - ExprYieldFrom { - range: 139..156, - value: Compare( - ExprCompare { - range: 150..156, - left: Name( - ExprName { - range: 150..151, - id: "x", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 155..156, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 157..176, - value: YieldFrom( - ExprYieldFrom { - range: 157..176, - value: Named( - ExprNamed { - range: 169..175, - target: Name( - ExprName { - range: 169..170, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 174..175, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 177..199, - value: YieldFrom( - ExprYieldFrom { - range: 177..199, - value: Tuple( - ExprTuple { - range: 188..199, - elts: [ - Name( - ExprName { - range: 189..190, - id: "x", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 192..198, - value: BinOp( - ExprBinOp { - range: 193..198, - left: Name( - ExprName { - range: 193..194, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 197..198, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap.new deleted file mode 100644 index 93a247d626..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap.new +++ /dev/null @@ -1,203 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/for_in_target_valid_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..89, - body: [ - For( - StmtFor { - range: 0..28, - is_async: false, - target: Subscript( - ExprSubscript { - range: 4..13, - value: Name( - ExprName { - range: 4..5, - id: "d", - ctx: Load, - }, - ), - slice: Compare( - ExprCompare { - range: 6..12, - left: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 11..12, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 17..23, - id: "target", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 29..57, - is_async: false, - target: Subscript( - ExprSubscript { - range: 33..44, - value: Compare( - ExprCompare { - range: 34..40, - left: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 39..40, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 42..43, - value: Int( - 0, - ), - }, - ), - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 48..52, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 54..57, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 54..57, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 58..88, - is_async: false, - target: Attribute( - ExprAttribute { - range: 62..75, - value: Compare( - ExprCompare { - range: 63..69, - left: Name( - ExprName { - range: 63..64, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 68..69, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - attr: Identifier { - id: "attr", - range: 71..75, - }, - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 79..83, - id: "iter", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 85..88, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 85..88, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap.new deleted file mode 100644 index 18bf1eae9b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap.new +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/from_import_no_space.py ---- -## AST - -``` -Module( - ModModule { - range: 0..30, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..13, - module: None, - names: [ - Alias { - range: 12..13, - name: Identifier { - id: "x", - range: 12..13, - }, - asname: None, - }, - ], - level: 1, - }, - ), - ImportFrom( - StmtImportFrom { - range: 14..29, - module: None, - names: [ - Alias { - range: 28..29, - name: Identifier { - id: "x", - range: 28..29, - }, - asname: None, - }, - ], - level: 3, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap.new deleted file mode 100644 index 5200ccac1c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap.new +++ /dev/null @@ -1,104 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/from_import_soft_keyword_module_name.py ---- -## AST - -``` -Module( - ModModule { - range: 0..104, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..25, - module: Some( - Identifier { - id: "match", - range: 5..10, - }, - ), - names: [ - Alias { - range: 18..25, - name: Identifier { - id: "pattern", - range: 18..25, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 26..46, - module: Some( - Identifier { - id: "type", - range: 31..35, - }, - ), - names: [ - Alias { - range: 43..46, - name: Identifier { - id: "bar", - range: 43..46, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 47..71, - module: Some( - Identifier { - id: "case", - range: 52..56, - }, - ), - names: [ - Alias { - range: 64..71, - name: Identifier { - id: "pattern", - range: 64..71, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 72..103, - module: Some( - Identifier { - id: "match.type.case", - range: 77..92, - }, - ), - names: [ - Alias { - range: 100..103, - name: Identifier { - id: "foo", - range: 100..103, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap.new deleted file mode 100644 index 8466d4837b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap.new +++ /dev/null @@ -1,220 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/from_import_stmt_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..97, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..20, - module: Some( - Identifier { - id: "a", - range: 5..6, - }, - ), - names: [ - Alias { - range: 15..16, - name: Identifier { - id: "b", - range: 15..16, - }, - asname: None, - }, - Alias { - range: 18..19, - name: Identifier { - id: "c", - range: 18..19, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 21..41, - module: Some( - Identifier { - id: "a", - range: 26..27, - }, - ), - names: [ - Alias { - range: 36..37, - name: Identifier { - id: "b", - range: 36..37, - }, - asname: None, - }, - Alias { - range: 39..40, - name: Identifier { - id: "c", - range: 39..40, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 43..47, - value: Tuple( - ExprTuple { - range: 43..47, - elts: [ - Name( - ExprName { - range: 43..44, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 46..47, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ImportFrom( - StmtImportFrom { - range: 48..66, - module: Some( - Identifier { - id: "a", - range: 53..54, - }, - ), - names: [ - Alias { - range: 62..63, - name: Identifier { - id: "b", - range: 62..63, - }, - asname: None, - }, - Alias { - range: 65..66, - name: Identifier { - id: "c", - range: 65..66, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 68..72, - value: Tuple( - ExprTuple { - range: 68..72, - elts: [ - Name( - ExprName { - range: 68..69, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 71..72, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ImportFrom( - StmtImportFrom { - range: 73..91, - module: Some( - Identifier { - id: "a", - range: 78..79, - }, - ), - names: [ - Alias { - range: 87..88, - name: Identifier { - id: "b", - range: 87..88, - }, - asname: None, - }, - Alias { - range: 90..91, - name: Identifier { - id: "c", - range: 90..91, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 92..96, - value: Tuple( - ExprTuple { - range: 92..96, - elts: [ - Name( - ExprName { - range: 92..93, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 95..96, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap.new deleted file mode 100644 index 51acdd78c2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap.new +++ /dev/null @@ -1,139 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/fstring_format_spec_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..43, - body: [ - Expr( - StmtExpr { - range: 0..19, - value: FString( - ExprFString { - range: 0..19, - value: FStringValue { - inner: Single( - FString( - FString { - range: 0..19, - elements: [ - Literal( - FStringLiteralElement { - range: 2..8, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 8..12, - expression: Name( - ExprName { - range: 9..10, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 11..11, - elements: [], - }, - ), - }, - ), - Literal( - FStringLiteralElement { - range: 12..18, - value: " world", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 20..42, - value: FString( - ExprFString { - range: 20..42, - value: FStringValue { - inner: Single( - FString( - FString { - range: 20..42, - elements: [ - Literal( - FStringLiteralElement { - range: 22..28, - value: "hello ", - }, - ), - Expression( - FStringExpressionElement { - range: 28..35, - expression: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 31..34, - elements: [ - Literal( - FStringLiteralElement { - range: 31..34, - value: ".3f", - }, - ), - ], - }, - ), - }, - ), - Literal( - FStringLiteralElement { - range: 35..41, - value: " world", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap.new deleted file mode 100644 index 7593631eef..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap.new +++ /dev/null @@ -1,98 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/function_def_parameter_range.py ---- -## AST - -``` -Module( - ModModule { - range: 0..56, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..55, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..43, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 13..23, - parameter: Parameter { - range: 13..23, - name: Identifier { - id: "first", - range: 13..18, - }, - annotation: Some( - Name( - ExprName { - range: 20..23, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 29..40, - parameter: Parameter { - range: 29..40, - name: Identifier { - id: "second", - range: 29..35, - }, - annotation: Some( - Name( - ExprName { - range: 37..40, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 47..50, - id: "int", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 52..55, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 52..55, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap.new deleted file mode 100644 index 6e93831eef..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap.new +++ /dev/null @@ -1,123 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/function_def_parenthesized_return_types.py ---- -## AST - -``` -Module( - ModModule { - range: 0..54, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..24, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Tuple( - ExprTuple { - range: 13..19, - elts: [ - Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 21..24, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 21..24, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 25..53, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 29..32, - }, - type_params: None, - parameters: Parameters { - range: 32..34, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Tuple( - ExprTuple { - range: 38..48, - elts: [ - Name( - ExprName { - range: 39..42, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 44..47, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 50..53, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 50..53, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap.new deleted file mode 100644 index 85f4269018..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap.new +++ /dev/null @@ -1,246 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/function_def_valid_return_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..125, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..27, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..9, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - BinOp( - ExprBinOp { - range: 13..22, - left: Name( - ExprName { - range: 13..16, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 19..22, - id: "str", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 24..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 24..27, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 28..57, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 32..35, - }, - type_params: None, - parameters: Parameters { - range: 35..37, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Lambda( - ExprLambda { - range: 41..52, - parameters: Some( - Parameters { - range: 48..49, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 48..49, - parameter: Parameter { - range: 48..49, - name: Identifier { - id: "x", - range: 48..49, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 51..52, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 54..57, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 54..57, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 58..85, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 62..65, - }, - type_params: None, - parameters: Parameters { - range: 65..67, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Yield( - ExprYield { - range: 72..79, - value: Some( - Name( - ExprName { - range: 78..79, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 82..85, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 82..85, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 86..124, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 90..93, - }, - type_params: None, - parameters: Parameters { - range: 93..95, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - If( - ExprIf { - range: 99..119, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 106..110, - value: true, - }, - ), - body: Name( - ExprName { - range: 99..102, - id: "int", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 116..119, - id: "str", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 121..124, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 121..124, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap.new deleted file mode 100644 index 99892c69e6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap.new +++ /dev/null @@ -1,46 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/global_stmt.py ---- -## AST - -``` -Module( - ModModule { - range: 0..24, - body: [ - Global( - StmtGlobal { - range: 0..8, - names: [ - Identifier { - id: "x", - range: 7..8, - }, - ], - }, - ), - Global( - StmtGlobal { - range: 9..23, - names: [ - Identifier { - id: "x", - range: 16..17, - }, - Identifier { - id: "y", - range: 19..20, - }, - Identifier { - id: "z", - range: 22..23, - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap.new deleted file mode 100644 index 692f881262..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap.new +++ /dev/null @@ -1,76 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/import_as_name_soft_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..58, - body: [ - Import( - StmtImport { - range: 0..19, - names: [ - Alias { - range: 7..19, - name: Identifier { - id: "foo", - range: 7..10, - }, - asname: Some( - Identifier { - id: "match", - range: 14..19, - }, - ), - }, - ], - }, - ), - Import( - StmtImport { - range: 20..38, - names: [ - Alias { - range: 27..38, - name: Identifier { - id: "bar", - range: 27..30, - }, - asname: Some( - Identifier { - id: "case", - range: 34..38, - }, - ), - }, - ], - }, - ), - Import( - StmtImport { - range: 39..57, - names: [ - Alias { - range: 46..57, - name: Identifier { - id: "baz", - range: 46..49, - }, - asname: Some( - Identifier { - id: "type", - range: 53..57, - }, - ), - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap.new deleted file mode 100644 index c773d9340a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap.new +++ /dev/null @@ -1,113 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/import_stmt_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..42, - body: [ - Import( - StmtImport { - range: 0..11, - names: [ - Alias { - range: 7..8, - name: Identifier { - id: "a", - range: 7..8, - }, - asname: None, - }, - Alias { - range: 10..11, - name: Identifier { - id: "b", - range: 10..11, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 13..24, - names: [ - Alias { - range: 20..21, - name: Identifier { - id: "c", - range: 20..21, - }, - asname: None, - }, - Alias { - range: 23..24, - name: Identifier { - id: "d", - range: 23..24, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 25..36, - names: [ - Alias { - range: 32..33, - name: Identifier { - id: "a", - range: 32..33, - }, - asname: None, - }, - Alias { - range: 35..36, - name: Identifier { - id: "b", - range: 35..36, - }, - asname: None, - }, - ], - }, - ), - Expr( - StmtExpr { - range: 37..41, - value: Tuple( - ExprTuple { - range: 37..41, - elts: [ - Name( - ExprName { - range: 37..38, - id: "c", - ctx: Load, - }, - ), - Name( - ExprName { - range: 40..41, - id: "d", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap.new deleted file mode 100644 index 373b7f1e0c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap.new +++ /dev/null @@ -1,349 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/lambda_with_valid_body.py ---- -## AST - -``` -Module( - ModModule { - range: 0..152, - body: [ - Expr( - StmtExpr { - range: 0..11, - value: Lambda( - ExprLambda { - range: 0..11, - parameters: Some( - Parameters { - range: 7..8, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 7..8, - parameter: Parameter { - range: 7..8, - name: Identifier { - id: "x", - range: 7..8, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 10..11, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 12..38, - value: Lambda( - ExprLambda { - range: 12..38, - parameters: Some( - Parameters { - range: 19..20, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 19..20, - parameter: Parameter { - range: 19..20, - name: Identifier { - id: "x", - range: 19..20, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: If( - ExprIf { - range: 22..38, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 27..31, - value: true, - }, - ), - body: Name( - ExprName { - range: 22..23, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 37..38, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 39..56, - value: Lambda( - ExprLambda { - range: 39..56, - parameters: Some( - Parameters { - range: 46..47, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 46..47, - parameter: Parameter { - range: 46..47, - name: Identifier { - id: "x", - range: 46..47, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Await( - ExprAwait { - range: 49..56, - value: Name( - ExprName { - range: 55..56, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 57..82, - value: Lambda( - ExprLambda { - range: 57..82, - parameters: Some( - Parameters { - range: 64..65, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 64..65, - parameter: Parameter { - range: 64..65, - name: Identifier { - id: "x", - range: 64..65, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Lambda( - ExprLambda { - range: 67..82, - parameters: Some( - Parameters { - range: 74..75, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 74..75, - parameter: Parameter { - range: 74..75, - name: Identifier { - id: "y", - range: 74..75, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: BinOp( - ExprBinOp { - range: 77..82, - left: Name( - ExprName { - range: 77..78, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 81..82, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 83..102, - value: Lambda( - ExprLambda { - range: 83..102, - parameters: Some( - Parameters { - range: 90..91, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 90..91, - parameter: Parameter { - range: 90..91, - name: Identifier { - id: "x", - range: 90..91, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Yield( - ExprYield { - range: 94..101, - value: Some( - Name( - ExprName { - range: 100..101, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 136..151, - value: Tuple( - ExprTuple { - range: 136..151, - elts: [ - Lambda( - ExprLambda { - range: 136..147, - parameters: Some( - Parameters { - range: 143..144, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 143..144, - parameter: Parameter { - range: 143..144, - name: Identifier { - id: "x", - range: 143..144, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 146..147, - id: "x", - ctx: Load, - }, - ), - }, - ), - Starred( - ExprStarred { - range: 149..151, - value: Name( - ExprName { - range: 150..151, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap.new deleted file mode 100644 index 9b8e4496b6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap.new +++ /dev/null @@ -1,81 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_as_pattern.py ---- -## AST - -``` -Module( - ModModule { - range: 0..49, - body: [ - Match( - StmtMatch { - range: 0..48, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 15..32, - pattern: MatchAs( - PatternMatchAs { - range: 20..27, - pattern: None, - name: Some( - Identifier { - id: "foo_bar", - range: 20..27, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 29..32, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 29..32, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 37..48, - pattern: MatchAs( - PatternMatchAs { - range: 42..43, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 45..48, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 45..48, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap.new deleted file mode 100644 index 1fb9f6ec9d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap.new +++ /dev/null @@ -1,114 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_as_pattern_soft_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..69, - body: [ - Match( - StmtMatch { - range: 0..68, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 15..29, - pattern: MatchAs( - PatternMatchAs { - range: 20..24, - pattern: None, - name: Some( - Identifier { - id: "case", - range: 20..24, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 26..29, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 26..29, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 34..49, - pattern: MatchAs( - PatternMatchAs { - range: 39..44, - pattern: None, - name: Some( - Identifier { - id: "match", - range: 39..44, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 46..49, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 46..49, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 54..68, - pattern: MatchAs( - PatternMatchAs { - range: 59..63, - pattern: None, - name: Some( - Identifier { - id: "type", - range: 59..63, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 65..68, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 65..68, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap.new deleted file mode 100644 index d89bfac720..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap.new +++ /dev/null @@ -1,232 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_attr_pattern_soft_keyword.py ---- -## AST - -``` -Module( - ModModule { - range: 0..131, - body: [ - Match( - StmtMatch { - range: 0..130, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 15..34, - pattern: MatchValue( - PatternMatchValue { - range: 20..29, - value: Attribute( - ExprAttribute { - range: 20..29, - value: Name( - ExprName { - range: 20..25, - id: "match", - ctx: Load, - }, - ), - attr: Identifier { - id: "bar", - range: 26..29, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 31..34, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 31..34, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 39..57, - pattern: MatchValue( - PatternMatchValue { - range: 44..52, - value: Attribute( - ExprAttribute { - range: 44..52, - value: Name( - ExprName { - range: 44..48, - id: "case", - ctx: Load, - }, - ), - attr: Identifier { - id: "bar", - range: 49..52, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 54..57, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 54..57, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 62..80, - pattern: MatchValue( - PatternMatchValue { - range: 67..75, - value: Attribute( - ExprAttribute { - range: 67..75, - value: Name( - ExprName { - range: 67..71, - id: "type", - ctx: Load, - }, - ), - attr: Identifier { - id: "bar", - range: 72..75, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 77..80, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 77..80, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 85..130, - pattern: MatchValue( - PatternMatchValue { - range: 90..125, - value: Attribute( - ExprAttribute { - range: 90..125, - value: Attribute( - ExprAttribute { - range: 90..119, - value: Attribute( - ExprAttribute { - range: 90..114, - value: Attribute( - ExprAttribute { - range: 90..109, - value: Attribute( - ExprAttribute { - range: 90..105, - value: Attribute( - ExprAttribute { - range: 90..100, - value: Name( - ExprName { - range: 90..95, - id: "match", - ctx: Load, - }, - ), - attr: Identifier { - id: "case", - range: 96..100, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "type", - range: 101..105, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "bar", - range: 106..109, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "type", - range: 110..114, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "case", - range: 115..119, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "match", - range: 120..125, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 127..130, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 127..130, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap.new deleted file mode 100644 index e8d80959f1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap.new +++ /dev/null @@ -1,45 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_identifier_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..18, - body: [ - Expr( - StmtExpr { - range: 0..17, - value: Compare( - ExprCompare { - range: 0..17, - left: Name( - ExprName { - range: 0..5, - id: "match", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( - ExprName { - range: 13..17, - id: "case", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap.new deleted file mode 100644 index 6931cb7b3c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap.new +++ /dev/null @@ -1,320 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_identifier_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..149, - body: [ - Expr( - StmtExpr { - range: 0..5, - value: Name( - ExprName { - range: 0..5, - id: "match", - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 6..18, - value: Compare( - ExprCompare { - range: 6..18, - left: Name( - ExprName { - range: 6..11, - id: "match", - ctx: Load, - }, - ), - ops: [ - NotEq, - ], - comparators: [ - Name( - ExprName { - range: 15..18, - id: "foo", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 19..31, - value: Tuple( - ExprTuple { - range: 19..31, - elts: [ - Name( - ExprName { - range: 20..23, - id: "foo", - ctx: Load, - }, - ), - Name( - ExprName { - range: 25..30, - id: "match", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 32..44, - value: List( - ExprList { - range: 32..44, - elts: [ - Name( - ExprName { - range: 33..36, - id: "foo", - ctx: Load, - }, - ), - Name( - ExprName { - range: 38..43, - id: "match", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 45..57, - value: Set( - ExprSet { - range: 45..57, - elts: [ - Name( - ExprName { - range: 46..49, - id: "foo", - ctx: Load, - }, - ), - Name( - ExprName { - range: 51..56, - id: "match", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 58..63, - value: Name( - ExprName { - range: 58..63, - id: "match", - ctx: Load, - }, - ), - }, - ), - AnnAssign( - StmtAnnAssign { - range: 65..75, - target: Name( - ExprName { - range: 65..70, - id: "match", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 72..75, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - Expr( - StmtExpr { - range: 76..82, - value: Tuple( - ExprTuple { - range: 76..82, - elts: [ - Name( - ExprName { - range: 76..81, - id: "match", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 83..92, - value: Attribute( - ExprAttribute { - range: 83..92, - value: Name( - ExprName { - range: 83..88, - id: "match", - ctx: Load, - }, - ), - attr: Identifier { - id: "foo", - range: 89..92, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 93..104, - value: BinOp( - ExprBinOp { - range: 93..104, - left: Name( - ExprName { - range: 93..98, - id: "match", - ctx: Load, - }, - ), - op: Div, - right: Name( - ExprName { - range: 101..104, - id: "foo", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 105..117, - value: BinOp( - ExprBinOp { - range: 105..117, - left: Name( - ExprName { - range: 105..110, - id: "match", - ctx: Load, - }, - ), - op: LShift, - right: Name( - ExprName { - range: 114..117, - id: "foo", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 118..131, - value: BoolOp( - ExprBoolOp { - range: 118..131, - op: And, - values: [ - Name( - ExprName { - range: 118..123, - id: "match", - ctx: Load, - }, - ), - Name( - ExprName { - range: 128..131, - id: "foo", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Expr( - StmtExpr { - range: 132..148, - value: Compare( - ExprCompare { - range: 132..148, - left: Name( - ExprName { - range: 132..137, - id: "match", - ctx: Load, - }, - ), - ops: [ - IsNot, - ], - comparators: [ - Name( - ExprName { - range: 145..148, - id: "foo", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap.new deleted file mode 100644 index c617621a23..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap.new +++ /dev/null @@ -1,579 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyword_1.py ---- -## AST - -``` -Module( - ModModule { - range: 0..358, - body: [ - Match( - StmtMatch { - range: 0..26, - subject: Name( - ExprName { - range: 6..9, - id: "foo", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 15..26, - pattern: MatchAs( - PatternMatchAs { - range: 20..21, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 23..26, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 23..26, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 27..51, - subject: NumberLiteral( - ExprNumberLiteral { - range: 33..34, - value: Int( - 1, - ), - }, - ), - cases: [ - MatchCase { - range: 40..51, - pattern: MatchAs( - PatternMatchAs { - range: 45..46, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 48..51, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 48..51, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 52..78, - subject: NumberLiteral( - ExprNumberLiteral { - range: 58..61, - value: Float( - 1.0, - ), - }, - ), - cases: [ - MatchCase { - range: 67..78, - pattern: MatchAs( - PatternMatchAs { - range: 72..73, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 75..78, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 75..78, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 79..104, - subject: NumberLiteral( - ExprNumberLiteral { - range: 85..87, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - cases: [ - MatchCase { - range: 93..104, - pattern: MatchAs( - PatternMatchAs { - range: 98..99, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 101..104, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 101..104, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 105..133, - subject: StringLiteral( - ExprStringLiteral { - range: 111..116, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 111..116, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - cases: [ - MatchCase { - range: 122..133, - pattern: MatchAs( - PatternMatchAs { - range: 127..128, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 130..133, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 130..133, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 134..167, - subject: FString( - ExprFString { - range: 140..150, - value: FStringValue { - inner: Single( - FString( - FString { - range: 140..150, - elements: [ - Literal( - FStringLiteralElement { - range: 142..146, - value: "foo ", - }, - ), - Expression( - FStringExpressionElement { - range: 146..149, - expression: Name( - ExprName { - range: 147..148, - id: "x", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - cases: [ - MatchCase { - range: 156..167, - pattern: MatchAs( - PatternMatchAs { - range: 161..162, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 164..167, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 164..167, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 168..197, - subject: Set( - ExprSet { - range: 174..180, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 175..176, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 178..179, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - cases: [ - MatchCase { - range: 186..197, - pattern: MatchAs( - PatternMatchAs { - range: 191..192, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 194..197, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 194..197, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 198..225, - subject: UnaryOp( - ExprUnaryOp { - range: 204..208, - op: Invert, - operand: Name( - ExprName { - range: 205..208, - id: "foo", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 214..225, - pattern: MatchAs( - PatternMatchAs { - range: 219..220, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 222..225, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 222..225, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 226..252, - subject: EllipsisLiteral( - ExprEllipsisLiteral { - range: 232..235, - }, - ), - cases: [ - MatchCase { - range: 241..252, - pattern: MatchAs( - PatternMatchAs { - range: 246..247, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 249..252, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 249..252, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 253..283, - subject: UnaryOp( - ExprUnaryOp { - range: 259..266, - op: Not, - operand: Name( - ExprName { - range: 263..266, - id: "foo", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 272..283, - pattern: MatchAs( - PatternMatchAs { - range: 277..278, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 280..283, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 280..283, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 284..318, - subject: Await( - ExprAwait { - range: 290..301, - value: Call( - ExprCall { - range: 296..301, - func: Name( - ExprName { - range: 296..299, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 299..301, - args: [], - keywords: [], - }, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 307..318, - pattern: MatchAs( - PatternMatchAs { - range: 312..313, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 315..318, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 315..318, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 319..357, - subject: Lambda( - ExprLambda { - range: 325..340, - parameters: Some( - Parameters { - range: 332..335, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 332..335, - parameter: Parameter { - range: 332..335, - name: Identifier { - id: "foo", - range: 332..335, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 337..340, - id: "foo", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 346..357, - pattern: MatchAs( - PatternMatchAs { - range: 351..352, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 354..357, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 354..357, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap.new deleted file mode 100644 index 77e047d7ab..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap.new +++ /dev/null @@ -1,234 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyword_2.py ---- -## AST - -``` -Module( - ModModule { - range: 0..170, - body: [ - Match( - StmtMatch { - range: 0..28, - subject: Name( - ExprName { - range: 6..11, - id: "match", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 17..28, - pattern: MatchAs( - PatternMatchAs { - range: 22..23, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 29..56, - subject: Name( - ExprName { - range: 35..39, - id: "case", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 45..56, - pattern: MatchAs( - PatternMatchAs { - range: 50..51, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 53..56, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 53..56, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 57..84, - subject: Name( - ExprName { - range: 63..67, - id: "type", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 73..84, - pattern: MatchAs( - PatternMatchAs { - range: 78..79, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 81..84, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 81..84, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 85..112, - subject: NoneLiteral( - ExprNoneLiteral { - range: 91..95, - }, - ), - cases: [ - MatchCase { - range: 101..112, - pattern: MatchAs( - PatternMatchAs { - range: 106..107, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 109..112, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 109..112, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 113..140, - subject: BooleanLiteral( - ExprBooleanLiteral { - range: 119..123, - value: true, - }, - ), - cases: [ - MatchCase { - range: 129..140, - pattern: MatchAs( - PatternMatchAs { - range: 134..135, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 137..140, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 137..140, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 141..169, - subject: BooleanLiteral( - ExprBooleanLiteral { - range: 147..152, - value: false, - }, - ), - cases: [ - MatchCase { - range: 158..169, - pattern: MatchAs( - PatternMatchAs { - range: 163..164, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 166..169, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 166..169, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap.new deleted file mode 100644 index 628e4e577d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap.new +++ /dev/null @@ -1,292 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyword_or_identifier.py ---- -## AST - -``` -Module( - ModModule { - range: 0..225, - body: [ - Expr( - StmtExpr { - range: 0..12, - value: Call( - ExprCall { - range: 0..12, - func: Name( - ExprName { - range: 0..5, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 6..12, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 7..8, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 10..11, - value: Int( - 2, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Match( - StmtMatch { - range: 27..67, - subject: Tuple( - ExprTuple { - range: 33..39, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 37..38, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - cases: [ - MatchCase { - range: 56..67, - pattern: MatchAs( - PatternMatchAs { - range: 61..62, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 64..67, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 64..67, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Expr( - StmtExpr { - range: 68..78, - value: Subscript( - ExprSubscript { - range: 68..78, - value: Name( - ExprName { - range: 68..73, - id: "match", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 75..77, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 75..76, - value: Int( - 1, - ), - }, - ), - ), - upper: None, - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - Match( - StmtMatch { - range: 93..133, - subject: List( - ExprList { - range: 99..105, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 100..101, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 103..104, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 122..133, - pattern: MatchAs( - PatternMatchAs { - range: 127..128, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 130..133, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 130..133, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Expr( - StmtExpr { - range: 134..145, - value: BinOp( - ExprBinOp { - range: 134..145, - left: Name( - ExprName { - range: 134..139, - id: "match", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 142..145, - id: "foo", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 160..171, - value: BinOp( - ExprBinOp { - range: 160..171, - left: Name( - ExprName { - range: 160..165, - id: "match", - ctx: Load, - }, - ), - op: Sub, - right: Name( - ExprName { - range: 168..171, - id: "foo", - ctx: Load, - }, - ), - }, - ), - }, - ), - Match( - StmtMatch { - range: 186..224, - subject: UnaryOp( - ExprUnaryOp { - range: 192..196, - op: USub, - operand: Name( - ExprName { - range: 193..196, - id: "foo", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 213..224, - pattern: MatchAs( - PatternMatchAs { - range: 218..219, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 221..224, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 221..224, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap.new deleted file mode 100644 index 9ae0863b8a..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_sequence_pattern_parentheses_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..57, - body: [ - Match( - StmtMatch { - range: 0..56, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 19..35, - pattern: MatchSequence( - PatternMatchSequence { - range: 24..30, - patterns: [ - MatchAs( - PatternMatchAs { - range: 25..26, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 25..26, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 28..29, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 28..29, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 32..35, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 32..35, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 40..56, - pattern: MatchSequence( - PatternMatchSequence { - range: 45..51, - patterns: [ - MatchAs( - PatternMatchAs { - range: 46..47, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 46..47, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 49..50, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 49..50, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 53..56, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 53..56, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap.new deleted file mode 100644 index 47e6c9393b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap.new +++ /dev/null @@ -1,196 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_sequence_pattern_terminator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..95, - body: [ - Match( - StmtMatch { - range: 0..94, - subject: Name( - ExprName { - range: 6..13, - id: "subject", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 19..30, - pattern: MatchAs( - PatternMatchAs { - range: 24..25, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 24..25, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 27..30, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 27..30, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 35..51, - pattern: MatchAs( - PatternMatchAs { - range: 40..41, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 40..41, - }, - ), - }, - ), - guard: Some( - Name( - ExprName { - range: 45..46, - id: "x", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 48..51, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 48..51, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 56..70, - pattern: MatchSequence( - PatternMatchSequence { - range: 61..65, - patterns: [ - MatchAs( - PatternMatchAs { - range: 61..62, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 61..62, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 64..65, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 64..65, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 67..70, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 67..70, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 75..94, - pattern: MatchSequence( - PatternMatchSequence { - range: 80..84, - patterns: [ - MatchAs( - PatternMatchAs { - range: 80..81, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 80..81, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 83..84, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 83..84, - }, - ), - }, - ), - ], - }, - ), - guard: Some( - Name( - ExprName { - range: 88..89, - id: "x", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 91..94, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 91..94, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap.new deleted file mode 100644 index cb7dd6a691..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap.new +++ /dev/null @@ -1,230 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_stmt_subject_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..185, - body: [ - Match( - StmtMatch { - range: 0..29, - subject: Named( - ExprNamed { - range: 6..12, - target: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 1, - ), - }, - ), - }, - ), - cases: [ - MatchCase { - range: 18..29, - pattern: MatchAs( - PatternMatchAs { - range: 23..24, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 26..29, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 26..29, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 30..61, - subject: Named( - ExprNamed { - range: 37..43, - target: Name( - ExprName { - range: 37..38, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 42..43, - value: Int( - 1, - ), - }, - ), - }, - ), - cases: [ - MatchCase { - range: 50..61, - pattern: MatchAs( - PatternMatchAs { - range: 55..56, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 58..61, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 58..61, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 121..153, - subject: Tuple( - ExprTuple { - range: 127..136, - elts: [ - Starred( - ExprStarred { - range: 127..133, - value: BinOp( - ExprBinOp { - range: 128..133, - left: Name( - ExprName { - range: 128..129, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 132..133, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 135..136, - id: "z", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 142..153, - pattern: MatchAs( - PatternMatchAs { - range: 147..148, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 150..153, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 150..153, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 154..184, - subject: Await( - ExprAwait { - range: 160..167, - value: Name( - ExprName { - range: 166..167, - id: "x", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 173..184, - pattern: MatchAs( - PatternMatchAs { - range: 178..179, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 181..184, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 181..184, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap.new deleted file mode 100644 index 28cf8498a5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap.new +++ /dev/null @@ -1,282 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/match_stmt_valid_guard_expr.py ---- -## AST - -``` -Module( - ModModule { - range: 0..158, - body: [ - Match( - StmtMatch { - range: 0..34, - subject: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 13..34, - pattern: MatchAs( - PatternMatchAs { - range: 18..19, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 18..19, - }, - ), - }, - ), - guard: Some( - Named( - ExprNamed { - range: 23..29, - target: Name( - ExprName { - range: 23..24, - id: "a", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 31..34, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 31..34, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 35..79, - subject: Name( - ExprName { - range: 41..42, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 48..79, - pattern: MatchAs( - PatternMatchAs { - range: 53..54, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 53..54, - }, - ), - }, - ), - guard: Some( - If( - ExprIf { - range: 58..74, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 63..67, - value: true, - }, - ), - body: Name( - ExprName { - range: 58..59, - id: "a", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 73..74, - id: "b", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 76..79, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 76..79, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 80..119, - subject: Name( - ExprName { - range: 86..87, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 93..119, - pattern: MatchAs( - PatternMatchAs { - range: 98..99, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 98..99, - }, - ), - }, - ), - guard: Some( - Lambda( - ExprLambda { - range: 103..114, - parameters: Some( - Parameters { - range: 110..111, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 110..111, - parameter: Parameter { - range: 110..111, - name: Identifier { - id: "a", - range: 110..111, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 113..114, - id: "b", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 116..119, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 116..119, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 120..157, - subject: Name( - ExprName { - range: 126..127, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 133..157, - pattern: MatchAs( - PatternMatchAs { - range: 138..139, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 138..139, - }, - ), - }, - ), - guard: Some( - Yield( - ExprYield { - range: 144..151, - value: Some( - Name( - ExprName { - range: 150..151, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 154..157, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 154..157, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap.new deleted file mode 100644 index 76a2e4f5cb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap.new +++ /dev/null @@ -1,46 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/nonlocal_stmt.py ---- -## AST - -``` -Module( - ModModule { - range: 0..28, - body: [ - Nonlocal( - StmtNonlocal { - range: 0..10, - names: [ - Identifier { - id: "x", - range: 9..10, - }, - ], - }, - ), - Nonlocal( - StmtNonlocal { - range: 11..27, - names: [ - Identifier { - id: "x", - range: 20..21, - }, - Identifier { - id: "y", - range: 23..24, - }, - Identifier { - id: "z", - range: 26..27, - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap.new deleted file mode 100644 index e1c86276c2..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap.new +++ /dev/null @@ -1,671 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/other/decorator.py ---- -## AST - -``` -Module( - ModModule { - range: 0..407, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..40, - is_async: false, - decorator_list: [ - Decorator { - range: 0..19, - expression: Name( - ExprName { - range: 1..19, - id: "function_decorator", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "test", - range: 24..28, - }, - type_params: None, - parameters: Parameters { - range: 28..30, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 36..40, - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 43..80, - decorator_list: [ - Decorator { - range: 43..59, - expression: Name( - ExprName { - range: 44..59, - id: "class_decorator", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "Test", - range: 66..70, - }, - type_params: None, - arguments: None, - body: [ - Pass( - StmtPass { - range: 76..80, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 83..106, - is_async: false, - decorator_list: [ - Decorator { - range: 83..93, - expression: Name( - ExprName { - range: 84..93, - id: "decorator", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "f", - range: 98..99, - }, - type_params: None, - parameters: Parameters { - range: 99..101, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 103..106, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 103..106, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 109..128, - is_async: false, - decorator_list: [ - Decorator { - range: 109..115, - expression: Attribute( - ExprAttribute { - range: 110..115, - value: Attribute( - ExprAttribute { - range: 110..113, - value: Name( - ExprName { - range: 110..111, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 112..113, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "c", - range: 114..115, - }, - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "f", - range: 120..121, - }, - type_params: None, - parameters: Parameters { - range: 121..123, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 125..128, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 125..128, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 131..153, - is_async: false, - decorator_list: [ - Decorator { - range: 131..133, - expression: Name( - ExprName { - range: 132..133, - id: "a", - ctx: Load, - }, - ), - }, - Decorator { - range: 134..140, - expression: Attribute( - ExprAttribute { - range: 135..140, - value: Attribute( - ExprAttribute { - range: 135..138, - value: Name( - ExprName { - range: 135..136, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 137..138, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "c", - range: 139..140, - }, - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "f", - range: 145..146, - }, - type_params: None, - parameters: Parameters { - range: 146..148, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 150..153, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 150..153, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 156..185, - decorator_list: [ - Decorator { - range: 156..158, - expression: Name( - ExprName { - range: 157..158, - id: "a", - ctx: Load, - }, - ), - }, - Decorator { - range: 159..165, - expression: BinOp( - ExprBinOp { - range: 160..165, - left: NumberLiteral( - ExprNumberLiteral { - range: 160..161, - value: Int( - 1, - ), - }, - ), - op: BitOr, - right: NumberLiteral( - ExprNumberLiteral { - range: 164..165, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - Decorator { - range: 166..172, - expression: Attribute( - ExprAttribute { - range: 167..172, - value: Attribute( - ExprAttribute { - range: 167..170, - value: Name( - ExprName { - range: 167..168, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 169..170, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "c", - range: 171..172, - }, - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "T", - range: 179..180, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 182..185, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 182..185, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 188..269, - is_async: false, - decorator_list: [ - Decorator { - range: 188..195, - expression: Named( - ExprNamed { - range: 189..195, - target: Name( - ExprName { - range: 189..190, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 194..195, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - Decorator { - range: 196..213, - expression: If( - ExprIf { - range: 197..213, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 202..206, - value: true, - }, - ), - body: Name( - ExprName { - range: 197..198, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 212..213, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - Decorator { - range: 214..226, - expression: Lambda( - ExprLambda { - range: 215..226, - parameters: Some( - Parameters { - range: 222..223, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 222..223, - parameter: Parameter { - range: 222..223, - name: Identifier { - id: "x", - range: 222..223, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 225..226, - id: "x", - ctx: Load, - }, - ), - }, - ), - }, - Decorator { - range: 227..235, - expression: BoolOp( - ExprBoolOp { - range: 228..235, - op: And, - values: [ - Name( - ExprName { - range: 228..229, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 234..235, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - }, - Decorator { - range: 236..246, - expression: Yield( - ExprYield { - range: 238..245, - value: Some( - Name( - ExprName { - range: 244..245, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - Decorator { - range: 247..256, - expression: Tuple( - ExprTuple { - range: 248..256, - elts: [ - Starred( - ExprStarred { - range: 249..251, - value: Name( - ExprName { - range: 250..251, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 253..255, - value: Name( - ExprName { - range: 254..255, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ], - name: Identifier { - id: "f", - range: 261..262, - }, - type_params: None, - parameters: Parameters { - range: 262..264, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 266..269, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 266..269, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 360..380, - is_async: false, - decorator_list: [ - Decorator { - range: 360..365, - expression: BinOp( - ExprBinOp { - range: 361..365, - left: Name( - ExprName { - range: 361..362, - id: "x", - ctx: Load, - }, - ), - op: MatMult, - right: Name( - ExprName { - range: 364..365, - id: "y", - ctx: Load, - }, - ), - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 370..373, - }, - type_params: None, - parameters: Parameters { - range: 373..375, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 377..380, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 377..380, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 383..407, - is_async: false, - decorator_list: [ - Decorator { - range: 383..385, - expression: Name( - ExprName { - range: 384..385, - id: "x", - ctx: Load, - }, - ), - }, - Decorator { - range: 388..390, - expression: Name( - ExprName { - range: 389..390, - id: "y", - ctx: Load, - }, - ), - }, - ], - name: Identifier { - id: "foo", - range: 397..400, - }, - type_params: None, - parameters: Parameters { - range: 400..402, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 404..407, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 404..407, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap.new deleted file mode 100644 index 4268c5e059..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap.new +++ /dev/null @@ -1,279 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/param_with_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..113, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..22, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..17, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..16, - parameter: Parameter { - range: 8..16, - name: Identifier { - id: "arg", - range: 8..11, - }, - annotation: Some( - Name( - ExprName { - range: 13..16, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 19..22, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 19..22, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 23..53, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 27..30, - }, - type_params: None, - parameters: Parameters { - range: 30..48, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 31..47, - parameter: Parameter { - range: 31..47, - name: Identifier { - id: "arg", - range: 31..34, - }, - annotation: Some( - Lambda( - ExprLambda { - range: 36..47, - parameters: Some( - Parameters { - range: 43..44, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 43..44, - parameter: Parameter { - range: 43..44, - name: Identifier { - id: "x", - range: 43..44, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 46..47, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 50..53, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 50..53, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 54..82, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 58..61, - }, - type_params: None, - parameters: Parameters { - range: 61..77, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 62..76, - parameter: Parameter { - range: 62..76, - name: Identifier { - id: "arg", - range: 62..65, - }, - annotation: Some( - Yield( - ExprYield { - range: 68..75, - value: Some( - Name( - ExprName { - range: 74..75, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 79..82, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 79..82, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 83..112, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 87..90, - }, - type_params: None, - parameters: Parameters { - range: 90..107, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 91..106, - parameter: Parameter { - range: 91..106, - name: Identifier { - id: "arg", - range: 91..94, - }, - annotation: Some( - Named( - ExprNamed { - range: 97..105, - target: Name( - ExprName { - range: 97..98, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 102..105, - id: "int", - ctx: Load, - }, - ), - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 109..112, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 109..112, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap.new deleted file mode 100644 index 10aeb8efeb..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap.new +++ /dev/null @@ -1,292 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/param_with_default.py ---- -## AST - -``` -Module( - ModModule { - range: 0..111, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..27, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..22, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..21, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "x", - range: 8..9, - }, - annotation: None, - }, - default: Some( - Lambda( - ExprLambda { - range: 10..21, - parameters: Some( - Parameters { - range: 17..18, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 17..18, - parameter: Parameter { - range: 17..18, - name: Identifier { - id: "y", - range: 17..18, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 20..21, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 24..27, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 24..27, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 28..60, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 32..35, - }, - type_params: None, - parameters: Parameters { - range: 35..55, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 36..54, - parameter: Parameter { - range: 36..37, - name: Identifier { - id: "x", - range: 36..37, - }, - annotation: None, - }, - default: Some( - If( - ExprIf { - range: 38..54, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 43..47, - value: true, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - range: 38..39, - value: Int( - 1, - ), - }, - ), - orelse: NumberLiteral( - ExprNumberLiteral { - range: 53..54, - value: Int( - 2, - ), - }, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 57..60, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 57..60, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 61..84, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 65..68, - }, - type_params: None, - parameters: Parameters { - range: 68..79, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 69..78, - parameter: Parameter { - range: 69..70, - name: Identifier { - id: "x", - range: 69..70, - }, - annotation: None, - }, - default: Some( - Await( - ExprAwait { - range: 71..78, - value: Name( - ExprName { - range: 77..78, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 81..84, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 81..84, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 85..110, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 89..92, - }, - type_params: None, - parameters: Parameters { - range: 92..105, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 93..104, - parameter: Parameter { - range: 93..94, - name: Identifier { - id: "x", - range: 93..94, - }, - annotation: None, - }, - default: Some( - Yield( - ExprYield { - range: 96..103, - value: Some( - Name( - ExprName { - range: 102..103, - id: "y", - ctx: Load, - }, - ), - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 107..110, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 107..110, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap.new deleted file mode 100644 index 3fdeb787cd..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap.new +++ /dev/null @@ -1,156 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/param_with_star_annotation.py ---- -## AST - -``` -Module( - ModModule { - range: 0..67, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..31, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..26, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 8..25, - name: Identifier { - id: "args", - range: 9..13, - }, - annotation: Some( - Starred( - ExprStarred { - range: 15..25, - value: BinOp( - ExprBinOp { - range: 16..25, - left: Name( - ExprName { - range: 16..19, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 22..25, - id: "str", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 28..31, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 28..31, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 32..66, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 36..39, - }, - type_params: None, - parameters: Parameters { - range: 39..61, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 40..60, - name: Identifier { - id: "args", - range: 41..45, - }, - annotation: Some( - Starred( - ExprStarred { - range: 47..60, - value: BoolOp( - ExprBoolOp { - range: 49..59, - op: Or, - values: [ - Name( - ExprName { - range: 49..52, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 56..59, - id: "str", - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 63..66, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 63..66, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap.new deleted file mode 100644 index 1fdb0a95c6..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap.new +++ /dev/null @@ -1,227 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/params_non_default_after_star.py ---- -## AST - -``` -Module( - ModModule { - range: 0..72, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..33, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..28, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 8..12, - parameter: Parameter { - range: 8..9, - name: Identifier { - id: "a", - range: 8..9, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 10..12, - value: Int( - 10, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 17..18, - parameter: Parameter { - range: 17..18, - name: Identifier { - id: "b", - range: 17..18, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 20..24, - parameter: Parameter { - range: 20..21, - name: Identifier { - id: "c", - range: 20..21, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 22..24, - value: Int( - 11, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 26..27, - parameter: Parameter { - range: 26..27, - name: Identifier { - id: "d", - range: 26..27, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 30..33, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 30..33, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 34..71, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 38..41, - }, - type_params: None, - parameters: Parameters { - range: 41..66, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 42..46, - parameter: Parameter { - range: 42..43, - name: Identifier { - id: "a", - range: 42..43, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 44..46, - value: Int( - 10, - ), - }, - ), - ), - }, - ], - vararg: Some( - Parameter { - range: 48..53, - name: Identifier { - id: "args", - range: 49..53, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 55..56, - parameter: Parameter { - range: 55..56, - name: Identifier { - id: "b", - range: 55..56, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 58..62, - parameter: Parameter { - range: 58..59, - name: Identifier { - id: "c", - range: 58..59, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 60..62, - value: Int( - 11, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 64..65, - parameter: Parameter { - range: 64..65, - name: Identifier { - id: "d", - range: 64..65, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 68..71, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 68..71, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap.new deleted file mode 100644 index 31b2f5cdc3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap.new +++ /dev/null @@ -1,135 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/params_seen_keyword_only_param_after_star.py ---- -## AST - -``` -Module( - ModModule { - range: 0..61, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..28, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 4..7, - }, - type_params: None, - parameters: Parameters { - range: 7..23, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 11..12, - parameter: Parameter { - range: 11..12, - name: Identifier { - id: "a", - range: 11..12, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: Some( - Parameter { - range: 14..22, - name: Identifier { - id: "kwargs", - range: 16..22, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 29..60, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 33..36, - }, - type_params: None, - parameters: Parameters { - range: 36..55, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 40..44, - parameter: Parameter { - range: 40..41, - name: Identifier { - id: "a", - range: 40..41, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 42..44, - value: Int( - 10, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 46..54, - name: Identifier { - id: "kwargs", - range: 48..54, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 57..60, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 57..60, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap.new deleted file mode 100644 index bf1e717b88..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap.new +++ /dev/null @@ -1,124 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/simple_stmts_in_block.py ---- -## AST - -``` -Module( - ModModule { - range: 0..84, - body: [ - If( - StmtIf { - range: 0..13, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 3..7, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 9..13, - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 14..27, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 17..21, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 23..27, - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 29..52, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 32..36, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 38..42, - }, - ), - Continue( - StmtContinue { - range: 44..52, - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 53..76, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 56..60, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 62..66, - }, - ), - Continue( - StmtContinue { - range: 68..76, - }, - ), - ], - elif_else_clauses: [], - }, - ), - Assign( - StmtAssign { - range: 78..83, - targets: [ - Name( - ExprName { - range: 78..79, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap.new deleted file mode 100644 index 76fa27529c..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap.new +++ /dev/null @@ -1,91 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/simple_stmts_with_semicolons.py ---- -## AST - -``` -Module( - ModModule { - range: 0..51, - body: [ - Return( - StmtReturn { - range: 0..6, - value: None, - }, - ), - Import( - StmtImport { - range: 8..16, - names: [ - Alias { - range: 15..16, - name: Identifier { - id: "a", - range: 15..16, - }, - asname: None, - }, - ], - }, - ), - ImportFrom( - StmtImportFrom { - range: 18..33, - module: Some( - Identifier { - id: "x", - range: 23..24, - }, - ), - names: [ - Alias { - range: 32..33, - name: Identifier { - id: "y", - range: 32..33, - }, - asname: None, - }, - ], - level: 0, - }, - ), - Expr( - StmtExpr { - range: 35..36, - value: Name( - ExprName { - range: 35..36, - id: "z", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 38..50, - name: Name( - ExprName { - range: 43..44, - id: "T", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 47..50, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap.new deleted file mode 100644 index 429a1e332d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap.new +++ /dev/null @@ -1,4032 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_with_items.py ---- -## AST - -``` -Module( - ModModule { - range: 0..3620, - body: [ - With( - StmtWith { - range: 588..604, - is_async: false, - items: [ - WithItem { - range: 594..598, - context_expr: Name( - ExprName { - range: 594..598, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 601..604, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 601..604, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 605..622, - is_async: false, - items: [ - WithItem { - range: 611..615, - context_expr: Name( - ExprName { - range: 611..615, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 619..622, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 619..622, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 648..668, - is_async: false, - items: [ - WithItem { - range: 654..662, - context_expr: Name( - ExprName { - range: 656..660, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 665..668, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 665..668, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 669..693, - is_async: false, - items: [ - WithItem { - range: 675..680, - context_expr: Name( - ExprName { - range: 675..680, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 682..687, - context_expr: Name( - ExprName { - range: 682..687, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 690..693, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 690..693, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 694..719, - is_async: false, - items: [ - WithItem { - range: 700..705, - context_expr: Name( - ExprName { - range: 700..705, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 707..712, - context_expr: Name( - ExprName { - range: 707..712, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 716..719, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 716..719, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 745..794, - is_async: false, - items: [ - WithItem { - range: 751..758, - context_expr: Name( - ExprName { - range: 752..757, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 760..767, - context_expr: Name( - ExprName { - range: 761..766, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 769..779, - context_expr: Name( - ExprName { - range: 769..774, - id: "item3", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 778..779, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 781..788, - context_expr: Name( - ExprName { - range: 782..787, - id: "item4", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 791..794, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 791..794, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 795..828, - is_async: false, - items: [ - WithItem { - range: 801..815, - context_expr: Tuple( - ExprTuple { - range: 801..815, - elts: [ - Name( - ExprName { - range: 802..807, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 809..814, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 817..822, - context_expr: Name( - ExprName { - range: 817..822, - id: "item3", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 825..828, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 825..828, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 829..852, - is_async: false, - items: [ - WithItem { - range: 835..846, - context_expr: Tuple( - ExprTuple { - range: 835..841, - elts: [ - Name( - ExprName { - range: 836..837, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 839..840, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 845..846, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 849..852, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 849..852, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 853..889, - is_async: false, - items: [ - WithItem { - range: 859..870, - context_expr: Name( - ExprName { - range: 859..864, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 868..870, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 872..883, - context_expr: Name( - ExprName { - range: 872..877, - id: "item2", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 881..883, - id: "f2", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 886..889, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 886..889, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 890..927, - is_async: false, - items: [ - WithItem { - range: 896..907, - context_expr: Name( - ExprName { - range: 896..901, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 905..907, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 909..920, - context_expr: Name( - ExprName { - range: 909..914, - id: "item2", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 918..920, - id: "f2", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 924..927, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 924..927, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 953..976, - is_async: false, - items: [ - WithItem { - range: 959..969, - context_expr: Compare( - ExprCompare { - range: 959..969, - left: Name( - ExprName { - range: 959..963, - id: "item", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 967..969, - value: Int( - 10, - ), - }, - ), - ], - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 973..976, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 973..976, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 977..1001, - is_async: false, - items: [ - WithItem { - range: 983..995, - context_expr: Named( - ExprNamed { - range: 984..994, - target: Name( - ExprName { - range: 984..988, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 992..994, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 998..1001, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 998..1001, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1002..1027, - is_async: false, - items: [ - WithItem { - range: 1008..1021, - context_expr: Tuple( - ExprTuple { - range: 1008..1021, - elts: [ - Named( - ExprNamed { - range: 1009..1019, - target: Name( - ExprName { - range: 1009..1013, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1017..1019, - value: Int( - 10, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1024..1027, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1024..1027, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1028..1048, - is_async: false, - items: [ - WithItem { - range: 1034..1042, - context_expr: Tuple( - ExprTuple { - range: 1034..1042, - elts: [ - Starred( - ExprStarred { - range: 1035..1040, - value: Name( - ExprName { - range: 1036..1040, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1045..1048, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1045..1048, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1049..1081, - is_async: false, - items: [ - WithItem { - range: 1055..1068, - context_expr: Named( - ExprNamed { - range: 1056..1067, - target: Name( - ExprName { - range: 1056..1061, - id: "item1", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1065..1067, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: None, - }, - WithItem { - range: 1070..1075, - context_expr: Name( - ExprName { - range: 1070..1075, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1078..1081, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1078..1081, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1082..1119, - is_async: false, - items: [ - WithItem { - range: 1088..1098, - context_expr: Name( - ExprName { - range: 1088..1093, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1097..1098, - id: "f", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 1100..1113, - context_expr: Named( - ExprNamed { - range: 1101..1112, - target: Name( - ExprName { - range: 1101..1106, - id: "item2", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1110..1112, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1116..1119, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1116..1119, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1120..1137, - is_async: false, - items: [ - WithItem { - range: 1126..1131, - context_expr: Call( - ExprCall { - range: 1126..1131, - func: Name( - ExprName { - range: 1126..1129, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1129..1131, - args: [], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1134..1137, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1134..1137, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1138..1156, - is_async: false, - items: [ - WithItem { - range: 1144..1149, - context_expr: Call( - ExprCall { - range: 1144..1149, - func: Name( - ExprName { - range: 1144..1147, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1147..1149, - args: [], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1153..1156, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1153..1156, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1157..1179, - is_async: false, - items: [ - WithItem { - range: 1163..1173, - context_expr: Call( - ExprCall { - range: 1163..1168, - func: Name( - ExprName { - range: 1163..1166, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1166..1168, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1172..1173, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1176..1179, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1176..1179, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1180..1207, - is_async: false, - items: [ - WithItem { - range: 1186..1201, - context_expr: FString( - ExprFString { - range: 1186..1201, - value: FStringValue { - inner: Single( - FString( - FString { - range: 1186..1201, - elements: [ - Expression( - FStringExpressionElement { - range: 1188..1200, - expression: Name( - ExprName { - range: 1189..1193, - id: "item", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - FStringFormatSpec { - range: 1195..1199, - elements: [ - Literal( - FStringLiteralElement { - range: 1195..1199, - value: "= 42", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1204..1207, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1204..1207, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1208..1237, - is_async: false, - items: [ - WithItem { - range: 1214..1231, - context_expr: FString( - ExprFString { - range: 1214..1231, - value: FStringValue { - inner: Single( - FString( - FString { - range: 1214..1231, - elements: [ - Expression( - FStringExpressionElement { - range: 1216..1230, - expression: Named( - ExprNamed { - range: 1218..1228, - target: Name( - ExprName { - range: 1218..1222, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1226..1228, - value: Int( - 42, - ), - }, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1234..1237, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1234..1237, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1238..1278, - is_async: false, - items: [ - WithItem { - range: 1244..1266, - context_expr: Generator( - ExprGenerator { - range: 1244..1266, - elt: Name( - ExprName { - range: 1245..1246, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 1247..1265, - target: Name( - ExprName { - range: 1251..1252, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 1256..1265, - func: Name( - ExprName { - range: 1256..1261, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1261..1265, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 1262..1264, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 1268..1272, - context_expr: Name( - ExprName { - range: 1268..1272, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1275..1278, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1275..1278, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1279..1319, - is_async: false, - items: [ - WithItem { - range: 1285..1289, - context_expr: Name( - ExprName { - range: 1285..1289, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 1291..1313, - context_expr: Generator( - ExprGenerator { - range: 1291..1313, - elt: Name( - ExprName { - range: 1292..1293, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 1294..1312, - target: Name( - ExprName { - range: 1298..1299, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 1303..1312, - func: Name( - ExprName { - range: 1303..1308, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1308..1312, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 1309..1311, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1316..1319, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1316..1319, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1320..1366, - is_async: false, - items: [ - WithItem { - range: 1326..1330, - context_expr: Name( - ExprName { - range: 1326..1330, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 1332..1354, - context_expr: Generator( - ExprGenerator { - range: 1332..1354, - elt: Name( - ExprName { - range: 1333..1334, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 1335..1353, - target: Name( - ExprName { - range: 1339..1340, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 1344..1353, - func: Name( - ExprName { - range: 1344..1349, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1349..1353, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 1350..1352, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 1356..1360, - context_expr: Name( - ExprName { - range: 1356..1360, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1363..1366, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1363..1366, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1367..1388, - is_async: false, - items: [ - WithItem { - range: 1373..1382, - context_expr: Subscript( - ExprSubscript { - range: 1373..1382, - value: Name( - ExprName { - range: 1373..1377, - id: "data", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 1378..1381, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1378..1379, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1380..1381, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1385..1388, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1385..1388, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1389..1415, - is_async: false, - items: [ - WithItem { - range: 1395..1409, - context_expr: Subscript( - ExprSubscript { - range: 1395..1404, - value: Name( - ExprName { - range: 1395..1399, - id: "data", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 1400..1403, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1400..1401, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1402..1403, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1408..1409, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1412..1415, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1412..1415, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1416..1450, - is_async: false, - items: [ - WithItem { - range: 1422..1444, - context_expr: Generator( - ExprGenerator { - range: 1422..1439, - elt: Name( - ExprName { - range: 1423..1424, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 1425..1438, - target: Name( - ExprName { - range: 1429..1430, - id: "x", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 1434..1438, - id: "iter", - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1443..1444, - id: "y", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1447..1450, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1447..1450, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1663..1684, - is_async: false, - items: [ - WithItem { - range: 1668..1679, - context_expr: Name( - ExprName { - range: 1669..1673, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1678..1679, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1681..1684, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1681..1684, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1685..1707, - is_async: false, - items: [ - WithItem { - range: 1690..1702, - context_expr: Named( - ExprNamed { - range: 1691..1701, - target: Name( - ExprName { - range: 1691..1695, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1699..1701, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1704..1707, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1704..1707, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1708..1735, - is_async: false, - items: [ - WithItem { - range: 1713..1730, - context_expr: Named( - ExprNamed { - range: 1714..1724, - target: Name( - ExprName { - range: 1714..1718, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1722..1724, - value: Int( - 10, - ), - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1729..1730, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1732..1735, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1732..1735, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1736..1762, - is_async: false, - items: [ - WithItem { - range: 1741..1757, - context_expr: Named( - ExprNamed { - range: 1744..1753, - target: Name( - ExprName { - range: 1744..1748, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1752..1753, - value: Int( - 1, - ), - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1759..1762, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1759..1762, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1763..1793, - is_async: false, - items: [ - WithItem { - range: 1768..1781, - context_expr: Named( - ExprNamed { - range: 1769..1780, - target: Name( - ExprName { - range: 1769..1774, - id: "item1", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1778..1780, - value: Int( - 42, - ), - }, - ), - }, - ), - optional_vars: None, - }, - WithItem { - range: 1783..1788, - context_expr: Name( - ExprName { - range: 1783..1788, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1790..1793, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1790..1793, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1794..1828, - is_async: false, - items: [ - WithItem { - range: 1799..1823, - context_expr: Call( - ExprCall { - range: 1799..1823, - func: Attribute( - ExprAttribute { - range: 1799..1821, - value: BinOp( - ExprBinOp { - range: 1800..1815, - left: Name( - ExprName { - range: 1800..1804, - id: "root", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 1807..1815, - id: "filename", - ctx: Load, - }, - ), - }, - ), - attr: Identifier { - id: "read", - range: 1817..1821, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 1821..1823, - args: [], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1825..1828, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1825..1828, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1851..1890, - is_async: false, - items: [ - WithItem { - range: 1856..1885, - context_expr: Call( - ExprCall { - range: 1856..1880, - func: Attribute( - ExprAttribute { - range: 1856..1878, - value: BinOp( - ExprBinOp { - range: 1857..1872, - left: Name( - ExprName { - range: 1857..1861, - id: "root", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 1864..1872, - id: "filename", - ctx: Load, - }, - ), - }, - ), - attr: Identifier { - id: "read", - range: 1874..1878, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 1878..1880, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1884..1885, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1887..1890, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1887..1890, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1913..1930, - is_async: false, - items: [ - WithItem { - range: 1918..1925, - context_expr: Call( - ExprCall { - range: 1918..1925, - func: Name( - ExprName { - range: 1919..1922, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1923..1925, - args: [], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 1927..1930, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1927..1930, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1953..1975, - is_async: false, - items: [ - WithItem { - range: 1958..1970, - context_expr: Call( - ExprCall { - range: 1958..1965, - func: Name( - ExprName { - range: 1959..1962, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1963..1965, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 1969..1970, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 1972..1975, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1972..1975, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 1998..2020, - is_async: false, - items: [ - WithItem { - range: 2003..2015, - context_expr: Call( - ExprCall { - range: 2004..2009, - func: Name( - ExprName { - range: 2004..2007, - id: "foo", - ctx: Load, - }, - ), - arguments: Arguments { - range: 2007..2009, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2014..2015, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2017..2020, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2017..2020, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2021..2047, - is_async: false, - items: [ - WithItem { - range: 2026..2042, - context_expr: Subscript( - ExprSubscript { - range: 2027..2036, - value: Name( - ExprName { - range: 2027..2031, - id: "data", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 2032..2035, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2032..2033, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2034..2035, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2041..2042, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2044..2047, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2044..2047, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2048..2070, - is_async: false, - items: [ - WithItem { - range: 2053..2065, - context_expr: Subscript( - ExprSubscript { - range: 2053..2065, - value: Tuple( - ExprTuple { - range: 2053..2062, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 2054..2055, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2057..2058, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2060..2061, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 2063..2064, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2067..2070, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2067..2070, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2093..2120, - is_async: false, - items: [ - WithItem { - range: 2098..2115, - context_expr: Subscript( - ExprSubscript { - range: 2098..2110, - value: Tuple( - ExprTuple { - range: 2098..2107, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 2099..2100, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2102..2103, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2105..2106, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 2108..2109, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2114..2115, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2117..2120, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2117..2120, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2143..2169, - is_async: false, - items: [ - WithItem { - range: 2148..2155, - context_expr: Name( - ExprName { - range: 2149..2154, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 2157..2164, - context_expr: Name( - ExprName { - range: 2158..2163, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2166..2169, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2166..2169, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2170..2210, - is_async: false, - items: [ - WithItem { - range: 2175..2189, - context_expr: Call( - ExprCall { - range: 2176..2188, - func: Name( - ExprName { - range: 2176..2180, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 2180..2188, - args: [ - StringLiteral( - ExprStringLiteral { - range: 2181..2187, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2181..2187, - value: "a.py", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - WithItem { - range: 2191..2205, - context_expr: Call( - ExprCall { - range: 2192..2204, - func: Name( - ExprName { - range: 2192..2196, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 2196..2204, - args: [ - StringLiteral( - ExprStringLiteral { - range: 2197..2203, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2197..2203, - value: "b.py", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2207..2210, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2207..2210, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2211..2230, - is_async: false, - items: [ - WithItem { - range: 2216..2225, - context_expr: Yield( - ExprYield { - range: 2217..2224, - value: Some( - Name( - ExprName { - range: 2223..2224, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2227..2230, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2227..2230, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2231..2252, - is_async: false, - items: [ - WithItem { - range: 2237..2246, - context_expr: Yield( - ExprYield { - range: 2238..2245, - value: Some( - Name( - ExprName { - range: 2244..2245, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2249..2252, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2249..2252, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2253..2277, - is_async: false, - items: [ - WithItem { - range: 2258..2272, - context_expr: YieldFrom( - ExprYieldFrom { - range: 2259..2271, - value: Name( - ExprName { - range: 2270..2271, - id: "x", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2274..2277, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2274..2277, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2278..2304, - is_async: false, - items: [ - WithItem { - range: 2284..2298, - context_expr: YieldFrom( - ExprYieldFrom { - range: 2285..2297, - value: Name( - ExprName { - range: 2296..2297, - id: "x", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2301..2304, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2301..2304, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2305..2329, - is_async: false, - items: [ - WithItem { - range: 2310..2324, - context_expr: Yield( - ExprYield { - range: 2311..2318, - value: Some( - Name( - ExprName { - range: 2317..2318, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2323..2324, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2326..2329, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2326..2329, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2330..2355, - is_async: false, - items: [ - WithItem { - range: 2335..2350, - context_expr: Yield( - ExprYield { - range: 2336..2344, - value: Some( - Tuple( - ExprTuple { - range: 2342..2344, - elts: [ - Name( - ExprName { - range: 2342..2343, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2349..2350, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2352..2355, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2352..2355, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2741..2753, - is_async: false, - items: [ - WithItem { - range: 2746..2748, - context_expr: Tuple( - ExprTuple { - range: 2746..2748, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2750..2753, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2750..2753, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2754..2771, - is_async: false, - items: [ - WithItem { - range: 2759..2766, - context_expr: Tuple( - ExprTuple { - range: 2759..2761, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2765..2766, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2768..2771, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2768..2771, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2772..2795, - is_async: false, - items: [ - WithItem { - range: 2777..2790, - context_expr: Tuple( - ExprTuple { - range: 2777..2790, - elts: [ - Named( - ExprNamed { - range: 2778..2788, - target: Name( - ExprName { - range: 2778..2782, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 2786..2788, - value: Int( - 42, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2792..2795, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2792..2795, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2796..2820, - is_async: false, - items: [ - WithItem { - range: 2801..2815, - context_expr: Tuple( - ExprTuple { - range: 2801..2815, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 2802..2803, - value: Int( - 1, - ), - }, - ), - Named( - ExprNamed { - range: 2805..2814, - target: Name( - ExprName { - range: 2805..2809, - id: "item", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 2813..2814, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2817..2820, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2817..2820, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2821..2851, - is_async: false, - items: [ - WithItem { - range: 2826..2846, - context_expr: Tuple( - ExprTuple { - range: 2826..2846, - elts: [ - Named( - ExprNamed { - range: 2827..2838, - target: Name( - ExprName { - range: 2827..2832, - id: "item1", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 2836..2838, - value: Int( - 10, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 2840..2845, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2848..2851, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2848..2851, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2852..2893, - is_async: false, - items: [ - WithItem { - range: 2857..2888, - context_expr: Tuple( - ExprTuple { - range: 2857..2883, - elts: [ - Name( - ExprName { - range: 2858..2863, - id: "item1", - ctx: Load, - }, - ), - Named( - ExprNamed { - range: 2865..2875, - target: Name( - ExprName { - range: 2865..2870, - id: "item2", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 2874..2875, - value: Int( - 2, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 2877..2882, - id: "item3", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2887..2888, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2890..2893, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2890..2893, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2894..2916, - is_async: false, - items: [ - WithItem { - range: 2899..2911, - context_expr: Tuple( - ExprTuple { - range: 2899..2906, - elts: [ - Name( - ExprName { - range: 2900..2904, - id: "item", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2910..2911, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2913..2916, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2913..2916, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2917..2935, - is_async: false, - items: [ - WithItem { - range: 2922..2930, - context_expr: Tuple( - ExprTuple { - range: 2922..2930, - elts: [ - Starred( - ExprStarred { - range: 2923..2928, - value: Name( - ExprName { - range: 2924..2928, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 2932..2935, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2932..2935, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2936..2959, - is_async: false, - items: [ - WithItem { - range: 2941..2954, - context_expr: Tuple( - ExprTuple { - range: 2941..2949, - elts: [ - Starred( - ExprStarred { - range: 2942..2947, - value: Name( - ExprName { - range: 2943..2947, - id: "item", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2953..2954, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2956..2959, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2956..2959, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2960..2989, - is_async: false, - items: [ - WithItem { - range: 2965..2984, - context_expr: Tuple( - ExprTuple { - range: 2965..2979, - elts: [ - Name( - ExprName { - range: 2966..2971, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 2973..2978, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 2983..2984, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 2986..2989, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2986..2989, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 2990..3020, - is_async: false, - items: [ - WithItem { - range: 2995..3015, - context_expr: Tuple( - ExprTuple { - range: 2995..3010, - elts: [ - Name( - ExprName { - range: 2996..3001, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3003..3008, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3014..3015, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 3017..3020, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3017..3020, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3021..3052, - is_async: false, - items: [ - WithItem { - range: 3026..3040, - context_expr: Tuple( - ExprTuple { - range: 3026..3040, - elts: [ - Name( - ExprName { - range: 3027..3032, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3034..3039, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 3042..3047, - context_expr: Name( - ExprName { - range: 3042..3047, - id: "item3", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3049..3052, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3049..3052, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3053..3091, - is_async: false, - items: [ - WithItem { - range: 3058..3086, - context_expr: Tuple( - ExprTuple { - range: 3058..3081, - elts: [ - Tuple( - ExprTuple { - range: 3059..3073, - elts: [ - Name( - ExprName { - range: 3060..3065, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3067..3072, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - Name( - ExprName { - range: 3075..3080, - id: "item3", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3085..3086, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 3088..3091, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3088..3091, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3092..3138, - is_async: false, - items: [ - WithItem { - range: 3097..3105, - context_expr: Tuple( - ExprTuple { - range: 3097..3105, - elts: [ - Name( - ExprName { - range: 3098..3103, - id: "item1", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 3107..3112, - context_expr: Name( - ExprName { - range: 3107..3112, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 3114..3133, - context_expr: Tuple( - ExprTuple { - range: 3114..3128, - elts: [ - Name( - ExprName { - range: 3115..3120, - id: "item3", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3122..3127, - id: "item4", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3132..3133, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 3135..3138, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3135..3138, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3139..3182, - is_async: false, - items: [ - WithItem { - range: 3144..3164, - context_expr: Tuple( - ExprTuple { - range: 3144..3158, - elts: [ - Name( - ExprName { - range: 3145..3150, - id: "item1", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3152..3157, - id: "item2", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3162..3164, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 3166..3177, - context_expr: Name( - ExprName { - range: 3166..3171, - id: "item3", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3175..3177, - id: "f2", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 3179..3182, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3179..3182, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3183..3208, - is_async: false, - items: [ - WithItem { - range: 3188..3203, - context_expr: Tuple( - ExprTuple { - range: 3188..3203, - elts: [ - Name( - ExprName { - range: 3189..3194, - id: "item1", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 3196..3202, - value: Name( - ExprName { - range: 3197..3202, - id: "item2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3205..3208, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3205..3208, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3209..3239, - is_async: false, - items: [ - WithItem { - range: 3214..3234, - context_expr: Tuple( - ExprTuple { - range: 3214..3229, - elts: [ - Name( - ExprName { - range: 3215..3220, - id: "item1", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 3222..3228, - value: Name( - ExprName { - range: 3223..3228, - id: "item2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 3233..3234, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 3236..3239, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3236..3239, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3240..3271, - is_async: false, - items: [ - WithItem { - range: 3245..3266, - context_expr: Tuple( - ExprTuple { - range: 3245..3266, - elts: [ - Named( - ExprNamed { - range: 3246..3257, - target: Name( - ExprName { - range: 3246..3251, - id: "item1", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 3255..3257, - value: Int( - 10, - ), - }, - ), - }, - ), - Starred( - ExprStarred { - range: 3259..3265, - value: Name( - ExprName { - range: 3260..3265, - id: "item2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3268..3271, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3268..3271, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3272..3305, - is_async: false, - items: [ - WithItem { - range: 3277..3300, - context_expr: Tuple( - ExprTuple { - range: 3277..3300, - elts: [ - Named( - ExprNamed { - range: 3279..3290, - target: Name( - ExprName { - range: 3279..3284, - id: "item1", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 3288..3290, - value: Int( - 10, - ), - }, - ), - }, - ), - Starred( - ExprStarred { - range: 3293..3299, - value: Name( - ExprName { - range: 3294..3299, - id: "item2", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3302..3305, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3302..3305, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3510..3542, - is_async: false, - items: [ - WithItem { - range: 3515..3537, - context_expr: Generator( - ExprGenerator { - range: 3515..3537, - elt: Name( - ExprName { - range: 3516..3517, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3518..3536, - target: Name( - ExprName { - range: 3522..3523, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 3527..3536, - func: Name( - ExprName { - range: 3527..3532, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3532..3536, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 3533..3535, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3539..3542, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3539..3542, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3543..3581, - is_async: false, - items: [ - WithItem { - range: 3548..3576, - context_expr: Generator( - ExprGenerator { - range: 3548..3576, - elt: Name( - ExprName { - range: 3549..3550, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3551..3575, - target: Name( - ExprName { - range: 3561..3562, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 3566..3575, - func: Name( - ExprName { - range: 3566..3571, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3571..3575, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 3572..3574, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: true, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3578..3581, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3578..3581, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 3582..3620, - is_async: false, - items: [ - WithItem { - range: 3587..3609, - context_expr: Generator( - ExprGenerator { - range: 3587..3609, - elt: Name( - ExprName { - range: 3588..3589, - id: "x", - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 3590..3608, - target: Name( - ExprName { - range: 3594..3595, - id: "x", - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 3599..3608, - func: Name( - ExprName { - range: 3599..3604, - id: "range", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3604..3608, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 3605..3607, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - optional_vars: None, - }, - WithItem { - range: 3611..3615, - context_expr: Name( - ExprName { - range: 3611..3615, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 3617..3620, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3617..3620, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap.new deleted file mode 100644 index 3bc30454c3..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap.new +++ /dev/null @@ -1,274 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/annotated_assignment.py ---- -## AST - -``` -Module( - ModModule { - range: 0..103, - body: [ - AnnAssign( - StmtAnnAssign { - range: 0..6, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 3..6, - id: "int", - ctx: Load, - }, - ), - value: None, - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 7..17, - target: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Store, - }, - ), - annotation: Name( - ExprName { - range: 10..13, - id: "int", - ctx: Load, - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 18..28, - target: Name( - ExprName { - range: 19..20, - id: "x", - ctx: Store, - }, - ), - annotation: BinOp( - ExprBinOp { - range: 23..28, - left: NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 27..28, - value: Int( - 2, - ), - }, - ), - }, - ), - value: None, - simple: false, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 29..55, - target: Name( - ExprName { - range: 29..30, - id: "x", - ctx: Store, - }, - ), - annotation: BinOp( - ExprBinOp { - range: 32..48, - left: Subscript( - ExprSubscript { - range: 32..42, - value: Name( - ExprName { - range: 32..37, - id: "tuple", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 38..41, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 45..48, - id: "int", - ctx: Load, - }, - ), - }, - ), - value: Some( - Tuple( - ExprTuple { - range: 51..55, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 52..53, - value: Int( - 1, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 56..83, - target: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Store, - }, - ), - annotation: If( - ExprIf { - range: 59..79, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 66..70, - value: true, - }, - ), - body: Name( - ExprName { - range: 59..62, - id: "int", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 76..79, - id: "str", - ctx: Load, - }, - ), - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 82..83, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - AnnAssign( - StmtAnnAssign { - range: 84..102, - target: Name( - ExprName { - range: 84..85, - id: "x", - ctx: Store, - }, - ), - annotation: Lambda( - ExprLambda { - range: 87..98, - parameters: Some( - Parameters { - range: 94..95, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 94..95, - parameter: Parameter { - range: 94..95, - name: Identifier { - id: "x", - range: 94..95, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 97..98, - id: "y", - ctx: Load, - }, - ), - }, - ), - value: Some( - NumberLiteral( - ExprNumberLiteral { - range: 101..102, - value: Int( - 1, - ), - }, - ), - ), - simple: true, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap.new deleted file mode 100644 index 6c870ff093..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap.new +++ /dev/null @@ -1,335 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/assert.py ---- -## AST - -``` -Module( - ModModule { - range: 0..186, - body: [ - Assert( - StmtAssert { - range: 0..12, - test: Compare( - ExprCompare { - range: 7..12, - left: NumberLiteral( - ExprNumberLiteral { - range: 7..8, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 13..26, - test: Call( - ExprCall { - range: 20..26, - func: Name( - ExprName { - range: 20..24, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 24..26, - args: [], - keywords: [], - }, - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 27..41, - test: BoolOp( - ExprBoolOp { - range: 34..41, - op: And, - values: [ - Name( - ExprName { - range: 34..35, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 40..41, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 42..60, - test: Lambda( - ExprLambda { - range: 49..60, - parameters: Some( - Parameters { - range: 56..57, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 56..57, - parameter: Parameter { - range: 56..57, - name: Identifier { - id: "x", - range: 56..57, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 59..60, - id: "y", - ctx: Load, - }, - ), - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 61..75, - test: Await( - ExprAwait { - range: 68..75, - value: Name( - ExprName { - range: 74..75, - id: "x", - ctx: Load, - }, - ), - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 76..99, - test: If( - ExprIf { - range: 83..99, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 88..92, - value: true, - }, - ), - body: Name( - ExprName { - range: 83..84, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 98..99, - id: "y", - ctx: Load, - }, - ), - }, - ), - msg: None, - }, - ), - Assert( - StmtAssert { - range: 101..118, - test: Name( - ExprName { - range: 108..109, - id: "x", - ctx: Load, - }, - ), - msg: Some( - StringLiteral( - ExprStringLiteral { - range: 111..118, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 111..118, - value: "error", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - }, - ), - Assert( - StmtAssert { - range: 119..140, - test: Name( - ExprName { - range: 126..127, - id: "x", - ctx: Load, - }, - ), - msg: Some( - Lambda( - ExprLambda { - range: 129..140, - parameters: Some( - Parameters { - range: 136..137, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 136..137, - parameter: Parameter { - range: 136..137, - name: Identifier { - id: "x", - range: 136..137, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 139..140, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Assert( - StmtAssert { - range: 141..158, - test: Name( - ExprName { - range: 148..149, - id: "x", - ctx: Load, - }, - ), - msg: Some( - Await( - ExprAwait { - range: 151..158, - value: Name( - ExprName { - range: 157..158, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Assert( - StmtAssert { - range: 159..185, - test: Name( - ExprName { - range: 166..167, - id: "x", - ctx: Load, - }, - ), - msg: Some( - If( - ExprIf { - range: 169..185, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 174..178, - value: true, - }, - ), - body: Name( - ExprName { - range: 169..170, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 184..185, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap.new deleted file mode 100644 index f03fb86219..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap.new +++ /dev/null @@ -1,955 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/assignment.py ---- -## AST - -``` -Module( - ModModule { - range: 0..734, - body: [ - Assign( - StmtAssign { - range: 0..13, - targets: [ - Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 4..13, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 8..9, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 11..12, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 15..33, - targets: [ - Tuple( - ExprTuple { - range: 15..21, - elts: [ - Name( - ExprName { - range: 16..17, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 19..20, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 24..33, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 25..26, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 28..29, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 31..32, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 35..53, - targets: [ - List( - ExprList { - range: 35..41, - elts: [ - Name( - ExprName { - range: 36..37, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 39..40, - id: "y", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 44..53, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 45..46, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 48..49, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 55..70, - targets: [ - Attribute( - ExprAttribute { - range: 55..58, - value: Name( - ExprName { - range: 55..56, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "y", - range: 57..58, - }, - ctx: Store, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 61..70, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 62..63, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 65..66, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 68..69, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 72..88, - targets: [ - Subscript( - ExprSubscript { - range: 72..76, - value: Name( - ExprName { - range: 72..73, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 74..75, - id: "y", - ctx: Load, - }, - ), - ctx: Store, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 79..88, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 80..81, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 86..87, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 90..109, - targets: [ - Tuple( - ExprTuple { - range: 90..97, - elts: [ - Name( - ExprName { - range: 91..92, - id: "x", - ctx: Store, - }, - ), - Starred( - ExprStarred { - range: 94..96, - value: Name( - ExprName { - range: 95..96, - id: "y", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 100..109, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 101..102, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 104..105, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 107..108, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 259..268, - targets: [ - Starred( - ExprStarred { - range: 259..263, - value: Name( - ExprName { - range: 260..263, - id: "foo", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 266..268, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 270..291, - targets: [ - List( - ExprList { - range: 270..279, - elts: [ - Name( - ExprName { - range: 271..272, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 274..275, - id: "y", - ctx: Store, - }, - ), - Name( - ExprName { - range: 277..278, - id: "z", - ctx: Store, - }, - ), - ], - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 282..291, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 283..284, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 286..287, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 289..290, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 293..314, - targets: [ - Tuple( - ExprTuple { - range: 293..302, - elts: [ - Name( - ExprName { - range: 294..295, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 297..298, - id: "y", - ctx: Store, - }, - ), - Name( - ExprName { - range: 300..301, - id: "z", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - ], - value: Tuple( - ExprTuple { - range: 305..314, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 306..307, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 309..310, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 312..313, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 315..324, - targets: [ - Subscript( - ExprSubscript { - range: 315..319, - value: Name( - ExprName { - range: 315..316, - id: "x", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 317..318, - value: Int( - 0, - ), - }, - ), - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 322..324, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 421..430, - targets: [ - Subscript( - ExprSubscript { - range: 421..425, - value: NumberLiteral( - ExprNumberLiteral { - range: 421..422, - value: Int( - 5, - ), - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 423..424, - value: Int( - 0, - ), - }, - ), - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 428..430, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 431..444, - targets: [ - Subscript( - ExprSubscript { - range: 431..437, - value: Name( - ExprName { - range: 431..432, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 433..436, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 433..434, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 435..436, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 440..444, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 441..443, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 540..553, - targets: [ - Subscript( - ExprSubscript { - range: 540..546, - value: NumberLiteral( - ExprNumberLiteral { - range: 540..541, - value: Int( - 5, - ), - }, - ), - slice: Slice( - ExprSlice { - range: 542..545, - lower: Some( - NumberLiteral( - ExprNumberLiteral { - range: 542..543, - value: Int( - 1, - ), - }, - ), - ), - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 544..545, - value: Int( - 2, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Store, - }, - ), - ], - value: List( - ExprList { - range: 549..553, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 550..552, - value: Int( - 42, - ), - }, - ), - ], - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 555..567, - targets: [ - Attribute( - ExprAttribute { - range: 555..562, - value: Name( - ExprName { - range: 555..558, - id: "foo", - ctx: Load, - }, - ), - attr: Identifier { - id: "bar", - range: 559..562, - }, - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 565..567, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 669..681, - targets: [ - Attribute( - ExprAttribute { - range: 669..676, - value: StringLiteral( - ExprStringLiteral { - range: 669..674, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 669..674, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - attr: Identifier { - id: "y", - range: 675..676, - }, - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 679..681, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 683..691, - targets: [ - Name( - ExprName { - range: 683..686, - id: "foo", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 689..691, - value: Int( - 42, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 693..703, - targets: [ - List( - ExprList { - range: 693..695, - elts: [], - ctx: Store, - }, - ), - ], - value: Starred( - ExprStarred { - range: 698..703, - value: Name( - ExprName { - range: 699..703, - id: "data", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 704..714, - targets: [ - Tuple( - ExprTuple { - range: 704..706, - elts: [], - ctx: Store, - parenthesized: true, - }, - ), - ], - value: Starred( - ExprStarred { - range: 709..714, - value: Name( - ExprName { - range: 710..714, - id: "data", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 715..724, - targets: [ - Tuple( - ExprTuple { - range: 715..719, - elts: [ - Name( - ExprName { - range: 715..716, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 718..719, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - ], - value: Name( - ExprName { - range: 722..724, - id: "ab", - ctx: Load, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 725..734, - targets: [ - Name( - ExprName { - range: 725..726, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 729..730, - id: "b", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 733..734, - id: "c", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap.new deleted file mode 100644 index 7f1a12b114..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap.new +++ /dev/null @@ -1,485 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/augmented_assignment.py ---- -## AST - -``` -Module( - ModModule { - range: 0..212, - body: [ - AugAssign( - StmtAugAssign { - range: 0..6, - target: Name( - ExprName { - range: 0..1, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 7..23, - target: Attribute( - ExprAttribute { - range: 7..10, - value: Name( - ExprName { - range: 7..8, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "y", - range: 9..10, - }, - ctx: Store, - }, - ), - op: Add, - value: Tuple( - ExprTuple { - range: 14..23, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 15..16, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 18..19, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 21..22, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 24..41, - target: Subscript( - ExprSubscript { - range: 24..28, - value: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 26..27, - id: "y", - ctx: Load, - }, - ), - ctx: Store, - }, - ), - op: Add, - value: Tuple( - ExprTuple { - range: 32..41, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 33..34, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 36..37, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 39..40, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 86..92, - target: Name( - ExprName { - range: 86..87, - id: "x", - ctx: Store, - }, - ), - op: Add, - value: NumberLiteral( - ExprNumberLiteral { - range: 91..92, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 93..99, - target: Name( - ExprName { - range: 93..94, - id: "x", - ctx: Store, - }, - ), - op: Sub, - value: NumberLiteral( - ExprNumberLiteral { - range: 98..99, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 100..106, - target: Name( - ExprName { - range: 100..101, - id: "x", - ctx: Store, - }, - ), - op: Mult, - value: NumberLiteral( - ExprNumberLiteral { - range: 105..106, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 107..113, - target: Name( - ExprName { - range: 107..108, - id: "x", - ctx: Store, - }, - ), - op: Div, - value: NumberLiteral( - ExprNumberLiteral { - range: 112..113, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 114..121, - target: Name( - ExprName { - range: 114..115, - id: "x", - ctx: Store, - }, - ), - op: FloorDiv, - value: NumberLiteral( - ExprNumberLiteral { - range: 120..121, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 122..128, - target: Name( - ExprName { - range: 122..123, - id: "x", - ctx: Store, - }, - ), - op: Mod, - value: NumberLiteral( - ExprNumberLiteral { - range: 127..128, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 129..136, - target: Name( - ExprName { - range: 129..130, - id: "x", - ctx: Store, - }, - ), - op: Pow, - value: NumberLiteral( - ExprNumberLiteral { - range: 135..136, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 137..143, - target: Name( - ExprName { - range: 137..138, - id: "x", - ctx: Store, - }, - ), - op: BitAnd, - value: NumberLiteral( - ExprNumberLiteral { - range: 142..143, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 144..150, - target: Name( - ExprName { - range: 144..145, - id: "x", - ctx: Store, - }, - ), - op: BitOr, - value: NumberLiteral( - ExprNumberLiteral { - range: 149..150, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 151..157, - target: Name( - ExprName { - range: 151..152, - id: "x", - ctx: Store, - }, - ), - op: BitXor, - value: NumberLiteral( - ExprNumberLiteral { - range: 156..157, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 158..165, - target: Name( - ExprName { - range: 158..159, - id: "x", - ctx: Store, - }, - ), - op: LShift, - value: NumberLiteral( - ExprNumberLiteral { - range: 164..165, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 166..173, - target: Name( - ExprName { - range: 166..167, - id: "x", - ctx: Store, - }, - ), - op: RShift, - value: NumberLiteral( - ExprNumberLiteral { - range: 172..173, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 174..180, - target: Name( - ExprName { - range: 174..175, - id: "x", - ctx: Store, - }, - ), - op: MatMult, - value: NumberLiteral( - ExprNumberLiteral { - range: 179..180, - value: Int( - 1, - ), - }, - ), - }, - ), - AugAssign( - StmtAugAssign { - range: 190..212, - target: Name( - ExprName { - range: 190..191, - id: "a", - ctx: Store, - }, - ), - op: FloorDiv, - value: BinOp( - ExprBinOp { - range: 196..212, - left: BinOp( - ExprBinOp { - range: 197..202, - left: Name( - ExprName { - range: 197..198, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 201..202, - id: "b", - ctx: Load, - }, - ), - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 206..212, - left: Name( - ExprName { - range: 206..207, - id: "c", - ctx: Load, - }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 211..212, - value: Int( - 2, - ), - }, - ), - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap.new deleted file mode 100644 index 8e6242ae81..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap.new +++ /dev/null @@ -1,1243 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/class.py ---- -## AST - -``` -Module( - ModModule { - range: 0..1023, - body: [ - ClassDef( - StmtClassDef { - range: 0..19, - decorator_list: [], - name: Identifier { - id: "Test", - range: 6..10, - }, - type_params: None, - arguments: None, - body: [ - Expr( - StmtExpr { - range: 16..19, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 16..19, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 22..80, - decorator_list: [], - name: Identifier { - id: "Test", - range: 28..32, - }, - type_params: None, - arguments: Some( - Arguments { - range: 32..34, - args: [], - keywords: [], - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 44..80, - is_async: false, - decorator_list: [], - name: Identifier { - id: "__init__", - range: 48..56, - }, - type_params: None, - parameters: Parameters { - range: 56..62, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 57..61, - parameter: Parameter { - range: 57..61, - name: Identifier { - id: "self", - range: 57..61, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 76..80, - }, - ), - ], - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 83..116, - decorator_list: [], - name: Identifier { - id: "Test", - range: 89..93, - }, - type_params: None, - arguments: Some( - Arguments { - range: 93..107, - args: [ - Starred( - ExprStarred { - range: 99..101, - value: Name( - ExprName { - range: 100..101, - id: "A", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 94..97, - arg: Some( - Identifier { - id: "a", - range: 94..95, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 96..97, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 103..106, - arg: None, - value: Name( - ExprName { - range: 105..106, - id: "k", - ctx: Load, - }, - ), - }, - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 113..116, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 113..116, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 119..168, - decorator_list: [], - name: Identifier { - id: "Test", - range: 125..129, - }, - type_params: None, - arguments: None, - body: [ - FunctionDef( - StmtFunctionDef { - range: 135..168, - is_async: false, - decorator_list: [], - name: Identifier { - id: "method", - range: 139..145, - }, - type_params: None, - parameters: Parameters { - range: 145..147, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Assign( - StmtAssign { - range: 157..168, - targets: [ - Tuple( - ExprTuple { - range: 157..161, - elts: [ - Name( - ExprName { - range: 157..158, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 160..161, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - ], - value: Name( - ExprName { - range: 164..168, - id: "data", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 171..289, - decorator_list: [], - name: Identifier { - id: "Test", - range: 177..181, - }, - type_params: None, - arguments: Some( - Arguments { - range: 181..187, - args: [ - Name( - ExprName { - range: 182..183, - id: "A", - ctx: Load, - }, - ), - Name( - ExprName { - range: 185..186, - id: "B", - ctx: Load, - }, - ), - ], - keywords: [], - }, - ), - body: [ - FunctionDef( - StmtFunctionDef { - range: 193..225, - is_async: false, - decorator_list: [], - name: Identifier { - id: "__init__", - range: 197..205, - }, - type_params: None, - parameters: Parameters { - range: 205..211, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 206..210, - parameter: Parameter { - range: 206..210, - name: Identifier { - id: "self", - range: 206..210, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 221..225, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 231..289, - is_async: false, - decorator_list: [], - name: Identifier { - id: "method_with_default", - range: 235..254, - }, - type_params: None, - parameters: Parameters { - range: 254..275, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 255..259, - parameter: Parameter { - range: 255..259, - name: Identifier { - id: "self", - range: 255..259, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 261..274, - parameter: Parameter { - range: 261..264, - name: Identifier { - id: "arg", - range: 261..264, - }, - annotation: None, - }, - default: Some( - StringLiteral( - ExprStringLiteral { - range: 265..274, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 265..274, - value: "default", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 285..289, - }, - ), - ], - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 331..351, - decorator_list: [], - name: Identifier { - id: "Test", - range: 337..341, - }, - type_params: Some( - TypeParams { - range: 341..344, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 342..343, - name: Identifier { - id: "T", - range: 342..343, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 344..346, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 348..351, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 348..351, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 376..402, - decorator_list: [], - name: Identifier { - id: "Test", - range: 382..386, - }, - type_params: Some( - TypeParams { - range: 386..395, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 387..394, - name: Identifier { - id: "T", - range: 387..388, - }, - bound: None, - default: Some( - Name( - ExprName { - range: 391..394, - id: "str", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 395..397, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 399..402, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 399..402, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 425..450, - decorator_list: [], - name: Identifier { - id: "Test", - range: 431..435, - }, - type_params: Some( - TypeParams { - range: 435..443, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 436..442, - name: Identifier { - id: "T", - range: 436..437, - }, - bound: Some( - Name( - ExprName { - range: 439..442, - id: "str", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 443..445, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 447..450, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 447..450, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 485..522, - decorator_list: [], - name: Identifier { - id: "Test", - range: 491..495, - }, - type_params: Some( - TypeParams { - range: 495..515, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 496..514, - name: Identifier { - id: "T", - range: 496..497, - }, - bound: Some( - BinOp( - ExprBinOp { - range: 499..508, - left: Name( - ExprName { - range: 499..502, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 505..508, - id: "str", - ctx: Load, - }, - ), - }, - ), - ), - default: Some( - Name( - ExprName { - range: 511..514, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 515..517, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 519..522, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 519..522, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 551..585, - decorator_list: [], - name: Identifier { - id: "Test", - range: 557..561, - }, - type_params: Some( - TypeParams { - range: 561..578, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 562..577, - name: Identifier { - id: "T", - range: 562..563, - }, - bound: Some( - Tuple( - ExprTuple { - range: 565..577, - elts: [ - Name( - ExprName { - range: 566..569, - id: "str", - ctx: Load, - }, - ), - Name( - ExprName { - range: 571..576, - id: "bytes", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 578..580, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 582..585, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 582..585, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 606..629, - decorator_list: [], - name: Identifier { - id: "Test", - range: 612..616, - }, - type_params: Some( - TypeParams { - range: 616..622, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 617..618, - name: Identifier { - id: "T", - range: 617..618, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 620..621, - name: Identifier { - id: "U", - range: 620..621, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 622..624, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 626..629, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 626..629, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 648..672, - decorator_list: [], - name: Identifier { - id: "Test", - range: 654..658, - }, - type_params: Some( - TypeParams { - range: 658..665, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 659..660, - name: Identifier { - id: "T", - range: 659..660, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 662..663, - name: Identifier { - id: "U", - range: 662..663, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 665..667, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 669..672, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 669..672, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 689..711, - decorator_list: [], - name: Identifier { - id: "Test", - range: 695..699, - }, - type_params: Some( - TypeParams { - range: 699..704, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 700..703, - name: Identifier { - id: "Ts", - range: 701..703, - }, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 704..706, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 708..711, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 708..711, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 741..789, - decorator_list: [], - name: Identifier { - id: "Test", - range: 747..751, - }, - type_params: Some( - TypeParams { - range: 751..782, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 752..781, - name: Identifier { - id: "Ts", - range: 753..755, - }, - default: Some( - Subscript( - ExprSubscript { - range: 758..781, - value: Name( - ExprName { - range: 758..764, - id: "Unpack", - ctx: Load, - }, - ), - slice: Subscript( - ExprSubscript { - range: 765..780, - value: Name( - ExprName { - range: 765..770, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 771..779, - elts: [ - Name( - ExprName { - range: 771..774, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 776..779, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 782..784, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 786..789, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 786..789, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 827..868, - decorator_list: [], - name: Identifier { - id: "Test", - range: 833..837, - }, - type_params: Some( - TypeParams { - range: 837..861, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 838..860, - name: Identifier { - id: "Ts", - range: 839..841, - }, - default: Some( - Starred( - ExprStarred { - range: 844..860, - value: Subscript( - ExprSubscript { - range: 845..860, - value: Name( - ExprName { - range: 845..850, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 851..859, - elts: [ - Name( - ExprName { - range: 851..854, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 856..859, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 861..863, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 865..868, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 865..868, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 882..904, - decorator_list: [], - name: Identifier { - id: "Test", - range: 888..892, - }, - type_params: Some( - TypeParams { - range: 892..897, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 893..896, - name: Identifier { - id: "P", - range: 895..896, - }, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 897..899, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 901..904, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 901..904, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 931..966, - decorator_list: [], - name: Identifier { - id: "Test", - range: 937..941, - }, - type_params: Some( - TypeParams { - range: 941..959, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 942..958, - name: Identifier { - id: "P", - range: 944..945, - }, - default: Some( - List( - ExprList { - range: 948..958, - elts: [ - Name( - ExprName { - range: 949..952, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 954..957, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 959..961, - args: [], - keywords: [], - }, - ), - body: [ - Expr( - StmtExpr { - range: 963..966, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 963..966, - }, - ), - }, - ), - ], - }, - ), - ClassDef( - StmtClassDef { - range: 982..1022, - decorator_list: [], - name: Identifier { - id: "Test", - range: 988..992, - }, - type_params: Some( - TypeParams { - range: 992..1012, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 993..994, - name: Identifier { - id: "X", - range: 993..994, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 996..1002, - name: Identifier { - id: "Y", - range: 996..997, - }, - bound: Some( - Name( - ExprName { - range: 999..1002, - id: "str", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 1004..1006, - name: Identifier { - id: "U", - range: 1005..1006, - }, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 1008..1011, - name: Identifier { - id: "P", - range: 1010..1011, - }, - default: None, - }, - ), - ], - }, - ), - arguments: Some( - Arguments { - range: 1012..1014, - args: [], - keywords: [], - }, - ), - body: [ - Pass( - StmtPass { - range: 1018..1022, - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap.new deleted file mode 100644 index 93580cb04f..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap.new +++ /dev/null @@ -1,300 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/delete.py ---- -## AST - -``` -Module( - ModModule { - range: 0..122, - body: [ - Delete( - StmtDelete { - range: 0..5, - targets: [ - Name( - ExprName { - range: 4..5, - id: "x", - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 6..13, - targets: [ - Name( - ExprName { - range: 11..12, - id: "x", - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 14..23, - targets: [ - Name( - ExprName { - range: 18..19, - id: "a", - ctx: Del, - }, - ), - Name( - ExprName { - range: 21..22, - id: "b", - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 24..40, - targets: [ - Name( - ExprName { - range: 28..29, - id: "a", - ctx: Del, - }, - ), - Tuple( - ExprTuple { - range: 31..37, - elts: [ - Name( - ExprName { - range: 32..33, - id: "b", - ctx: Del, - }, - ), - Name( - ExprName { - range: 35..36, - id: "c", - ctx: Del, - }, - ), - ], - ctx: Del, - parenthesized: true, - }, - ), - Name( - ExprName { - range: 39..40, - id: "d", - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 41..51, - targets: [ - List( - ExprList { - range: 45..51, - elts: [ - Name( - ExprName { - range: 46..47, - id: "a", - ctx: Del, - }, - ), - Name( - ExprName { - range: 49..50, - id: "b", - ctx: Del, - }, - ), - ], - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 52..70, - targets: [ - List( - ExprList { - range: 56..70, - elts: [ - Name( - ExprName { - range: 57..58, - id: "a", - ctx: Del, - }, - ), - List( - ExprList { - range: 60..66, - elts: [ - Name( - ExprName { - range: 61..62, - id: "b", - ctx: Del, - }, - ), - Name( - ExprName { - range: 64..65, - id: "c", - ctx: Del, - }, - ), - ], - ctx: Del, - }, - ), - Name( - ExprName { - range: 68..69, - id: "d", - ctx: Del, - }, - ), - ], - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 71..78, - targets: [ - Attribute( - ExprAttribute { - range: 75..78, - value: Name( - ExprName { - range: 75..76, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "y", - range: 77..78, - }, - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 79..87, - targets: [ - Subscript( - ExprSubscript { - range: 83..87, - value: Name( - ExprName { - range: 83..84, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 85..86, - id: "y", - ctx: Load, - }, - ), - ctx: Del, - }, - ), - ], - }, - ), - Delete( - StmtDelete { - range: 88..121, - targets: [ - Tuple( - ExprTuple { - range: 92..121, - elts: [ - Name( - ExprName { - range: 98..99, - id: "x", - ctx: Del, - }, - ), - Attribute( - ExprAttribute { - range: 105..108, - value: Name( - ExprName { - range: 105..106, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "y", - range: 107..108, - }, - ctx: Del, - }, - ), - Subscript( - ExprSubscript { - range: 114..118, - value: Name( - ExprName { - range: 114..115, - id: "x", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 116..117, - id: "y", - ctx: Load, - }, - ), - ctx: Del, - }, - ), - ], - ctx: Del, - parenthesized: true, - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap.new deleted file mode 100644 index 7a0acfce9d..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap.new +++ /dev/null @@ -1,834 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/for.py ---- -## AST - -``` -Module( - ModModule { - range: 0..660, - body: [ - For( - StmtFor { - range: 0..28, - is_async: false, - target: Name( - ExprName { - range: 4..10, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 14..18, - id: "iter", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 24..28, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 30..63, - is_async: false, - target: Name( - ExprName { - range: 34..40, - id: "target", - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 44..53, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 45..46, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 48..49, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 51..52, - value: Int( - 3, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 59..63, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 65..100, - is_async: false, - target: Attribute( - ExprAttribute { - range: 69..80, - value: Name( - ExprName { - range: 69..75, - id: "target", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 76..80, - }, - ctx: Store, - }, - ), - iter: Call( - ExprCall { - range: 84..90, - func: Name( - ExprName { - range: 84..88, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 88..90, - args: [], - keywords: [], - }, - }, - ), - body: [ - Pass( - StmtPass { - range: 96..100, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 102..135, - is_async: false, - target: Subscript( - ExprSubscript { - range: 106..115, - value: Name( - ExprName { - range: 106..112, - id: "target", - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - range: 113..114, - value: Int( - 0, - ), - }, - ), - ctx: Store, - }, - ), - iter: Attribute( - ExprAttribute { - range: 119..125, - value: Name( - ExprName { - range: 119..120, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 121..125, - }, - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 131..135, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 137..167, - is_async: false, - target: Name( - ExprName { - range: 141..147, - id: "target", - ctx: Store, - }, - ), - iter: Compare( - ExprCompare { - range: 151..157, - left: Name( - ExprName { - range: 151..152, - id: "x", - ctx: Load, - }, - ), - ops: [ - LtE, - ], - comparators: [ - Name( - ExprName { - range: 156..157, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Pass( - StmtPass { - range: 163..167, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 169..200, - is_async: false, - target: Name( - ExprName { - range: 173..179, - id: "target", - ctx: Store, - }, - ), - iter: BoolOp( - ExprBoolOp { - range: 183..190, - op: And, - values: [ - Name( - ExprName { - range: 183..184, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 189..190, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Pass( - StmtPass { - range: 196..200, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 202..232, - is_async: false, - target: Tuple( - ExprTuple { - range: 206..214, - elts: [ - Name( - ExprName { - range: 206..207, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 209..210, - id: "b", - ctx: Store, - }, - ), - Name( - ExprName { - range: 212..213, - id: "c", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: false, - }, - ), - iter: Name( - ExprName { - range: 218..222, - id: "iter", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 228..232, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 234..262, - is_async: false, - target: Tuple( - ExprTuple { - range: 238..244, - elts: [ - Name( - ExprName { - range: 239..240, - id: "a", - ctx: Store, - }, - ), - Name( - ExprName { - range: 242..243, - id: "b", - ctx: Store, - }, - ), - ], - ctx: Store, - parenthesized: true, - }, - ), - iter: Name( - ExprName { - range: 248..252, - id: "iter", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 258..262, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 264..295, - is_async: false, - target: Name( - ExprName { - range: 268..274, - id: "target", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 278..285, - value: Attribute( - ExprAttribute { - range: 279..285, - value: Name( - ExprName { - range: 279..280, - id: "x", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 281..285, - }, - ctx: Load, - }, - ), - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 291..295, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 297..327, - is_async: false, - target: Name( - ExprName { - range: 301..307, - id: "target", - ctx: Store, - }, - ), - iter: List( - ExprList { - range: 311..317, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 312..313, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 315..316, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 323..327, - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 329..377, - is_async: false, - target: Starred( - ExprStarred { - range: 333..340, - value: Name( - ExprName { - range: 334..340, - id: "target", - ctx: Store, - }, - ), - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - range: 344..352, - elts: [ - Name( - ExprName { - range: 344..345, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 347..348, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 350..351, - id: "c", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - body: [ - Pass( - StmtPass { - range: 358..362, - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 373..377, - }, - ), - ], - }, - ), - For( - StmtFor { - range: 379..404, - is_async: false, - target: Name( - ExprName { - range: 383..389, - id: "target", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 393..399, - value: BinOp( - ExprBinOp { - range: 394..399, - left: Name( - ExprName { - range: 394..395, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 398..399, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 401..404, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 401..404, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 405..432, - is_async: false, - target: Name( - ExprName { - range: 409..415, - id: "target", - ctx: Store, - }, - ), - iter: Starred( - ExprStarred { - range: 419..427, - value: Await( - ExprAwait { - range: 420..427, - value: Name( - ExprName { - range: 426..427, - id: "x", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 429..432, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 429..432, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 433..459, - is_async: false, - target: Name( - ExprName { - range: 437..443, - id: "target", - ctx: Store, - }, - ), - iter: Await( - ExprAwait { - range: 447..454, - value: Name( - ExprName { - range: 453..454, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 456..459, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 456..459, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 460..490, - is_async: false, - target: Name( - ExprName { - range: 464..470, - id: "target", - ctx: Store, - }, - ), - iter: Lambda( - ExprLambda { - range: 474..485, - parameters: Some( - Parameters { - range: 481..482, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 481..482, - parameter: Parameter { - range: 481..482, - name: Identifier { - id: "x", - range: 481..482, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 484..485, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 487..490, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 487..490, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - For( - StmtFor { - range: 491..526, - is_async: false, - target: Name( - ExprName { - range: 495..501, - id: "target", - ctx: Store, - }, - ), - iter: If( - ExprIf { - range: 505..521, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 510..514, - value: true, - }, - ), - body: Name( - ExprName { - range: 505..506, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 520..521, - id: "y", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 523..526, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 523..526, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - If( - StmtIf { - range: 528..659, - test: Name( - ExprName { - range: 531..532, - id: "x", - ctx: Load, - }, - ), - body: [ - For( - StmtFor { - range: 538..570, - is_async: false, - target: Name( - ExprName { - range: 542..548, - id: "target", - ctx: Store, - }, - ), - iter: Name( - ExprName { - range: 552..556, - id: "iter", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 566..570, - }, - ), - ], - orelse: [], - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 645..659, - test: None, - body: [ - Pass( - StmtPass { - range: 655..659, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap.new deleted file mode 100644 index 7952363409..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap.new +++ /dev/null @@ -1,238 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/from_import.py ---- -## AST - -``` -Module( - ModModule { - range: 0..259, - body: [ - ImportFrom( - StmtImportFrom { - range: 0..15, - module: Some( - Identifier { - id: "a", - range: 5..6, - }, - ), - names: [ - Alias { - range: 14..15, - name: Identifier { - id: "b", - range: 14..15, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 27..42, - module: None, - names: [ - Alias { - range: 41..42, - name: Identifier { - id: "a", - range: 41..42, - }, - asname: None, - }, - ], - level: 1, - }, - ), - ImportFrom( - StmtImportFrom { - range: 43..85, - module: Some( - Identifier { - id: "foo.bar", - range: 48..55, - }, - ), - names: [ - Alias { - range: 63..71, - name: Identifier { - id: "baz", - range: 63..66, - }, - asname: Some( - Identifier { - id: "b", - range: 70..71, - }, - ), - }, - Alias { - range: 73..85, - name: Identifier { - id: "FooBar", - range: 73..79, - }, - asname: Some( - Identifier { - id: "fb", - range: 83..85, - }, - ), - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 86..102, - module: Some( - Identifier { - id: "a", - range: 92..93, - }, - ), - names: [ - Alias { - range: 101..102, - name: Identifier { - id: "b", - range: 101..102, - }, - asname: None, - }, - ], - level: 1, - }, - ), - ImportFrom( - StmtImportFrom { - range: 103..120, - module: None, - names: [ - Alias { - range: 119..120, - name: Identifier { - id: "c", - range: 119..120, - }, - asname: None, - }, - ], - level: 3, - }, - ), - ImportFrom( - StmtImportFrom { - range: 121..161, - module: None, - names: [ - Alias { - range: 160..161, - name: Identifier { - id: "d", - range: 160..161, - }, - asname: None, - }, - ], - level: 26, - }, - ), - ImportFrom( - StmtImportFrom { - range: 162..207, - module: Some( - Identifier { - id: "a.b.c", - range: 193..198, - }, - ), - names: [ - Alias { - range: 206..207, - name: Identifier { - id: "d", - range: 206..207, - }, - asname: None, - }, - ], - level: 26, - }, - ), - ImportFrom( - StmtImportFrom { - range: 208..242, - module: Some( - Identifier { - id: "module", - range: 213..219, - }, - ), - names: [ - Alias { - range: 228..229, - name: Identifier { - id: "a", - range: 228..229, - }, - asname: None, - }, - Alias { - range: 231..237, - name: Identifier { - id: "b", - range: 231..232, - }, - asname: Some( - Identifier { - id: "B", - range: 236..237, - }, - ), - }, - Alias { - range: 239..240, - name: Identifier { - id: "c", - range: 239..240, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ImportFrom( - StmtImportFrom { - range: 243..258, - module: Some( - Identifier { - id: "a", - range: 248..249, - }, - ), - names: [ - Alias { - range: 257..258, - name: Identifier { - id: "*", - range: 257..258, - }, - asname: None, - }, - ], - level: 0, - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap.new deleted file mode 100644 index c4864e78bf..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap.new +++ /dev/null @@ -1,3242 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/function.py ---- -## AST - -``` -Module( - ModModule { - range: 0..2399, - body: [ - FunctionDef( - StmtFunctionDef { - range: 0..29, - is_async: false, - decorator_list: [], - name: Identifier { - id: "no_parameters", - range: 4..17, - }, - type_params: None, - parameters: Parameters { - range: 17..19, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 25..29, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 32..76, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_parameters", - range: 36..57, - }, - type_params: None, - parameters: Parameters { - range: 57..66, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 58..59, - parameter: Parameter { - range: 58..59, - name: Identifier { - id: "a", - range: 58..59, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 61..62, - parameter: Parameter { - range: 61..62, - name: Identifier { - id: "b", - range: 61..62, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 64..65, - parameter: Parameter { - range: 64..65, - name: Identifier { - id: "c", - range: 64..65, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 72..76, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 79..149, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_parameters_with_default_values", - range: 83..124, - }, - type_params: None, - parameters: Parameters { - range: 124..139, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 125..126, - parameter: Parameter { - range: 125..126, - name: Identifier { - id: "a", - range: 125..126, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 128..132, - parameter: Parameter { - range: 128..129, - name: Identifier { - id: "b", - range: 128..129, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 130..132, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 134..138, - parameter: Parameter { - range: 134..135, - name: Identifier { - id: "c", - range: 134..135, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 136..138, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 145..149, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 152..226, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_parameters_with_default_values2", - range: 156..198, - }, - type_params: None, - parameters: Parameters { - range: 198..216, - posonlyargs: [ - ParameterWithDefault { - range: 199..200, - parameter: Parameter { - range: 199..200, - name: Identifier { - id: "a", - range: 199..200, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 202..206, - parameter: Parameter { - range: 202..203, - name: Identifier { - id: "b", - range: 202..203, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 204..206, - value: Int( - 20, - ), - }, - ), - ), - }, - ], - args: [ - ParameterWithDefault { - range: 211..215, - parameter: Parameter { - range: 211..212, - name: Identifier { - id: "c", - range: 211..212, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 213..215, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 222..226, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 229..296, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_only_and_positional_parameters", - range: 233..274, - }, - type_params: None, - parameters: Parameters { - range: 274..286, - posonlyargs: [ - ParameterWithDefault { - range: 275..276, - parameter: Parameter { - range: 275..276, - name: Identifier { - id: "a", - range: 275..276, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 281..282, - parameter: Parameter { - range: 281..282, - name: Identifier { - id: "b", - range: 281..282, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 284..285, - parameter: Parameter { - range: 284..285, - name: Identifier { - id: "c", - range: 284..285, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 292..296, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 299..393, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_args_with_defaults_and_varargs_and_kwargs", - range: 303..348, - }, - type_params: None, - parameters: Parameters { - range: 348..383, - posonlyargs: [ - ParameterWithDefault { - range: 349..350, - parameter: Parameter { - range: 349..350, - name: Identifier { - id: "a", - range: 349..350, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 352..356, - parameter: Parameter { - range: 352..353, - name: Identifier { - id: "b", - range: 352..353, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 354..356, - value: Int( - 20, - ), - }, - ), - ), - }, - ], - args: [ - ParameterWithDefault { - range: 361..365, - parameter: Parameter { - range: 361..362, - name: Identifier { - id: "c", - range: 361..362, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 363..365, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - vararg: Some( - Parameter { - range: 367..372, - name: Identifier { - id: "args", - range: 368..372, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 374..382, - name: Identifier { - id: "kwargs", - range: 376..382, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 389..393, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 396..445, - is_async: false, - decorator_list: [], - name: Identifier { - id: "keyword_only_parameters", - range: 400..423, - }, - type_params: None, - parameters: Parameters { - range: 423..435, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 427..428, - parameter: Parameter { - range: 427..428, - name: Identifier { - id: "a", - range: 427..428, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 430..431, - parameter: Parameter { - range: 430..431, - name: Identifier { - id: "b", - range: 430..431, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 433..434, - parameter: Parameter { - range: 433..434, - name: Identifier { - id: "c", - range: 433..434, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 441..445, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 448..517, - is_async: false, - decorator_list: [], - name: Identifier { - id: "keyword_only_parameters_with_defaults", - range: 452..489, - }, - type_params: None, - parameters: Parameters { - range: 489..507, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 493..494, - parameter: Parameter { - range: 493..494, - name: Identifier { - id: "a", - range: 493..494, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 496..500, - parameter: Parameter { - range: 496..497, - name: Identifier { - id: "b", - range: 496..497, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 498..500, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 502..506, - parameter: Parameter { - range: 502..503, - name: Identifier { - id: "c", - range: 502..503, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 504..506, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 513..517, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 520..594, - is_async: false, - decorator_list: [], - name: Identifier { - id: "kw_only_args_with_defaults_and_varargs", - range: 524..562, - }, - type_params: None, - parameters: Parameters { - range: 562..584, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 563..568, - name: Identifier { - id: "args", - range: 564..568, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 570..571, - parameter: Parameter { - range: 570..571, - name: Identifier { - id: "a", - range: 570..571, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 573..577, - parameter: Parameter { - range: 573..574, - name: Identifier { - id: "b", - range: 573..574, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 575..577, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 579..583, - parameter: Parameter { - range: 579..580, - name: Identifier { - id: "c", - range: 579..580, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 581..583, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 590..594, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 597..676, - is_async: false, - decorator_list: [], - name: Identifier { - id: "kw_only_args_with_defaults_and_kwargs", - range: 601..638, - }, - type_params: None, - parameters: Parameters { - range: 638..666, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 642..643, - parameter: Parameter { - range: 642..643, - name: Identifier { - id: "a", - range: 642..643, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 645..649, - parameter: Parameter { - range: 645..646, - name: Identifier { - id: "b", - range: 645..646, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 647..649, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 651..655, - parameter: Parameter { - range: 651..652, - name: Identifier { - id: "c", - range: 651..652, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 653..655, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 657..665, - name: Identifier { - id: "kwargs", - range: 659..665, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 672..676, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 679..774, - is_async: false, - decorator_list: [], - name: Identifier { - id: "kw_only_args_with_defaults_and_varargs_and_kwargs", - range: 683..732, - }, - type_params: None, - parameters: Parameters { - range: 732..764, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 733..738, - name: Identifier { - id: "args", - range: 734..738, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 740..741, - parameter: Parameter { - range: 740..741, - name: Identifier { - id: "a", - range: 740..741, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 743..747, - parameter: Parameter { - range: 743..744, - name: Identifier { - id: "b", - range: 743..744, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 745..747, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 749..753, - parameter: Parameter { - range: 749..750, - name: Identifier { - id: "c", - range: 749..750, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 751..753, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 755..763, - name: Identifier { - id: "kwargs", - range: 757..763, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 770..774, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 777..835, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_and_kw_only_args", - range: 781..801, - }, - type_params: None, - parameters: Parameters { - range: 801..825, - posonlyargs: [ - ParameterWithDefault { - range: 802..803, - parameter: Parameter { - range: 802..803, - name: Identifier { - id: "a", - range: 802..803, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 805..806, - parameter: Parameter { - range: 805..806, - name: Identifier { - id: "b", - range: 805..806, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 811..812, - parameter: Parameter { - range: 811..812, - name: Identifier { - id: "c", - range: 811..812, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 817..818, - parameter: Parameter { - range: 817..818, - name: Identifier { - id: "d", - range: 817..818, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 820..821, - parameter: Parameter { - range: 820..821, - name: Identifier { - id: "e", - range: 820..821, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 823..824, - parameter: Parameter { - range: 823..824, - name: Identifier { - id: "f", - range: 823..824, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 831..835, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 838..916, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_and_kw_only_args_with_defaults", - range: 842..876, - }, - type_params: None, - parameters: Parameters { - range: 876..906, - posonlyargs: [ - ParameterWithDefault { - range: 877..878, - parameter: Parameter { - range: 877..878, - name: Identifier { - id: "a", - range: 877..878, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 880..881, - parameter: Parameter { - range: 880..881, - name: Identifier { - id: "b", - range: 880..881, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 886..887, - parameter: Parameter { - range: 886..887, - name: Identifier { - id: "c", - range: 886..887, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 892..893, - parameter: Parameter { - range: 892..893, - name: Identifier { - id: "d", - range: 892..893, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 895..899, - parameter: Parameter { - range: 895..896, - name: Identifier { - id: "e", - range: 895..896, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 897..899, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 901..905, - parameter: Parameter { - range: 901..902, - name: Identifier { - id: "f", - range: 901..902, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 903..905, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 912..916, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 919..1013, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_and_kw_only_args_with_defaults_and_varargs", - range: 923..969, - }, - type_params: None, - parameters: Parameters { - range: 969..1003, - posonlyargs: [ - ParameterWithDefault { - range: 970..971, - parameter: Parameter { - range: 970..971, - name: Identifier { - id: "a", - range: 970..971, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 973..974, - parameter: Parameter { - range: 973..974, - name: Identifier { - id: "b", - range: 973..974, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 979..980, - parameter: Parameter { - range: 979..980, - name: Identifier { - id: "c", - range: 979..980, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 982..987, - name: Identifier { - id: "args", - range: 983..987, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 989..990, - parameter: Parameter { - range: 989..990, - name: Identifier { - id: "d", - range: 989..990, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 992..996, - parameter: Parameter { - range: 992..993, - name: Identifier { - id: "e", - range: 992..993, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 994..996, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 998..1002, - parameter: Parameter { - range: 998..999, - name: Identifier { - id: "f", - range: 998..999, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1000..1002, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1009..1013, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1016..1121, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_and_kw_only_args_with_defaults_and_kwargs", - range: 1020..1065, - }, - type_params: None, - parameters: Parameters { - range: 1065..1111, - posonlyargs: [ - ParameterWithDefault { - range: 1071..1072, - parameter: Parameter { - range: 1071..1072, - name: Identifier { - id: "a", - range: 1071..1072, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1074..1075, - parameter: Parameter { - range: 1074..1075, - name: Identifier { - id: "b", - range: 1074..1075, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 1080..1081, - parameter: Parameter { - range: 1080..1081, - name: Identifier { - id: "c", - range: 1080..1081, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 1086..1087, - parameter: Parameter { - range: 1086..1087, - name: Identifier { - id: "d", - range: 1086..1087, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1089..1093, - parameter: Parameter { - range: 1089..1090, - name: Identifier { - id: "e", - range: 1089..1090, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1091..1093, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 1095..1099, - parameter: Parameter { - range: 1095..1096, - name: Identifier { - id: "f", - range: 1095..1096, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1097..1099, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 1101..1109, - name: Identifier { - id: "kwargs", - range: 1103..1109, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1117..1121, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1124..1245, - is_async: false, - decorator_list: [], - name: Identifier { - id: "pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs", - range: 1128..1185, - }, - type_params: None, - parameters: Parameters { - range: 1185..1235, - posonlyargs: [ - ParameterWithDefault { - range: 1191..1192, - parameter: Parameter { - range: 1191..1192, - name: Identifier { - id: "a", - range: 1191..1192, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1194..1195, - parameter: Parameter { - range: 1194..1195, - name: Identifier { - id: "b", - range: 1194..1195, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 1200..1201, - parameter: Parameter { - range: 1200..1201, - name: Identifier { - id: "c", - range: 1200..1201, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 1203..1208, - name: Identifier { - id: "args", - range: 1204..1208, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 1210..1211, - parameter: Parameter { - range: 1210..1211, - name: Identifier { - id: "d", - range: 1210..1211, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1213..1217, - parameter: Parameter { - range: 1213..1214, - name: Identifier { - id: "e", - range: 1213..1214, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1215..1217, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 1219..1223, - parameter: Parameter { - range: 1219..1220, - name: Identifier { - id: "f", - range: 1219..1220, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1221..1223, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 1225..1233, - name: Identifier { - id: "kwargs", - range: 1227..1233, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1241..1245, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1248..1316, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_and_keyword_parameters", - range: 1252..1285, - }, - type_params: None, - parameters: Parameters { - range: 1285..1306, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1286..1287, - parameter: Parameter { - range: 1286..1287, - name: Identifier { - id: "a", - range: 1286..1287, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1289..1290, - parameter: Parameter { - range: 1289..1290, - name: Identifier { - id: "b", - range: 1289..1290, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1292..1293, - parameter: Parameter { - range: 1292..1293, - name: Identifier { - id: "c", - range: 1292..1293, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 1298..1299, - parameter: Parameter { - range: 1298..1299, - name: Identifier { - id: "d", - range: 1298..1299, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1301..1302, - parameter: Parameter { - range: 1301..1302, - name: Identifier { - id: "e", - range: 1301..1302, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1304..1305, - parameter: Parameter { - range: 1304..1305, - name: Identifier { - id: "f", - range: 1304..1305, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1312..1316, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1319..1407, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_and_keyword_parameters_with_defaults", - range: 1323..1370, - }, - type_params: None, - parameters: Parameters { - range: 1370..1397, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1371..1372, - parameter: Parameter { - range: 1371..1372, - name: Identifier { - id: "a", - range: 1371..1372, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1374..1375, - parameter: Parameter { - range: 1374..1375, - name: Identifier { - id: "b", - range: 1374..1375, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1377..1378, - parameter: Parameter { - range: 1377..1378, - name: Identifier { - id: "c", - range: 1377..1378, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 1383..1384, - parameter: Parameter { - range: 1383..1384, - name: Identifier { - id: "d", - range: 1383..1384, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1386..1390, - parameter: Parameter { - range: 1386..1387, - name: Identifier { - id: "e", - range: 1386..1387, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1388..1390, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 1392..1396, - parameter: Parameter { - range: 1392..1393, - name: Identifier { - id: "f", - range: 1392..1393, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1394..1396, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1403..1407, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1410..1520, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_and_keyword_parameters_with_defaults_and_varargs", - range: 1414..1473, - }, - type_params: None, - parameters: Parameters { - range: 1473..1510, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1479..1480, - parameter: Parameter { - range: 1479..1480, - name: Identifier { - id: "a", - range: 1479..1480, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1482..1483, - parameter: Parameter { - range: 1482..1483, - name: Identifier { - id: "b", - range: 1482..1483, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1485..1486, - parameter: Parameter { - range: 1485..1486, - name: Identifier { - id: "c", - range: 1485..1486, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 1488..1493, - name: Identifier { - id: "args", - range: 1489..1493, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 1495..1496, - parameter: Parameter { - range: 1495..1496, - name: Identifier { - id: "d", - range: 1495..1496, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1498..1502, - parameter: Parameter { - range: 1498..1499, - name: Identifier { - id: "e", - range: 1498..1499, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1500..1502, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 1504..1508, - parameter: Parameter { - range: 1504..1505, - name: Identifier { - id: "f", - range: 1504..1505, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1506..1508, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1516..1520, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1523..1654, - is_async: false, - decorator_list: [], - name: Identifier { - id: "positional_and_keyword_parameters_with_defaults_and_varargs_and_kwargs", - range: 1527..1597, - }, - type_params: None, - parameters: Parameters { - range: 1597..1644, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1603..1604, - parameter: Parameter { - range: 1603..1604, - name: Identifier { - id: "a", - range: 1603..1604, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1606..1607, - parameter: Parameter { - range: 1606..1607, - name: Identifier { - id: "b", - range: 1606..1607, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1609..1610, - parameter: Parameter { - range: 1609..1610, - name: Identifier { - id: "c", - range: 1609..1610, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: Some( - Parameter { - range: 1612..1617, - name: Identifier { - id: "args", - range: 1613..1617, - }, - annotation: None, - }, - ), - kwonlyargs: [ - ParameterWithDefault { - range: 1619..1620, - parameter: Parameter { - range: 1619..1620, - name: Identifier { - id: "d", - range: 1619..1620, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 1622..1626, - parameter: Parameter { - range: 1622..1623, - name: Identifier { - id: "e", - range: 1622..1623, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1624..1626, - value: Int( - 20, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 1628..1632, - parameter: Parameter { - range: 1628..1629, - name: Identifier { - id: "f", - range: 1628..1629, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1630..1632, - value: Int( - 30, - ), - }, - ), - ), - }, - ], - kwarg: Some( - Parameter { - range: 1634..1642, - name: Identifier { - id: "kwargs", - range: 1636..1642, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1650..1654, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1703..1735, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1707..1711, - }, - type_params: Some( - TypeParams { - range: 1711..1714, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1712..1713, - name: Identifier { - id: "T", - range: 1712..1713, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1714..1720, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1715..1719, - parameter: Parameter { - range: 1715..1719, - name: Identifier { - id: "a", - range: 1715..1716, - }, - annotation: Some( - Name( - ExprName { - range: 1718..1719, - id: "T", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 1724..1725, - id: "T", - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 1731..1735, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1738..1775, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1742..1746, - }, - type_params: Some( - TypeParams { - range: 1746..1754, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1747..1753, - name: Identifier { - id: "T", - range: 1747..1748, - }, - bound: Some( - Name( - ExprName { - range: 1750..1753, - id: "str", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1754..1760, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1755..1759, - parameter: Parameter { - range: 1755..1759, - name: Identifier { - id: "a", - range: 1755..1756, - }, - annotation: Some( - Name( - ExprName { - range: 1758..1759, - id: "T", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 1764..1765, - id: "T", - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 1771..1775, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1778..1824, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1782..1786, - }, - type_params: Some( - TypeParams { - range: 1786..1803, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1787..1802, - name: Identifier { - id: "T", - range: 1787..1788, - }, - bound: Some( - Tuple( - ExprTuple { - range: 1790..1802, - elts: [ - Name( - ExprName { - range: 1791..1794, - id: "str", - ctx: Load, - }, - ), - Name( - ExprName { - range: 1796..1801, - id: "bytes", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1803..1809, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1804..1808, - parameter: Parameter { - range: 1804..1808, - name: Identifier { - id: "a", - range: 1804..1805, - }, - annotation: Some( - Name( - ExprName { - range: 1807..1808, - id: "T", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 1813..1814, - id: "T", - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 1820..1824, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1827..1873, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1831..1835, - }, - type_params: Some( - TypeParams { - range: 1835..1840, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 1836..1839, - name: Identifier { - id: "Ts", - range: 1837..1839, - }, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1840..1849, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 1841..1848, - name: Identifier { - id: "a", - range: 1842..1843, - }, - annotation: Some( - Starred( - ExprStarred { - range: 1845..1848, - value: Name( - ExprName { - range: 1846..1848, - id: "Ts", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Subscript( - ExprSubscript { - range: 1853..1863, - value: Name( - ExprName { - range: 1853..1858, - id: "Tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 1859..1862, - elts: [ - Starred( - ExprStarred { - range: 1859..1862, - value: Name( - ExprName { - range: 1860..1862, - id: "Ts", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - ), - body: [ - Pass( - StmtPass { - range: 1869..1873, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1876..1934, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1880..1884, - }, - type_params: Some( - TypeParams { - range: 1884..1889, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 1885..1888, - name: Identifier { - id: "P", - range: 1887..1888, - }, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1889..1924, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 1890..1903, - name: Identifier { - id: "args", - range: 1891..1895, - }, - annotation: Some( - Attribute( - ExprAttribute { - range: 1897..1903, - value: Name( - ExprName { - range: 1897..1898, - id: "P", - ctx: Load, - }, - ), - attr: Identifier { - id: "args", - range: 1899..1903, - }, - ctx: Load, - }, - ), - ), - }, - ), - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 1905..1923, - name: Identifier { - id: "kwargs", - range: 1907..1913, - }, - annotation: Some( - Attribute( - ExprAttribute { - range: 1915..1923, - value: Name( - ExprName { - range: 1915..1916, - id: "P", - ctx: Load, - }, - ), - attr: Identifier { - id: "kwargs", - range: 1917..1923, - }, - ctx: Load, - }, - ), - ), - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1930..1934, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1937..1978, - is_async: false, - decorator_list: [], - name: Identifier { - id: "func", - range: 1941..1945, - }, - type_params: Some( - TypeParams { - range: 1945..1966, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1946..1947, - name: Identifier { - id: "T", - range: 1946..1947, - }, - bound: None, - default: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 1949..1955, - name: Identifier { - id: "U", - range: 1949..1950, - }, - bound: Some( - Name( - ExprName { - range: 1952..1955, - id: "str", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 1957..1960, - name: Identifier { - id: "Ts", - range: 1958..1960, - }, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 1962..1965, - name: Identifier { - id: "P", - range: 1964..1965, - }, - default: None, - }, - ), - ], - }, - ), - parameters: Parameters { - range: 1966..1968, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 1974..1978, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 1981..2000, - is_async: false, - decorator_list: [], - name: Identifier { - id: "ellipsis", - range: 1985..1993, - }, - type_params: None, - parameters: Parameters { - range: 1993..1995, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Expr( - StmtExpr { - range: 1997..2000, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 1997..2000, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2003..2064, - is_async: false, - decorator_list: [], - name: Identifier { - id: "multiple_statements", - range: 2007..2026, - }, - type_params: None, - parameters: Parameters { - range: 2026..2028, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: Some( - Name( - ExprName { - range: 2032..2035, - id: "int", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 2041..2047, - value: Call( - ExprCall { - range: 2041..2047, - func: Name( - ExprName { - range: 2041..2045, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 2045..2047, - args: [], - keywords: [], - }, - }, - ), - }, - ), - Pass( - StmtPass { - range: 2052..2056, - }, - ), - Expr( - StmtExpr { - range: 2061..2064, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 2061..2064, - }, - ), - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2067..2091, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2071..2074, - }, - type_params: None, - parameters: Parameters { - range: 2074..2081, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 2075..2080, - name: Identifier { - id: "args", - range: 2076..2080, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2087..2091, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2094..2121, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2098..2101, - }, - type_params: None, - parameters: Parameters { - range: 2101..2111, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 2102..2110, - name: Identifier { - id: "kwargs", - range: 2104..2110, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2117..2121, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2124..2158, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2128..2131, - }, - type_params: None, - parameters: Parameters { - range: 2131..2148, - posonlyargs: [], - args: [], - vararg: Some( - Parameter { - range: 2132..2137, - name: Identifier { - id: "args", - range: 2133..2137, - }, - annotation: None, - }, - ), - kwonlyargs: [], - kwarg: Some( - Parameter { - range: 2139..2147, - name: Identifier { - id: "kwargs", - range: 2141..2147, - }, - annotation: None, - }, - ), - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2154..2158, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2161..2184, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2165..2168, - }, - type_params: None, - parameters: Parameters { - range: 2168..2174, - posonlyargs: [ - ParameterWithDefault { - range: 2169..2170, - parameter: Parameter { - range: 2169..2170, - name: Identifier { - id: "a", - range: 2169..2170, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2180..2184, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2187..2213, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2191..2194, - }, - type_params: None, - parameters: Parameters { - range: 2194..2203, - posonlyargs: [ - ParameterWithDefault { - range: 2195..2196, - parameter: Parameter { - range: 2195..2196, - name: Identifier { - id: "a", - range: 2195..2196, - }, - annotation: None, - }, - default: None, - }, - ], - args: [ - ParameterWithDefault { - range: 2201..2202, - parameter: Parameter { - range: 2201..2202, - name: Identifier { - id: "b", - range: 2201..2202, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2209..2213, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2216..2242, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2220..2223, - }, - type_params: None, - parameters: Parameters { - range: 2223..2232, - posonlyargs: [ - ParameterWithDefault { - range: 2224..2227, - parameter: Parameter { - range: 2224..2225, - name: Identifier { - id: "a", - range: 2224..2225, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2226..2227, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2238..2242, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2245..2277, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2249..2252, - }, - type_params: None, - parameters: Parameters { - range: 2252..2267, - posonlyargs: [ - ParameterWithDefault { - range: 2253..2254, - parameter: Parameter { - range: 2253..2254, - name: Identifier { - id: "a", - range: 2253..2254, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 2256..2257, - parameter: Parameter { - range: 2256..2257, - name: Identifier { - id: "b", - range: 2256..2257, - }, - annotation: None, - }, - default: None, - }, - ], - args: [], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 2265..2266, - parameter: Parameter { - range: 2265..2266, - name: Identifier { - id: "c", - range: 2265..2266, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2273..2277, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2280..2309, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2284..2287, - }, - type_params: None, - parameters: Parameters { - range: 2287..2299, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 2288..2292, - parameter: Parameter { - range: 2288..2290, - name: Identifier { - id: "kw", - range: 2288..2290, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2291..2292, - value: Int( - 1, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [ - ParameterWithDefault { - range: 2297..2298, - parameter: Parameter { - range: 2297..2298, - name: Identifier { - id: "a", - range: 2297..2298, - }, - annotation: None, - }, - default: None, - }, - ], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2305..2309, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2312..2357, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2316..2319, - }, - type_params: None, - parameters: Parameters { - range: 2319..2347, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 2320..2326, - parameter: Parameter { - range: 2320..2326, - name: Identifier { - id: "x", - range: 2320..2321, - }, - annotation: Some( - Name( - ExprName { - range: 2323..2326, - id: "int", - ctx: Load, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 2328..2336, - parameter: Parameter { - range: 2328..2336, - name: Identifier { - id: "y", - range: 2328..2329, - }, - annotation: Some( - StringLiteral( - ExprStringLiteral { - range: 2331..2336, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2331..2336, - value: "str", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - }, - default: None, - }, - ParameterWithDefault { - range: 2338..2346, - parameter: Parameter { - range: 2338..2346, - name: Identifier { - id: "z", - range: 2338..2339, - }, - annotation: Some( - BinOp( - ExprBinOp { - range: 2341..2346, - left: NumberLiteral( - ExprNumberLiteral { - range: 2341..2342, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 2345..2346, - value: Int( - 2, - ), - }, - ), - }, - ), - ), - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2353..2357, - }, - ), - ], - }, - ), - FunctionDef( - StmtFunctionDef { - range: 2360..2398, - is_async: false, - decorator_list: [], - name: Identifier { - id: "foo", - range: 2364..2367, - }, - type_params: None, - parameters: Parameters { - range: 2367..2388, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 2368..2372, - parameter: Parameter { - range: 2368..2372, - name: Identifier { - id: "self", - range: 2368..2372, - }, - annotation: None, - }, - default: None, - }, - ParameterWithDefault { - range: 2374..2377, - parameter: Parameter { - range: 2374..2375, - name: Identifier { - id: "a", - range: 2374..2375, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2376..2377, - value: Int( - 1, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 2379..2382, - parameter: Parameter { - range: 2379..2380, - name: Identifier { - id: "b", - range: 2379..2380, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2381..2382, - value: Int( - 2, - ), - }, - ), - ), - }, - ParameterWithDefault { - range: 2384..2387, - parameter: Parameter { - range: 2384..2385, - name: Identifier { - id: "c", - range: 2384..2385, - }, - annotation: None, - }, - default: Some( - NumberLiteral( - ExprNumberLiteral { - range: 2386..2387, - value: Int( - 3, - ), - }, - ), - ), - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - returns: None, - body: [ - Pass( - StmtPass { - range: 2394..2398, - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap.new deleted file mode 100644 index 61665feb7b..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap.new +++ /dev/null @@ -1,674 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/if.py ---- -## AST - -``` -Module( - ModModule { - range: 0..375, - body: [ - If( - StmtIf { - range: 0..28, - test: NumberLiteral( - ExprNumberLiteral { - range: 3..4, - value: Int( - 1, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 6..8, - value: NumberLiteral( - ExprNumberLiteral { - range: 6..8, - value: Int( - 10, - ), - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 9..19, - test: Some( - NumberLiteral( - ExprNumberLiteral { - range: 14..15, - value: Int( - 2, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 17..19, - value: NumberLiteral( - ExprNumberLiteral { - range: 17..19, - value: Int( - 20, - ), - }, - ), - }, - ), - ], - }, - ElifElseClause { - range: 20..28, - test: None, - body: [ - Expr( - StmtExpr { - range: 26..28, - value: NumberLiteral( - ExprNumberLiteral { - range: 26..28, - value: Int( - 30, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 30..52, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 33..37, - value: true, - }, - ), - body: [ - Expr( - StmtExpr { - range: 43..44, - value: NumberLiteral( - ExprNumberLiteral { - range: 43..44, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 49..52, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 49..52, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 53..85, - test: Compare( - ExprCompare { - range: 56..61, - left: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 60..61, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 67..70, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 67..70, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 71..85, - test: None, - body: [ - Pass( - StmtPass { - range: 81..85, - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 87..117, - test: Name( - ExprName { - range: 90..91, - id: "a", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 97..101, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 102..117, - test: Some( - Name( - ExprName { - range: 107..108, - id: "b", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 114..117, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 114..117, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 119..203, - test: BoolOp( - ExprBoolOp { - range: 122..129, - op: And, - values: [ - Name( - ExprName { - range: 122..123, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 128..129, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 135..138, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 135..138, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 139..157, - test: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 144..148, - value: true, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 154..157, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 154..157, - }, - ), - }, - ), - ], - }, - ElifElseClause { - range: 158..173, - test: Some( - Name( - ExprName { - range: 163..164, - id: "c", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 170..173, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 170..173, - }, - ), - }, - ), - ], - }, - ElifElseClause { - range: 174..189, - test: Some( - Name( - ExprName { - range: 179..180, - id: "d", - ctx: Load, - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 186..189, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 186..189, - }, - ), - }, - ), - ], - }, - ElifElseClause { - range: 190..203, - test: None, - body: [ - Expr( - StmtExpr { - range: 200..203, - value: Call( - ExprCall { - range: 200..203, - func: Name( - ExprName { - range: 200..201, - id: "f", - ctx: Load, - }, - ), - arguments: Arguments { - range: 201..203, - args: [], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 229..260, - test: Named( - ExprNamed { - range: 232..238, - target: Name( - ExprName { - range: 232..233, - id: "a", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 237..238, - id: "b", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 240..243, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 240..243, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 244..260, - test: Some( - Named( - ExprNamed { - range: 249..255, - target: Name( - ExprName { - range: 249..250, - id: "a", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 254..255, - id: "b", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 257..260, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 257..260, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 261..302, - test: Lambda( - ExprLambda { - range: 264..275, - parameters: Some( - Parameters { - range: 271..272, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 271..272, - parameter: Parameter { - range: 271..272, - name: Identifier { - id: "x", - range: 271..272, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 274..275, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 277..280, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 277..280, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 281..302, - test: Some( - Lambda( - ExprLambda { - range: 286..297, - parameters: Some( - Parameters { - range: 293..294, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 293..294, - parameter: Parameter { - range: 293..294, - name: Identifier { - id: "x", - range: 293..294, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 296..297, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 299..302, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 299..302, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 303..336, - test: Await( - ExprAwait { - range: 306..313, - value: Name( - ExprName { - range: 312..313, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 315..318, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 315..318, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 319..336, - test: Some( - Await( - ExprAwait { - range: 324..331, - value: Name( - ExprName { - range: 330..331, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 333..336, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 333..336, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 337..374, - test: Yield( - ExprYield { - range: 341..348, - value: Some( - Name( - ExprName { - range: 347..348, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 351..354, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 351..354, - }, - ), - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 355..374, - test: Some( - Yield( - ExprYield { - range: 361..368, - value: Some( - Name( - ExprName { - range: 367..368, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 371..374, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 371..374, - }, - ), - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap.new deleted file mode 100644 index e1d3248def..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap.new +++ /dev/null @@ -1,130 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/import.py ---- -## AST - -``` -Module( - ModModule { - range: 0..92, - body: [ - Import( - StmtImport { - range: 0..8, - names: [ - Alias { - range: 7..8, - name: Identifier { - id: "a", - range: 7..8, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 9..21, - names: [ - Alias { - range: 16..21, - name: Identifier { - id: "a.b.c", - range: 16..21, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 22..39, - names: [ - Alias { - range: 29..39, - name: Identifier { - id: "a.b.c", - range: 29..34, - }, - asname: Some( - Identifier { - id: "d", - range: 38..39, - }, - ), - }, - ], - }, - ), - Import( - StmtImport { - range: 40..54, - names: [ - Alias { - range: 47..48, - name: Identifier { - id: "a", - range: 47..48, - }, - asname: None, - }, - Alias { - range: 50..51, - name: Identifier { - id: "b", - range: 50..51, - }, - asname: None, - }, - Alias { - range: 53..54, - name: Identifier { - id: "c", - range: 53..54, - }, - asname: None, - }, - ], - }, - ), - Import( - StmtImport { - range: 55..91, - names: [ - Alias { - range: 62..74, - name: Identifier { - id: "foo.bar", - range: 62..69, - }, - asname: Some( - Identifier { - id: "a", - range: 73..74, - }, - ), - }, - Alias { - range: 76..91, - name: Identifier { - id: "a.b.c.d", - range: 76..83, - }, - asname: Some( - Identifier { - id: "abcd", - range: 87..91, - }, - ), - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap.new deleted file mode 100644 index da1222e23e..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap.new +++ /dev/null @@ -1,7717 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/match.py ---- -## AST - -``` -Module( - ModModule { - range: 0..5743, - body: [ - Match( - StmtMatch { - range: 67..103, - subject: Name( - ExprName { - range: 73..74, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 80..103, - pattern: MatchValue( - PatternMatchValue { - range: 85..88, - value: UnaryOp( - ExprUnaryOp { - range: 85..88, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 86..88, - value: Complex { - real: 0.0, - imag: 0.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 98..103, - targets: [ - Name( - ExprName { - range: 98..99, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 102..103, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 126..167, - subject: Name( - ExprName { - range: 132..133, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 139..167, - pattern: MatchClass( - PatternMatchClass { - range: 144..152, - cls: Name( - ExprName { - range: 144..149, - id: "bytes", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 149..152, - patterns: [ - MatchAs( - PatternMatchAs { - range: 150..151, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 150..151, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 162..167, - targets: [ - Name( - ExprName { - range: 162..163, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 166..167, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 190..260, - subject: Name( - ExprName { - range: 196..197, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 203..229, - pattern: MatchValue( - PatternMatchValue { - range: 208..209, - value: NumberLiteral( - ExprNumberLiteral { - range: 208..209, - value: Int( - 0, - ), - }, - ), - }, - ), - guard: Some( - NumberLiteral( - ExprNumberLiteral { - range: 213..214, - value: Int( - 0, - ), - }, - ), - ), - body: [ - Assign( - StmtAssign { - range: 224..229, - targets: [ - Name( - ExprName { - range: 224..225, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 228..229, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 234..260, - pattern: MatchValue( - PatternMatchValue { - range: 239..240, - value: NumberLiteral( - ExprNumberLiteral { - range: 239..240, - value: Int( - 0, - ), - }, - ), - }, - ), - guard: Some( - NumberLiteral( - ExprNumberLiteral { - range: 244..245, - value: Int( - 1, - ), - }, - ), - ), - body: [ - Assign( - StmtAssign { - range: 255..260, - targets: [ - Name( - ExprName { - range: 255..256, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 259..260, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 283..332, - subject: NumberLiteral( - ExprNumberLiteral { - range: 289..290, - value: Int( - 3, - ), - }, - ), - cases: [ - MatchCase { - range: 296..332, - pattern: MatchOr( - PatternMatchOr { - range: 301..314, - patterns: [ - MatchValue( - PatternMatchValue { - range: 301..302, - value: NumberLiteral( - ExprNumberLiteral { - range: 301..302, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 305..306, - value: NumberLiteral( - ExprNumberLiteral { - range: 305..306, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 309..310, - value: NumberLiteral( - ExprNumberLiteral { - range: 309..310, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 313..314, - value: NumberLiteral( - ExprNumberLiteral { - range: 313..314, - value: Int( - 3, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 324..332, - targets: [ - Name( - ExprName { - range: 324..325, - id: "x", - ctx: Store, - }, - ), - ], - value: BooleanLiteral( - ExprBooleanLiteral { - range: 328..332, - value: true, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 355..403, - subject: Name( - ExprName { - range: 361..362, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 368..403, - pattern: MatchOr( - PatternMatchOr { - range: 373..388, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 373..379, - patterns: [ - MatchValue( - PatternMatchValue { - range: 374..375, - value: NumberLiteral( - ExprNumberLiteral { - range: 374..375, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 377..378, - value: NumberLiteral( - ExprNumberLiteral { - range: 377..378, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - MatchSequence( - PatternMatchSequence { - range: 382..388, - patterns: [ - MatchValue( - PatternMatchValue { - range: 383..384, - value: NumberLiteral( - ExprNumberLiteral { - range: 383..384, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 386..387, - value: NumberLiteral( - ExprNumberLiteral { - range: 386..387, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 398..403, - targets: [ - Name( - ExprName { - range: 398..399, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 402..403, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 445..523, - subject: Name( - ExprName { - range: 451..452, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 458..489, - pattern: MatchSequence( - PatternMatchSequence { - range: 463..467, - patterns: [ - MatchStar( - PatternMatchStar { - range: 464..466, - name: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Return( - StmtReturn { - range: 477..489, - value: Some( - StringLiteral( - ExprStringLiteral { - range: 484..489, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 484..489, - value: "seq", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - }, - ), - ], - }, - MatchCase { - range: 494..523, - pattern: MatchMapping( - PatternMatchMapping { - range: 499..501, - keys: [], - patterns: [], - rest: None, - }, - ), - guard: None, - body: [ - Return( - StmtReturn { - range: 511..523, - value: Some( - StringLiteral( - ExprStringLiteral { - range: 518..523, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 518..523, - value: "map", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 546..714, - subject: Name( - ExprName { - range: 552..553, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 559..594, - pattern: MatchMapping( - PatternMatchMapping { - range: 564..579, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 565..566, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 568..578, - patterns: [ - MatchValue( - PatternMatchValue { - range: 569..570, - value: NumberLiteral( - ExprNumberLiteral { - range: 569..570, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 572..573, - value: NumberLiteral( - ExprNumberLiteral { - range: 572..573, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 575..577, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 589..594, - targets: [ - Name( - ExprName { - range: 589..590, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 593..594, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 599..687, - pattern: MatchOr( - PatternMatchOr { - range: 604..672, - patterns: [ - MatchMapping( - PatternMatchMapping { - range: 604..626, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 605..606, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchOr( - PatternMatchOr { - range: 608..625, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 608..618, - patterns: [ - MatchValue( - PatternMatchValue { - range: 609..610, - value: NumberLiteral( - ExprNumberLiteral { - range: 609..610, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 612..613, - value: NumberLiteral( - ExprNumberLiteral { - range: 612..613, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 615..617, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - MatchSingleton( - PatternMatchSingleton { - range: 621..625, - value: True, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchMapping( - PatternMatchMapping { - range: 629..638, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 630..631, - value: Int( - 1, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 633..637, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 634..636, - patterns: [], - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchMapping( - PatternMatchMapping { - range: 641..656, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 642..643, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 645..655, - patterns: [ - MatchValue( - PatternMatchValue { - range: 646..647, - value: NumberLiteral( - ExprNumberLiteral { - range: 646..647, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 649..650, - value: NumberLiteral( - ExprNumberLiteral { - range: 649..650, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 652..654, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchSequence( - PatternMatchSequence { - range: 659..661, - patterns: [], - }, - ), - MatchValue( - PatternMatchValue { - range: 664..667, - value: StringLiteral( - ExprStringLiteral { - range: 664..667, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 664..667, - value: "X", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 670..672, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 682..687, - targets: [ - Name( - ExprName { - range: 682..683, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 686..687, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 692..714, - pattern: MatchSequence( - PatternMatchSequence { - range: 697..699, - patterns: [], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 709..714, - targets: [ - Name( - ExprName { - range: 709..710, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 713..714, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 737..782, - subject: Name( - ExprName { - range: 743..744, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 750..782, - pattern: MatchValue( - PatternMatchValue { - range: 755..767, - value: BinOp( - ExprBinOp { - range: 755..767, - left: NumberLiteral( - ExprNumberLiteral { - range: 755..759, - value: Float( - 0.25, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 762..767, - value: Complex { - real: 0.0, - imag: 1.75, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 777..782, - targets: [ - Name( - ExprName { - range: 777..778, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 781..782, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 805..841, - subject: Name( - ExprName { - range: 811..812, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 818..841, - pattern: MatchValue( - PatternMatchValue { - range: 823..826, - value: UnaryOp( - ExprUnaryOp { - range: 823..826, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 824..826, - value: Complex { - real: 0.0, - imag: 0.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 836..841, - targets: [ - Name( - ExprName { - range: 836..837, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 840..841, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 864..913, - subject: NumberLiteral( - ExprNumberLiteral { - range: 870..871, - value: Int( - 4, - ), - }, - ), - cases: [ - MatchCase { - range: 877..913, - pattern: MatchOr( - PatternMatchOr { - range: 882..895, - patterns: [ - MatchValue( - PatternMatchValue { - range: 882..883, - value: NumberLiteral( - ExprNumberLiteral { - range: 882..883, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 886..887, - value: NumberLiteral( - ExprNumberLiteral { - range: 886..887, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 890..891, - value: NumberLiteral( - ExprNumberLiteral { - range: 890..891, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 894..895, - value: NumberLiteral( - ExprNumberLiteral { - range: 894..895, - value: Int( - 3, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 905..913, - targets: [ - Name( - ExprName { - range: 905..906, - id: "x", - ctx: Store, - }, - ), - ], - value: BooleanLiteral( - ExprBooleanLiteral { - range: 909..913, - value: true, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 936..975, - subject: Name( - ExprName { - range: 942..943, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 949..975, - pattern: MatchValue( - PatternMatchValue { - range: 954..955, - value: NumberLiteral( - ExprNumberLiteral { - range: 954..955, - value: Int( - 0, - ), - }, - ), - }, - ), - guard: Some( - Name( - ExprName { - range: 959..960, - id: "x", - ctx: Load, - }, - ), - ), - body: [ - Assign( - StmtAssign { - range: 970..975, - targets: [ - Name( - ExprName { - range: 970..971, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 974..975, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 998..1098, - subject: Name( - ExprName { - range: 1004..1005, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1011..1037, - pattern: MatchMapping( - PatternMatchMapping { - range: 1016..1022, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 1017..1018, - value: Int( - 1, - ), - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 1020..1021, - value: NumberLiteral( - ExprNumberLiteral { - range: 1020..1021, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1032..1037, - targets: [ - Name( - ExprName { - range: 1032..1033, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1036..1037, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 1042..1068, - pattern: MatchMapping( - PatternMatchMapping { - range: 1047..1053, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 1048..1049, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchValue( - PatternMatchValue { - range: 1051..1052, - value: NumberLiteral( - ExprNumberLiteral { - range: 1051..1052, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1063..1068, - targets: [ - Name( - ExprName { - range: 1063..1064, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1067..1068, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 1073..1098, - pattern: MatchMapping( - PatternMatchMapping { - range: 1078..1083, - keys: [], - patterns: [], - rest: Some( - Identifier { - id: "z", - range: 1081..1082, - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1093..1098, - targets: [ - Name( - ExprName { - range: 1093..1094, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1097..1098, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1121..1162, - subject: Call( - ExprCall { - range: 1127..1132, - func: Name( - ExprName { - range: 1127..1130, - id: "Seq", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1130..1132, - args: [], - keywords: [], - }, - }, - ), - cases: [ - MatchCase { - range: 1138..1162, - pattern: MatchSequence( - PatternMatchSequence { - range: 1143..1147, - patterns: [ - MatchStar( - PatternMatchStar { - range: 1144..1146, - name: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1157..1162, - targets: [ - Name( - ExprName { - range: 1157..1158, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1161..1162, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1185..1245, - subject: Name( - ExprName { - range: 1191..1192, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1198..1219, - pattern: MatchValue( - PatternMatchValue { - range: 1203..1204, - value: NumberLiteral( - ExprNumberLiteral { - range: 1203..1204, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1214..1219, - targets: [ - Name( - ExprName { - range: 1214..1215, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1218..1219, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 1224..1245, - pattern: MatchValue( - PatternMatchValue { - range: 1229..1230, - value: NumberLiteral( - ExprNumberLiteral { - range: 1229..1230, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1240..1245, - targets: [ - Name( - ExprName { - range: 1240..1241, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1244..1245, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1268..1315, - subject: Name( - ExprName { - range: 1274..1275, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1281..1315, - pattern: MatchMapping( - PatternMatchMapping { - range: 1286..1298, - keys: [ - StringLiteral( - ExprStringLiteral { - range: 1287..1292, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 1287..1292, - value: "foo", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - patterns: [ - MatchAs( - PatternMatchAs { - range: 1294..1297, - pattern: None, - name: Some( - Identifier { - id: "bar", - range: 1294..1297, - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1308..1315, - targets: [ - Name( - ExprName { - range: 1308..1309, - id: "y", - ctx: Store, - }, - ), - ], - value: Name( - ExprName { - range: 1312..1315, - id: "bar", - ctx: Load, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1338..1392, - subject: Tuple( - ExprTuple { - range: 1344..1353, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 1345..1346, - value: Int( - 0, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 1348..1349, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 1351..1352, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - cases: [ - MatchCase { - range: 1359..1392, - pattern: MatchSequence( - PatternMatchSequence { - range: 1364..1377, - patterns: [ - MatchValue( - PatternMatchValue { - range: 1365..1366, - value: NumberLiteral( - ExprNumberLiteral { - range: 1365..1366, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 1368..1369, - value: NumberLiteral( - ExprNumberLiteral { - range: 1368..1369, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 1371..1373, - name: Some( - Identifier { - id: "x", - range: 1372..1373, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 1375..1376, - value: NumberLiteral( - ExprNumberLiteral { - range: 1375..1376, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1387..1392, - targets: [ - Name( - ExprName { - range: 1387..1388, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1391..1392, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1415..1529, - subject: Name( - ExprName { - range: 1421..1422, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1428..1451, - pattern: MatchSequence( - PatternMatchSequence { - range: 1433..1436, - patterns: [ - MatchValue( - PatternMatchValue { - range: 1434..1435, - value: NumberLiteral( - ExprNumberLiteral { - range: 1434..1435, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1446..1451, - targets: [ - Name( - ExprName { - range: 1446..1447, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1450..1451, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 1456..1498, - pattern: MatchSequence( - PatternMatchSequence { - range: 1461..1467, - patterns: [ - MatchValue( - PatternMatchValue { - range: 1462..1463, - value: NumberLiteral( - ExprNumberLiteral { - range: 1462..1463, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 1465..1466, - value: NumberLiteral( - ExprNumberLiteral { - range: 1465..1466, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ), - guard: Some( - Named( - ExprNamed { - range: 1472..1482, - target: Name( - ExprName { - range: 1472..1473, - id: "x", - ctx: Store, - }, - ), - value: Subscript( - ExprSubscript { - range: 1477..1482, - value: Name( - ExprName { - range: 1477..1478, - id: "x", - ctx: Load, - }, - ), - slice: Slice( - ExprSlice { - range: 1479..1481, - lower: None, - upper: Some( - NumberLiteral( - ExprNumberLiteral { - range: 1480..1481, - value: Int( - 0, - ), - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Assign( - StmtAssign { - range: 1493..1498, - targets: [ - Name( - ExprName { - range: 1493..1494, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1497..1498, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 1503..1529, - pattern: MatchSequence( - PatternMatchSequence { - range: 1508..1514, - patterns: [ - MatchValue( - PatternMatchValue { - range: 1509..1510, - value: NumberLiteral( - ExprNumberLiteral { - range: 1509..1510, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 1512..1513, - value: NumberLiteral( - ExprNumberLiteral { - range: 1512..1513, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1524..1529, - targets: [ - Name( - ExprName { - range: 1524..1525, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1528..1529, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1552..1595, - subject: Name( - ExprName { - range: 1558..1559, - id: "w", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1565..1595, - pattern: MatchSequence( - PatternMatchSequence { - range: 1570..1580, - patterns: [ - MatchAs( - PatternMatchAs { - range: 1571..1572, - pattern: None, - name: Some( - Identifier { - id: "x", - range: 1571..1572, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 1574..1575, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 1574..1575, - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 1577..1579, - name: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1590..1595, - targets: [ - Name( - ExprName { - range: 1590..1591, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1594..1595, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1618..1664, - subject: Name( - ExprName { - range: 1624..1625, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1631..1664, - pattern: MatchValue( - PatternMatchValue { - range: 1636..1649, - value: BinOp( - ExprBinOp { - range: 1636..1649, - left: UnaryOp( - ExprUnaryOp { - range: 1636..1641, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 1637..1641, - value: Float( - 0.25, - ), - }, - ), - }, - ), - op: Sub, - right: NumberLiteral( - ExprNumberLiteral { - range: 1644..1649, - value: Complex { - real: 0.0, - imag: 1.75, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1659..1664, - targets: [ - Name( - ExprName { - range: 1659..1660, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1663..1664, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1687..1726, - subject: Tuple( - ExprTuple { - range: 1693..1697, - elts: [ - Name( - ExprName { - range: 1694..1695, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - cases: [ - MatchCase { - range: 1703..1726, - pattern: MatchSequence( - PatternMatchSequence { - range: 1708..1711, - patterns: [ - MatchAs( - PatternMatchAs { - range: 1709..1710, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 1709..1710, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1721..1726, - targets: [ - Name( - ExprName { - range: 1721..1722, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1725..1726, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1749..1789, - subject: Name( - ExprName { - range: 1755..1756, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1762..1789, - pattern: MatchValue( - PatternMatchValue { - range: 1767..1774, - value: Attribute( - ExprAttribute { - range: 1767..1774, - value: Attribute( - ExprAttribute { - range: 1767..1772, - value: Attribute( - ExprAttribute { - range: 1767..1770, - value: Name( - ExprName { - range: 1767..1768, - id: "A", - ctx: Load, - }, - ), - attr: Identifier { - id: "B", - range: 1769..1770, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "C", - range: 1771..1772, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "D", - range: 1773..1774, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1784..1789, - targets: [ - Name( - ExprName { - range: 1784..1785, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1788..1789, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1812..1849, - subject: Name( - ExprName { - range: 1818..1819, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1825..1849, - pattern: MatchSingleton( - PatternMatchSingleton { - range: 1830..1834, - value: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1844..1849, - targets: [ - Name( - ExprName { - range: 1844..1845, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1848..1849, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1872..1906, - subject: Name( - ExprName { - range: 1878..1879, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1885..1906, - pattern: MatchValue( - PatternMatchValue { - range: 1890..1891, - value: NumberLiteral( - ExprNumberLiteral { - range: 1890..1891, - value: Int( - 0, - ), - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1901..1906, - targets: [ - Name( - ExprName { - range: 1901..1902, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1905..1906, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1929..1967, - subject: Name( - ExprName { - range: 1935..1936, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 1942..1967, - pattern: MatchSingleton( - PatternMatchSingleton { - range: 1947..1952, - value: False, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 1962..1967, - targets: [ - Name( - ExprName { - range: 1962..1963, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1966..1967, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 1990..2081, - subject: Name( - ExprName { - range: 1996..1997, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2003..2025, - pattern: MatchSequence( - PatternMatchSequence { - range: 2008..2010, - patterns: [], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2020..2025, - targets: [ - Name( - ExprName { - range: 2020..2021, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2024..2025, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 2030..2054, - pattern: MatchSequence( - PatternMatchSequence { - range: 2035..2039, - patterns: [ - MatchValue( - PatternMatchValue { - range: 2036..2038, - value: StringLiteral( - ExprStringLiteral { - range: 2036..2038, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2036..2038, - value: "", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2049..2054, - targets: [ - Name( - ExprName { - range: 2049..2050, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2053..2054, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 2059..2081, - pattern: MatchValue( - PatternMatchValue { - range: 2064..2066, - value: StringLiteral( - ExprStringLiteral { - range: 2064..2066, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2064..2066, - value: "", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2076..2081, - targets: [ - Name( - ExprName { - range: 2076..2077, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2080..2081, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2104..2138, - subject: Name( - ExprName { - range: 2110..2111, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2117..2138, - pattern: MatchAs( - PatternMatchAs { - range: 2122..2123, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 2122..2123, - }, - ), - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2133..2138, - targets: [ - Name( - ExprName { - range: 2133..2134, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2137..2138, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2161..2207, - subject: Name( - ExprName { - range: 2167..2168, - id: "w", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2174..2207, - pattern: MatchSequence( - PatternMatchSequence { - range: 2179..2192, - patterns: [ - MatchAs( - PatternMatchAs { - range: 2180..2181, - pattern: None, - name: Some( - Identifier { - id: "x", - range: 2180..2181, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 2183..2184, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 2183..2184, - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 2186..2191, - name: Some( - Identifier { - id: "rest", - range: 2187..2191, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2202..2207, - targets: [ - Name( - ExprName { - range: 2202..2203, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2206..2207, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2230..2307, - subject: Name( - ExprName { - range: 2236..2237, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2243..2307, - pattern: MatchOr( - PatternMatchOr { - range: 2248..2278, - patterns: [ - MatchAs( - PatternMatchAs { - range: 2249..2255, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 2249..2250, - value: NumberLiteral( - ExprNumberLiteral { - range: 2249..2250, - value: Int( - 0, - ), - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "z", - range: 2254..2255, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 2260..2266, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 2260..2261, - value: NumberLiteral( - ExprNumberLiteral { - range: 2260..2261, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "z", - range: 2265..2266, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 2271..2277, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 2271..2272, - value: NumberLiteral( - ExprNumberLiteral { - range: 2271..2272, - value: Int( - 2, - ), - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "z", - range: 2276..2277, - }, - ), - }, - ), - ], - }, - ), - guard: Some( - Compare( - ExprCompare { - range: 2282..2292, - left: Name( - ExprName { - range: 2282..2283, - id: "z", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - BinOp( - ExprBinOp { - range: 2287..2292, - left: Name( - ExprName { - range: 2287..2288, - id: "x", - ctx: Load, - }, - ), - op: Mod, - right: NumberLiteral( - ExprNumberLiteral { - range: 2291..2292, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - ), - body: [ - Assign( - StmtAssign { - range: 2302..2307, - targets: [ - Name( - ExprName { - range: 2302..2303, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2306..2307, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2330..2499, - subject: Name( - ExprName { - range: 2336..2337, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2343..2378, - pattern: MatchMapping( - PatternMatchMapping { - range: 2348..2363, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 2349..2350, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 2352..2362, - patterns: [ - MatchValue( - PatternMatchValue { - range: 2353..2354, - value: NumberLiteral( - ExprNumberLiteral { - range: 2353..2354, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 2356..2357, - value: NumberLiteral( - ExprNumberLiteral { - range: 2356..2357, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2359..2361, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2373..2378, - targets: [ - Name( - ExprName { - range: 2373..2374, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2377..2378, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 2383..2472, - pattern: MatchOr( - PatternMatchOr { - range: 2388..2457, - patterns: [ - MatchMapping( - PatternMatchMapping { - range: 2388..2411, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 2389..2390, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchOr( - PatternMatchOr { - range: 2392..2410, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 2392..2402, - patterns: [ - MatchValue( - PatternMatchValue { - range: 2393..2394, - value: NumberLiteral( - ExprNumberLiteral { - range: 2393..2394, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 2396..2397, - value: NumberLiteral( - ExprNumberLiteral { - range: 2396..2397, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2399..2401, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - MatchSingleton( - PatternMatchSingleton { - range: 2405..2410, - value: False, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2414..2423, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 2415..2416, - value: Int( - 1, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 2418..2422, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 2419..2421, - patterns: [], - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2426..2441, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 2427..2428, - value: Int( - 0, - ), - }, - ), - ], - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 2430..2440, - patterns: [ - MatchValue( - PatternMatchValue { - range: 2431..2432, - value: NumberLiteral( - ExprNumberLiteral { - range: 2431..2432, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 2434..2435, - value: NumberLiteral( - ExprNumberLiteral { - range: 2434..2435, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2437..2439, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - ], - rest: None, - }, - ), - MatchSequence( - PatternMatchSequence { - range: 2444..2446, - patterns: [], - }, - ), - MatchValue( - PatternMatchValue { - range: 2449..2452, - value: StringLiteral( - ExprStringLiteral { - range: 2449..2452, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2449..2452, - value: "X", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - MatchMapping( - PatternMatchMapping { - range: 2455..2457, - keys: [], - patterns: [], - rest: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2467..2472, - targets: [ - Name( - ExprName { - range: 2467..2468, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2471..2472, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - MatchCase { - range: 2477..2499, - pattern: MatchSequence( - PatternMatchSequence { - range: 2482..2484, - patterns: [], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2494..2499, - targets: [ - Name( - ExprName { - range: 2494..2495, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2498..2499, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2522..2568, - subject: Tuple( - ExprTuple { - range: 2528..2537, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 2529..2530, - value: Int( - 0, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2532..2533, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2535..2536, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - cases: [ - MatchCase { - range: 2543..2568, - pattern: MatchSequence( - PatternMatchSequence { - range: 2548..2553, - patterns: [ - MatchValue( - PatternMatchValue { - range: 2548..2549, - value: NumberLiteral( - ExprNumberLiteral { - range: 2548..2549, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 2551..2553, - name: Some( - Identifier { - id: "x", - range: 2552..2553, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2563..2568, - targets: [ - Name( - ExprName { - range: 2563..2564, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2567..2568, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2591..2638, - subject: Tuple( - ExprTuple { - range: 2597..2606, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 2598..2599, - value: Int( - 0, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2601..2602, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 2604..2605, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - cases: [ - MatchCase { - range: 2612..2638, - pattern: MatchSequence( - PatternMatchSequence { - range: 2617..2623, - patterns: [ - MatchStar( - PatternMatchStar { - range: 2617..2619, - name: Some( - Identifier { - id: "x", - range: 2618..2619, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 2621..2622, - value: NumberLiteral( - ExprNumberLiteral { - range: 2621..2622, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2633..2638, - targets: [ - Name( - ExprName { - range: 2633..2634, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2637..2638, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2661..2697, - subject: Tuple( - ExprTuple { - range: 2667..2669, - elts: [ - Name( - ExprName { - range: 2667..2668, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 2675..2697, - pattern: MatchSequence( - PatternMatchSequence { - range: 2680..2682, - patterns: [ - MatchAs( - PatternMatchAs { - range: 2680..2681, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 2680..2681, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2692..2697, - targets: [ - Name( - ExprName { - range: 2692..2693, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2696..2697, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2720..2760, - subject: Tuple( - ExprTuple { - range: 2726..2730, - elts: [ - Name( - ExprName { - range: 2726..2727, - id: "w", - ctx: Load, - }, - ), - Name( - ExprName { - range: 2729..2730, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 2736..2760, - pattern: MatchSequence( - PatternMatchSequence { - range: 2741..2745, - patterns: [ - MatchAs( - PatternMatchAs { - range: 2741..2742, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 2741..2742, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 2744..2745, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 2744..2745, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2755..2760, - targets: [ - Name( - ExprName { - range: 2755..2756, - id: "v", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2759..2760, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2783..2829, - subject: Tuple( - ExprTuple { - range: 2789..2796, - elts: [ - Named( - ExprNamed { - range: 2789..2795, - target: Name( - ExprName { - range: 2789..2790, - id: "w", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 2794..2795, - id: "x", - ctx: Load, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 2802..2829, - pattern: MatchSequence( - PatternMatchSequence { - range: 2807..2814, - patterns: [ - MatchAs( - PatternMatchAs { - range: 2807..2813, - pattern: Some( - MatchAs( - PatternMatchAs { - range: 2807..2808, - pattern: None, - name: Some( - Identifier { - id: "y", - range: 2807..2808, - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "v", - range: 2812..2813, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 2824..2829, - targets: [ - Name( - ExprName { - range: 2824..2825, - id: "z", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 2828..2829, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2831..2952, - subject: Name( - ExprName { - range: 2837..2838, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 2927..2952, - pattern: MatchValue( - PatternMatchValue { - range: 2932..2938, - value: FString( - ExprFString { - range: 2932..2938, - value: FStringValue { - inner: Single( - FString( - FString { - range: 2932..2938, - elements: [ - Expression( - FStringExpressionElement { - range: 2934..2937, - expression: Name( - ExprName { - range: 2935..2936, - id: "y", - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 2948..2952, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 2953..3025, - subject: Dict( - ExprDict { - range: 2959..2970, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 2960..2966, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2960..2966, - value: "test", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 2968..2969, - value: Int( - 1, - ), - }, - ), - }, - ], - }, - ), - cases: [ - MatchCase { - range: 2976..3025, - pattern: MatchMapping( - PatternMatchMapping { - range: 2981..3004, - keys: [], - patterns: [], - rest: Some( - Identifier { - id: "rest", - range: 2993..2997, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3014..3025, - value: Call( - ExprCall { - range: 3014..3025, - func: Name( - ExprName { - range: 3014..3019, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3019..3025, - args: [ - Name( - ExprName { - range: 3020..3024, - id: "rest", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3026..3129, - subject: Dict( - ExprDict { - range: 3032..3049, - items: [ - DictItem { - key: Some( - StringLiteral( - ExprStringLiteral { - range: 3033..3040, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3033..3040, - value: "label", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - value: StringLiteral( - ExprStringLiteral { - range: 3042..3048, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3042..3048, - value: "test", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ], - }, - ), - cases: [ - MatchCase { - range: 3055..3129, - pattern: MatchMapping( - PatternMatchMapping { - range: 3060..3107, - keys: [ - StringLiteral( - ExprStringLiteral { - range: 3070..3077, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3070..3077, - value: "label", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - patterns: [ - MatchAs( - PatternMatchAs { - range: 3079..3100, - pattern: Some( - MatchOr( - PatternMatchOr { - range: 3079..3091, - patterns: [ - MatchClass( - PatternMatchClass { - range: 3079..3084, - cls: Name( - ExprName { - range: 3079..3082, - id: "str", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 3082..3084, - patterns: [], - keywords: [], - }, - }, - ), - MatchSingleton( - PatternMatchSingleton { - range: 3087..3091, - value: None, - }, - ), - ], - }, - ), - ), - name: Some( - Identifier { - id: "label", - range: 3095..3100, - }, - ), - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3117..3129, - value: Call( - ExprCall { - range: 3117..3129, - func: Name( - ExprName { - range: 3117..3122, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 3122..3129, - args: [ - Name( - ExprName { - range: 3123..3128, - id: "label", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3130..3170, - subject: Name( - ExprName { - range: 3136..3137, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3143..3170, - pattern: MatchSequence( - PatternMatchSequence { - range: 3148..3155, - patterns: [ - MatchValue( - PatternMatchValue { - range: 3149..3150, - value: NumberLiteral( - ExprNumberLiteral { - range: 3149..3150, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3152..3153, - value: NumberLiteral( - ExprNumberLiteral { - range: 3152..3153, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 3165..3170, - targets: [ - Name( - ExprName { - range: 3165..3166, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 3169..3170, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3171..3211, - subject: Name( - ExprName { - range: 3177..3178, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3184..3211, - pattern: MatchSequence( - PatternMatchSequence { - range: 3189..3196, - patterns: [ - MatchValue( - PatternMatchValue { - range: 3190..3191, - value: NumberLiteral( - ExprNumberLiteral { - range: 3190..3191, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3193..3194, - value: NumberLiteral( - ExprNumberLiteral { - range: 3193..3194, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 3206..3211, - targets: [ - Name( - ExprName { - range: 3206..3207, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 3210..3211, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3212..3249, - subject: Name( - ExprName { - range: 3218..3219, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3225..3249, - pattern: MatchSequence( - PatternMatchSequence { - range: 3230..3234, - patterns: [ - MatchValue( - PatternMatchValue { - range: 3231..3232, - value: NumberLiteral( - ExprNumberLiteral { - range: 3231..3232, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Assign( - StmtAssign { - range: 3244..3249, - targets: [ - Name( - ExprName { - range: 3244..3245, - id: "y", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 3248..3249, - value: Int( - 0, - ), - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3250..3284, - subject: Tuple( - ExprTuple { - range: 3256..3258, - elts: [ - Name( - ExprName { - range: 3256..3257, - id: "x", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 3264..3284, - pattern: MatchAs( - PatternMatchAs { - range: 3269..3270, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 3269..3270, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 3280..3284, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3285..3321, - subject: Tuple( - ExprTuple { - range: 3291..3295, - elts: [ - Name( - ExprName { - range: 3291..3292, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3294..3295, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 3301..3321, - pattern: MatchAs( - PatternMatchAs { - range: 3306..3307, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 3306..3307, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 3317..3321, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3322..3359, - subject: Tuple( - ExprTuple { - range: 3328..3333, - elts: [ - Name( - ExprName { - range: 3328..3329, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 3331..3332, - id: "y", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - cases: [ - MatchCase { - range: 3339..3359, - pattern: MatchAs( - PatternMatchAs { - range: 3344..3345, - pattern: None, - name: Some( - Identifier { - id: "z", - range: 3344..3345, - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 3355..3359, - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3385..3475, - subject: Name( - ExprName { - range: 3391..3392, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3398..3420, - pattern: MatchSingleton( - PatternMatchSingleton { - range: 3403..3407, - value: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3417..3420, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3417..3420, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3425..3447, - pattern: MatchSingleton( - PatternMatchSingleton { - range: 3430..3434, - value: True, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3444..3447, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3444..3447, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3452..3475, - pattern: MatchSingleton( - PatternMatchSingleton { - range: 3457..3462, - value: False, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3472..3475, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3472..3475, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3497..3821, - subject: Name( - ExprName { - range: 3503..3504, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3510..3531, - pattern: MatchValue( - PatternMatchValue { - range: 3515..3518, - value: Attribute( - ExprAttribute { - range: 3515..3518, - value: Name( - ExprName { - range: 3515..3516, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 3517..3518, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3528..3531, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3528..3531, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3536..3559, - pattern: MatchValue( - PatternMatchValue { - range: 3541..3546, - value: Attribute( - ExprAttribute { - range: 3541..3546, - value: Attribute( - ExprAttribute { - range: 3541..3544, - value: Name( - ExprName { - range: 3541..3542, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 3543..3544, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "c", - range: 3545..3546, - }, - ctx: Load, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3556..3559, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3556..3559, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3564..3584, - pattern: MatchValue( - PatternMatchValue { - range: 3569..3571, - value: StringLiteral( - ExprStringLiteral { - range: 3569..3571, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3569..3571, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3581..3584, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3581..3584, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3589..3610, - pattern: MatchValue( - PatternMatchValue { - range: 3594..3597, - value: BytesLiteral( - ExprBytesLiteral { - range: 3594..3597, - value: BytesLiteralValue { - inner: Single( - BytesLiteral { - range: 3594..3597, - value: [], - flags: BytesLiteralFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3607..3610, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3607..3610, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3615..3634, - pattern: MatchValue( - PatternMatchValue { - range: 3620..3621, - value: NumberLiteral( - ExprNumberLiteral { - range: 3620..3621, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3631..3634, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3631..3634, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3639..3660, - pattern: MatchValue( - PatternMatchValue { - range: 3644..3647, - value: NumberLiteral( - ExprNumberLiteral { - range: 3644..3647, - value: Float( - 1.0, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3657..3660, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3657..3660, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3665..3687, - pattern: MatchValue( - PatternMatchValue { - range: 3670..3674, - value: NumberLiteral( - ExprNumberLiteral { - range: 3670..3674, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3684..3687, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3684..3687, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3692..3716, - pattern: MatchValue( - PatternMatchValue { - range: 3697..3703, - value: BinOp( - ExprBinOp { - range: 3697..3703, - left: NumberLiteral( - ExprNumberLiteral { - range: 3697..3698, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 3701..3703, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3713..3716, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3713..3716, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3721..3741, - pattern: MatchValue( - PatternMatchValue { - range: 3726..3728, - value: UnaryOp( - ExprUnaryOp { - range: 3726..3728, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 3727..3728, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3738..3741, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3738..3741, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3746..3767, - pattern: MatchValue( - PatternMatchValue { - range: 3751..3754, - value: UnaryOp( - ExprUnaryOp { - range: 3751..3754, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 3752..3754, - value: Float( - 1.0, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3764..3767, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3764..3767, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3772..3795, - pattern: MatchValue( - PatternMatchValue { - range: 3777..3782, - value: UnaryOp( - ExprUnaryOp { - range: 3777..3782, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 3778..3782, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3792..3795, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3792..3795, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3800..3821, - pattern: MatchValue( - PatternMatchValue { - range: 3806..3807, - value: NumberLiteral( - ExprNumberLiteral { - range: 3806..3807, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3818..3821, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3818..3821, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3840..3927, - subject: Name( - ExprName { - range: 3846..3847, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3853..3876, - pattern: MatchOr( - PatternMatchOr { - range: 3858..3863, - patterns: [ - MatchValue( - PatternMatchValue { - range: 3858..3859, - value: NumberLiteral( - ExprNumberLiteral { - range: 3858..3859, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3862..3863, - value: NumberLiteral( - ExprNumberLiteral { - range: 3862..3863, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3873..3876, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3873..3876, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3881..3927, - pattern: MatchOr( - PatternMatchOr { - range: 3886..3914, - patterns: [ - MatchValue( - PatternMatchValue { - range: 3886..3888, - value: StringLiteral( - ExprStringLiteral { - range: 3886..3888, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3886..3888, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3891..3894, - value: NumberLiteral( - ExprNumberLiteral { - range: 3891..3894, - value: Float( - 1.1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3897..3899, - value: UnaryOp( - ExprUnaryOp { - range: 3897..3899, - op: USub, - operand: NumberLiteral( - ExprNumberLiteral { - range: 3898..3899, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3902..3908, - value: BinOp( - ExprBinOp { - range: 3902..3908, - left: NumberLiteral( - ExprNumberLiteral { - range: 3902..3903, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 3906..3908, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 3911..3914, - value: Attribute( - ExprAttribute { - range: 3911..3914, - value: Name( - ExprName { - range: 3911..3912, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 3913..3914, - }, - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3924..3927, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3924..3927, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 3946..4163, - subject: Name( - ExprName { - range: 3952..3953, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 3959..3978, - pattern: MatchAs( - PatternMatchAs { - range: 3964..3965, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 3964..3965, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 3975..3978, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 3975..3978, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 3983..4007, - pattern: MatchAs( - PatternMatchAs { - range: 3988..3994, - pattern: Some( - MatchAs( - PatternMatchAs { - range: 3988..3989, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 3988..3989, - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "b", - range: 3993..3994, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4004..4007, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4004..4007, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4012..4042, - pattern: MatchAs( - PatternMatchAs { - range: 4017..4029, - pattern: Some( - MatchOr( - PatternMatchOr { - range: 4017..4022, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4017..4018, - value: NumberLiteral( - ExprNumberLiteral { - range: 4017..4018, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4021..4022, - value: NumberLiteral( - ExprNumberLiteral { - range: 4021..4022, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - ), - name: Some( - Identifier { - id: "two", - range: 4026..4029, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4039..4042, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4039..4042, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4047..4078, - pattern: MatchAs( - PatternMatchAs { - range: 4052..4065, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 4052..4058, - value: BinOp( - ExprBinOp { - range: 4052..4058, - left: NumberLiteral( - ExprNumberLiteral { - range: 4052..4053, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 4056..4058, - value: Complex { - real: 0.0, - imag: 3.0, - }, - }, - ), - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "sum", - range: 4062..4065, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4075..4078, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4075..4078, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4083..4110, - pattern: MatchAs( - PatternMatchAs { - range: 4088..4097, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 4088..4091, - value: Attribute( - ExprAttribute { - range: 4088..4091, - value: Name( - ExprName { - range: 4088..4089, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 4090..4091, - }, - ctx: Load, - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "ab", - range: 4095..4097, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4107..4110, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4107..4110, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4115..4134, - pattern: MatchAs( - PatternMatchAs { - range: 4120..4121, - pattern: None, - name: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4131..4134, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4131..4134, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4139..4163, - pattern: MatchAs( - PatternMatchAs { - range: 4144..4150, - pattern: Some( - MatchAs( - PatternMatchAs { - range: 4144..4145, - pattern: None, - name: None, - }, - ), - ), - name: Some( - Identifier { - id: "x", - range: 4149..4150, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4160..4163, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4160..4163, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 4188..4439, - subject: Name( - ExprName { - range: 4194..4195, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 4201..4226, - pattern: MatchSequence( - PatternMatchSequence { - range: 4206..4213, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4206..4207, - value: NumberLiteral( - ExprNumberLiteral { - range: 4206..4207, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4209..4210, - value: NumberLiteral( - ExprNumberLiteral { - range: 4209..4210, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4212..4213, - value: NumberLiteral( - ExprNumberLiteral { - range: 4212..4213, - value: Int( - 3, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4223..4226, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4223..4226, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4231..4259, - pattern: MatchSequence( - PatternMatchSequence { - range: 4236..4246, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4237..4238, - value: NumberLiteral( - ExprNumberLiteral { - range: 4237..4238, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4240..4241, - value: NumberLiteral( - ExprNumberLiteral { - range: 4240..4241, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4243..4244, - value: NumberLiteral( - ExprNumberLiteral { - range: 4243..4244, - value: Int( - 3, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4256..4259, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4256..4259, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4264..4304, - pattern: MatchSequence( - PatternMatchSequence { - range: 4269..4291, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4270..4276, - value: BinOp( - ExprBinOp { - range: 4270..4276, - left: NumberLiteral( - ExprNumberLiteral { - range: 4270..4271, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 4274..4276, - value: Complex { - real: 0.0, - imag: 2.0, - }, - }, - ), - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 4278..4279, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 4278..4279, - }, - ), - }, - ), - MatchSingleton( - PatternMatchSingleton { - range: 4281..4285, - value: None, - }, - ), - MatchValue( - PatternMatchValue { - range: 4287..4290, - value: Attribute( - ExprAttribute { - range: 4287..4290, - value: Name( - ExprName { - range: 4287..4288, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 4289..4290, - }, - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4301..4304, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4301..4304, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4309..4343, - pattern: MatchAs( - PatternMatchAs { - range: 4314..4330, - pattern: Some( - MatchSequence( - PatternMatchSequence { - range: 4314..4325, - patterns: [ - MatchAs( - PatternMatchAs { - range: 4315..4321, - pattern: Some( - MatchValue( - PatternMatchValue { - range: 4315..4316, - value: NumberLiteral( - ExprNumberLiteral { - range: 4315..4316, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - name: Some( - Identifier { - id: "X", - range: 4320..4321, - }, - ), - }, - ), - MatchAs( - PatternMatchAs { - range: 4323..4324, - pattern: None, - name: Some( - Identifier { - id: "b", - range: 4323..4324, - }, - ), - }, - ), - ], - }, - ), - ), - name: Some( - Identifier { - id: "S", - range: 4329..4330, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4340..4343, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4340..4343, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4348..4380, - pattern: MatchSequence( - PatternMatchSequence { - range: 4353..4367, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4354..4355, - value: NumberLiteral( - ExprNumberLiteral { - range: 4354..4355, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4357..4358, - value: NumberLiteral( - ExprNumberLiteral { - range: 4357..4358, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4360..4366, - value: BinOp( - ExprBinOp { - range: 4360..4366, - left: NumberLiteral( - ExprNumberLiteral { - range: 4360..4361, - value: Int( - 3, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 4364..4366, - value: Complex { - real: 0.0, - imag: 1.0, - }, - }, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4377..4380, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4377..4380, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4385..4413, - pattern: MatchSequence( - PatternMatchSequence { - range: 4390..4400, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 4391..4396, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4392..4393, - value: NumberLiteral( - ExprNumberLiteral { - range: 4392..4393, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4394..4395, - value: NumberLiteral( - ExprNumberLiteral { - range: 4394..4395, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - MatchValue( - PatternMatchValue { - range: 4398..4399, - value: NumberLiteral( - ExprNumberLiteral { - range: 4398..4399, - value: Int( - 3, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4410..4413, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4410..4413, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4418..4439, - pattern: MatchSequence( - PatternMatchSequence { - range: 4423..4426, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4424..4425, - value: NumberLiteral( - ExprNumberLiteral { - range: 4424..4425, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4436..4439, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4436..4439, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 4460..4589, - subject: Name( - ExprName { - range: 4466..4467, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 4473..4494, - pattern: MatchSequence( - PatternMatchSequence { - range: 4478..4481, - patterns: [ - MatchStar( - PatternMatchStar { - range: 4478..4480, - name: Some( - Identifier { - id: "a", - range: 4479..4480, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4491..4494, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4491..4494, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4499..4520, - pattern: MatchSequence( - PatternMatchSequence { - range: 4504..4507, - patterns: [ - MatchStar( - PatternMatchStar { - range: 4504..4506, - name: None, - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4517..4520, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4517..4520, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4525..4556, - pattern: MatchSequence( - PatternMatchSequence { - range: 4530..4543, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4531..4532, - value: NumberLiteral( - ExprNumberLiteral { - range: 4531..4532, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4534..4535, - value: NumberLiteral( - ExprNumberLiteral { - range: 4534..4535, - value: Int( - 2, - ), - }, - ), - }, - ), - MatchStar( - PatternMatchStar { - range: 4537..4542, - name: Some( - Identifier { - id: "rest", - range: 4538..4542, - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4553..4556, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4553..4556, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4561..4589, - pattern: MatchSequence( - PatternMatchSequence { - range: 4566..4576, - patterns: [ - MatchStar( - PatternMatchStar { - range: 4567..4569, - name: None, - }, - ), - MatchValue( - PatternMatchValue { - range: 4571..4572, - value: NumberLiteral( - ExprNumberLiteral { - range: 4571..4572, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4574..4575, - value: NumberLiteral( - ExprNumberLiteral { - range: 4574..4575, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4586..4589, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4586..4589, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 4611..4883, - subject: Name( - ExprName { - range: 4617..4618, - id: "x", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 4624..4649, - pattern: MatchClass( - PatternMatchClass { - range: 4629..4636, - cls: Name( - ExprName { - range: 4629..4634, - id: "Point", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4634..4636, - patterns: [], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4646..4649, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4646..4649, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4654..4683, - pattern: MatchClass( - PatternMatchClass { - range: 4659..4670, - cls: Attribute( - ExprAttribute { - range: 4659..4668, - value: Attribute( - ExprAttribute { - range: 4659..4662, - value: Name( - ExprName { - range: 4659..4660, - id: "a", - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 4661..4662, - }, - ctx: Load, - }, - ), - attr: Identifier { - id: "Point", - range: 4663..4668, - }, - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4668..4670, - patterns: [], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4680..4683, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4680..4683, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4688..4718, - pattern: MatchClass( - PatternMatchClass { - range: 4693..4705, - cls: Name( - ExprName { - range: 4693..4700, - id: "Point2D", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4700..4705, - patterns: [], - keywords: [ - PatternKeyword { - range: 4701..4704, - attr: Identifier { - id: "x", - range: 4701..4702, - }, - pattern: MatchValue( - PatternMatchValue { - range: 4703..4704, - value: NumberLiteral( - ExprNumberLiteral { - range: 4703..4704, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4715..4718, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4715..4718, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4723..4759, - pattern: MatchClass( - PatternMatchClass { - range: 4728..4746, - cls: Name( - ExprName { - range: 4728..4735, - id: "Point2D", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4735..4746, - patterns: [], - keywords: [ - PatternKeyword { - range: 4736..4739, - attr: Identifier { - id: "x", - range: 4736..4737, - }, - pattern: MatchValue( - PatternMatchValue { - range: 4738..4739, - value: NumberLiteral( - ExprNumberLiteral { - range: 4738..4739, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - PatternKeyword { - range: 4741..4744, - attr: Identifier { - id: "y", - range: 4741..4742, - }, - pattern: MatchValue( - PatternMatchValue { - range: 4743..4744, - value: NumberLiteral( - ExprNumberLiteral { - range: 4743..4744, - value: Int( - 0, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4756..4759, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4756..4759, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4764..4795, - pattern: MatchClass( - PatternMatchClass { - range: 4769..4782, - cls: Name( - ExprName { - range: 4769..4776, - id: "Point2D", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4776..4782, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4777..4778, - value: NumberLiteral( - ExprNumberLiteral { - range: 4777..4778, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4780..4781, - value: NumberLiteral( - ExprNumberLiteral { - range: 4780..4781, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4792..4795, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4792..4795, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4800..4838, - pattern: MatchClass( - PatternMatchClass { - range: 4805..4825, - cls: Name( - ExprName { - range: 4805..4812, - id: "Point2D", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4812..4825, - patterns: [ - MatchSequence( - PatternMatchSequence { - range: 4813..4819, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4814..4815, - value: NumberLiteral( - ExprNumberLiteral { - range: 4814..4815, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4817..4818, - value: NumberLiteral( - ExprNumberLiteral { - range: 4817..4818, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - ], - keywords: [ - PatternKeyword { - range: 4821..4824, - attr: Identifier { - id: "y", - range: 4821..4822, - }, - pattern: MatchValue( - PatternMatchValue { - range: 4823..4824, - value: NumberLiteral( - ExprNumberLiteral { - range: 4823..4824, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4835..4838, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4835..4838, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4843..4883, - pattern: MatchClass( - PatternMatchClass { - range: 4848..4870, - cls: Name( - ExprName { - range: 4848..4855, - id: "Point2D", - ctx: Load, - }, - ), - arguments: PatternArguments { - range: 4855..4870, - patterns: [], - keywords: [ - PatternKeyword { - range: 4856..4864, - attr: Identifier { - id: "x", - range: 4856..4857, - }, - pattern: MatchSequence( - PatternMatchSequence { - range: 4858..4864, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4859..4860, - value: NumberLiteral( - ExprNumberLiteral { - range: 4859..4860, - value: Int( - 0, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4862..4863, - value: NumberLiteral( - ExprNumberLiteral { - range: 4862..4863, - value: Int( - 1, - ), - }, - ), - }, - ), - ], - }, - ), - }, - PatternKeyword { - range: 4866..4869, - attr: Identifier { - id: "y", - range: 4866..4867, - }, - pattern: MatchValue( - PatternMatchValue { - range: 4868..4869, - value: NumberLiteral( - ExprNumberLiteral { - range: 4868..4869, - value: Int( - 1, - ), - }, - ), - }, - ), - }, - ], - }, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4880..4883, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4880..4883, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 4907..5001, - subject: Named( - ExprNamed { - range: 4913..4919, - target: Name( - ExprName { - range: 4913..4914, - id: "x", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 4918..4919, - id: "b", - ctx: Load, - }, - ), - }, - ), - cases: [ - MatchCase { - range: 4925..4949, - pattern: MatchMapping( - PatternMatchMapping { - range: 4930..4936, - keys: [ - NumberLiteral( - ExprNumberLiteral { - range: 4931..4932, - value: Int( - 1, - ), - }, - ), - ], - patterns: [ - MatchAs( - PatternMatchAs { - range: 4934..4935, - pattern: None, - name: None, - }, - ), - ], - rest: None, - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4946..4949, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4946..4949, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 4954..5001, - pattern: MatchMapping( - PatternMatchMapping { - range: 4959..4988, - keys: [ - StringLiteral( - ExprStringLiteral { - range: 4960..4962, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 4960..4962, - value: "", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - NoneLiteral( - ExprNoneLiteral { - range: 4967..4971, - }, - ), - ], - patterns: [ - MatchAs( - PatternMatchAs { - range: 4964..4965, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 4964..4965, - }, - ), - }, - ), - MatchSequence( - PatternMatchSequence { - range: 4973..4979, - patterns: [ - MatchValue( - PatternMatchValue { - range: 4974..4975, - value: NumberLiteral( - ExprNumberLiteral { - range: 4974..4975, - value: Int( - 1, - ), - }, - ), - }, - ), - MatchValue( - PatternMatchValue { - range: 4977..4978, - value: NumberLiteral( - ExprNumberLiteral { - range: 4977..4978, - value: Int( - 2, - ), - }, - ), - }, - ), - ], - }, - ), - ], - rest: Some( - Identifier { - id: "rest", - range: 4983..4987, - }, - ), - }, - ), - guard: None, - body: [ - Expr( - StmtExpr { - range: 4998..5001, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 4998..5001, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Match( - StmtMatch { - range: 5019..5079, - subject: Name( - ExprName { - range: 5025..5026, - id: "y", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 5032..5053, - pattern: MatchAs( - PatternMatchAs { - range: 5037..5038, - pattern: None, - name: Some( - Identifier { - id: "a", - range: 5037..5038, - }, - ), - }, - ), - guard: Some( - Named( - ExprNamed { - range: 5042..5048, - target: Name( - ExprName { - range: 5042..5043, - id: "b", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 5047..5048, - id: "c", - ctx: Load, - }, - ), - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 5050..5053, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 5050..5053, - }, - ), - }, - ), - ], - }, - MatchCase { - range: 5058..5079, - pattern: MatchAs( - PatternMatchAs { - range: 5063..5064, - pattern: None, - name: Some( - Identifier { - id: "e", - range: 5063..5064, - }, - ), - }, - ), - guard: Some( - Compare( - ExprCompare { - range: 5069..5074, - left: NumberLiteral( - ExprNumberLiteral { - range: 5069..5070, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 5073..5074, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - body: [ - Expr( - StmtExpr { - range: 5076..5079, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 5076..5079, - }, - ), - }, - ), - ], - }, - ], - }, - ), - Expr( - StmtExpr { - range: 5108..5123, - value: Tuple( - ExprTuple { - range: 5108..5123, - elts: [ - BinOp( - ExprBinOp { - range: 5108..5120, - left: BinOp( - ExprBinOp { - range: 5108..5116, - left: Name( - ExprName { - range: 5108..5113, - id: "match", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 5115..5116, - id: "a", - ctx: Load, - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 5119..5120, - id: "b", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 5122..5123, - id: "c", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5149..5166, - value: Tuple( - ExprTuple { - range: 5149..5166, - elts: [ - BinOp( - ExprBinOp { - range: 5149..5163, - left: Name( - ExprName { - range: 5149..5154, - id: "match", - ctx: Load, - }, - ), - op: Mult, - right: BinOp( - ExprBinOp { - range: 5157..5162, - left: Name( - ExprName { - range: 5157..5158, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 5161..5162, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 5165..5166, - id: "c", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5192..5209, - value: Call( - ExprCall { - range: 5192..5209, - func: Name( - ExprName { - range: 5192..5197, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5198..5209, - args: [ - Starred( - ExprStarred { - range: 5199..5205, - value: BinOp( - ExprBinOp { - range: 5200..5205, - left: Name( - ExprName { - range: 5200..5201, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 5204..5205, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 5207..5208, - id: "c", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5236..5252, - value: BinOp( - ExprBinOp { - range: 5236..5252, - left: BinOp( - ExprBinOp { - range: 5236..5248, - left: Name( - ExprName { - range: 5236..5241, - id: "match", - ctx: Load, - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 5243..5248, - left: Name( - ExprName { - range: 5243..5244, - id: "a", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 5247..5248, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 5251..5252, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5279..5297, - value: BinOp( - ExprBinOp { - range: 5279..5297, - left: BinOp( - ExprBinOp { - range: 5279..5293, - left: Name( - ExprName { - range: 5279..5284, - id: "match", - ctx: Load, - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 5287..5292, - left: Name( - ExprName { - range: 5287..5288, - id: "a", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 5291..5292, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 5296..5297, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5324..5342, - value: BinOp( - ExprBinOp { - range: 5324..5342, - left: BinOp( - ExprBinOp { - range: 5324..5338, - left: Call( - ExprCall { - range: 5324..5334, - func: Name( - ExprName { - range: 5324..5329, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5330..5334, - args: [ - UnaryOp( - ExprUnaryOp { - range: 5331..5333, - op: USub, - operand: Name( - ExprName { - range: 5332..5333, - id: "a", - ctx: Load, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 5337..5338, - id: "b", - ctx: Load, - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 5341..5342, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5370..5380, - value: Attribute( - ExprAttribute { - range: 5370..5380, - value: Call( - ExprCall { - range: 5370..5378, - func: Name( - ExprName { - range: 5370..5375, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5376..5378, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 5379..5380, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5397..5409, - value: Attribute( - ExprAttribute { - range: 5397..5409, - value: Call( - ExprCall { - range: 5397..5407, - func: Name( - ExprName { - range: 5397..5402, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5403..5407, - args: [ - Tuple( - ExprTuple { - range: 5404..5406, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 5408..5409, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5428..5441, - value: Attribute( - ExprAttribute { - range: 5428..5441, - value: Call( - ExprCall { - range: 5428..5439, - func: Name( - ExprName { - range: 5428..5433, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5434..5439, - args: [ - Tuple( - ExprTuple { - range: 5435..5437, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 5440..5441, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5460..5471, - value: Attribute( - ExprAttribute { - range: 5460..5471, - value: Subscript( - ExprSubscript { - range: 5460..5469, - value: Name( - ExprName { - range: 5460..5465, - id: "match", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 5467..5468, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 5470..5471, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5489..5501, - value: Attribute( - ExprAttribute { - range: 5489..5501, - value: Subscript( - ExprSubscript { - range: 5489..5499, - value: Name( - ExprName { - range: 5489..5494, - id: "match", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 5496..5498, - elts: [ - Name( - ExprName { - range: 5496..5497, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 5500..5501, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5542..5556, - value: Attribute( - ExprAttribute { - range: 5542..5556, - value: Subscript( - ExprSubscript { - range: 5542..5554, - value: Name( - ExprName { - range: 5542..5547, - id: "match", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 5549..5553, - elts: [ - Name( - ExprName { - range: 5550..5551, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 5555..5556, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5577..5594, - value: Subscript( - ExprSubscript { - range: 5577..5594, - value: Call( - ExprCall { - range: 5577..5584, - func: Name( - ExprName { - range: 5577..5582, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5582..5584, - args: [], - keywords: [], - }, - }, - ), - slice: Slice( - ExprSlice { - range: 5585..5593, - lower: Some( - Name( - ExprName { - range: 5585..5586, - id: "a", - ctx: Load, - }, - ), - ), - upper: Some( - Name( - ExprName { - range: 5592..5593, - id: "b", - ctx: Load, - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - If( - StmtIf { - range: 5614..5633, - test: Named( - ExprNamed { - range: 5617..5627, - target: Name( - ExprName { - range: 5617..5622, - id: "match", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 5626..5627, - value: Int( - 1, - ), - }, - ), - }, - ), - body: [ - Pass( - StmtPass { - range: 5629..5633, - }, - ), - ], - elif_else_clauses: [], - }, - ), - Match( - StmtMatch { - range: 5634..5688, - subject: Name( - ExprName { - range: 5640..5645, - id: "match", - ctx: Load, - }, - ), - cases: [ - MatchCase { - range: 5651..5663, - pattern: MatchValue( - PatternMatchValue { - range: 5656..5657, - value: NumberLiteral( - ExprNumberLiteral { - range: 5656..5657, - value: Int( - 1, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 5659..5663, - }, - ), - ], - }, - MatchCase { - range: 5668..5688, - pattern: MatchValue( - PatternMatchValue { - range: 5673..5674, - value: NumberLiteral( - ExprNumberLiteral { - range: 5673..5674, - value: Int( - 2, - ), - }, - ), - }, - ), - guard: None, - body: [ - Pass( - StmtPass { - range: 5684..5688, - }, - ), - ], - }, - ], - }, - ), - Assign( - StmtAssign { - range: 5689..5725, - targets: [ - Name( - ExprName { - range: 5689..5694, - id: "match", - ctx: Store, - }, - ), - ], - value: Lambda( - ExprLambda { - range: 5697..5725, - parameters: Some( - Parameters { - range: 5704..5709, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 5704..5709, - parameter: Parameter { - range: 5704..5709, - name: Identifier { - id: "query", - range: 5704..5709, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Compare( - ExprCompare { - range: 5711..5725, - left: Name( - ExprName { - range: 5711..5716, - id: "query", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 5720..5725, - id: "event", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 5726..5742, - value: Call( - ExprCall { - range: 5726..5742, - func: Name( - ExprName { - range: 5726..5731, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5731..5742, - args: [ - Call( - ExprCall { - range: 5732..5741, - func: Name( - ExprName { - range: 5732..5737, - id: "match", - ctx: Load, - }, - ), - arguments: Arguments { - range: 5737..5741, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 5738..5740, - value: Int( - 12, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap.new deleted file mode 100644 index a639504e78..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap.new +++ /dev/null @@ -1,491 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/raise.py ---- -## AST - -``` -Module( - ModModule { - range: 0..289, - body: [ - Raise( - StmtRaise { - range: 8..13, - exc: None, - cause: None, - }, - ), - Raise( - StmtRaise { - range: 14..21, - exc: Some( - Name( - ExprName { - range: 20..21, - id: "a", - ctx: Load, - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 22..34, - exc: Some( - Tuple( - ExprTuple { - range: 28..34, - elts: [ - Name( - ExprName { - range: 29..30, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 32..33, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 35..46, - exc: Some( - Compare( - ExprCompare { - range: 41..46, - left: NumberLiteral( - ExprNumberLiteral { - range: 41..42, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 45..46, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 47..60, - exc: Some( - BoolOp( - ExprBoolOp { - range: 53..60, - op: And, - values: [ - Name( - ExprName { - range: 53..54, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 59..60, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 61..78, - exc: Some( - Lambda( - ExprLambda { - range: 67..78, - parameters: Some( - Parameters { - range: 74..75, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 74..75, - parameter: Parameter { - range: 74..75, - name: Identifier { - id: "x", - range: 74..75, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 77..78, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 79..92, - exc: Some( - Await( - ExprAwait { - range: 85..92, - value: Name( - ExprName { - range: 91..92, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 93..115, - exc: Some( - If( - ExprIf { - range: 99..115, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 104..108, - value: true, - }, - ), - body: Name( - ExprName { - range: 99..100, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 114..115, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - cause: None, - }, - ), - Raise( - StmtRaise { - range: 138..152, - exc: Some( - Name( - ExprName { - range: 144..145, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Name( - ExprName { - range: 151..152, - id: "a", - ctx: Load, - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 153..172, - exc: Some( - Name( - ExprName { - range: 159..160, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Tuple( - ExprTuple { - range: 166..172, - elts: [ - Name( - ExprName { - range: 167..168, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 170..171, - id: "b", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 173..191, - exc: Some( - Name( - ExprName { - range: 179..180, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Compare( - ExprCompare { - range: 186..191, - left: NumberLiteral( - ExprNumberLiteral { - range: 186..187, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 190..191, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 192..212, - exc: Some( - Name( - ExprName { - range: 198..199, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - BoolOp( - ExprBoolOp { - range: 205..212, - op: And, - values: [ - Name( - ExprName { - range: 205..206, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 211..212, - id: "b", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 213..237, - exc: Some( - Name( - ExprName { - range: 219..220, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Lambda( - ExprLambda { - range: 226..237, - parameters: Some( - Parameters { - range: 233..234, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 233..234, - parameter: Parameter { - range: 233..234, - name: Identifier { - id: "x", - range: 233..234, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 236..237, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 238..258, - exc: Some( - Name( - ExprName { - range: 244..245, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - Await( - ExprAwait { - range: 251..258, - value: Name( - ExprName { - range: 257..258, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Raise( - StmtRaise { - range: 259..288, - exc: Some( - Name( - ExprName { - range: 265..266, - id: "x", - ctx: Load, - }, - ), - ), - cause: Some( - If( - ExprIf { - range: 272..288, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 277..281, - value: true, - }, - ), - body: Name( - ExprName { - range: 272..273, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 287..288, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap.new deleted file mode 100644 index f6a9a4e2a9..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap.new +++ /dev/null @@ -1,383 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/return.py ---- -## AST - -``` -Module( - ModModule { - range: 0..191, - body: [ - Return( - StmtReturn { - range: 0..6, - value: None, - }, - ), - Return( - StmtReturn { - range: 7..15, - value: Some( - Name( - ExprName { - range: 14..15, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 16..25, - value: Some( - Starred( - ExprStarred { - range: 23..25, - value: Name( - ExprName { - range: 24..25, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 26..39, - value: Some( - Starred( - ExprStarred { - range: 33..39, - value: BinOp( - ExprBinOp { - range: 34..39, - left: Name( - ExprName { - range: 34..35, - id: "x", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 38..39, - id: "y", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 40..53, - value: Some( - Tuple( - ExprTuple { - range: 47..53, - elts: [ - Starred( - ExprStarred { - range: 47..49, - value: Name( - ExprName { - range: 48..49, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 51..53, - value: Name( - ExprName { - range: 52..53, - id: "y", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 54..69, - value: Some( - Named( - ExprNamed { - range: 62..68, - target: Name( - ExprName { - range: 62..63, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 67..68, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 70..81, - value: Some( - NoneLiteral( - ExprNoneLiteral { - range: 77..81, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 82..96, - value: Some( - BoolOp( - ExprBoolOp { - range: 89..96, - op: And, - values: [ - Name( - ExprName { - range: 89..90, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 95..96, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 97..109, - value: Some( - Compare( - ExprCompare { - range: 104..109, - left: NumberLiteral( - ExprNumberLiteral { - range: 104..105, - value: Int( - 1, - ), - }, - ), - ops: [ - Lt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 108..109, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 110..122, - value: Some( - Tuple( - ExprTuple { - range: 117..122, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 117..118, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 120..121, - value: Int( - 2, - ), - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 123..136, - value: Some( - Call( - ExprCall { - range: 130..136, - func: Name( - ExprName { - range: 130..134, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 134..136, - args: [], - keywords: [], - }, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 137..156, - value: Some( - Call( - ExprCall { - range: 144..156, - func: Attribute( - ExprAttribute { - range: 144..154, - value: Name( - ExprName { - range: 144..148, - id: "attr", - ctx: Load, - }, - ), - attr: Identifier { - id: "value", - range: 149..154, - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 154..156, - args: [], - keywords: [], - }, - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 157..171, - value: Some( - Await( - ExprAwait { - range: 164..171, - value: Name( - ExprName { - range: 170..171, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - Return( - StmtReturn { - range: 172..190, - value: Some( - Lambda( - ExprLambda { - range: 179..190, - parameters: Some( - Parameters { - range: 186..187, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 186..187, - parameter: Parameter { - range: 186..187, - name: Identifier { - id: "x", - range: 186..187, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 189..190, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap.new deleted file mode 100644 index 83d3944114..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap.new +++ /dev/null @@ -1,249 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/simple.py ---- -## AST - -``` -Module( - ModModule { - range: 0..172, - body: [ - Continue( - StmtContinue { - range: 61..69, - }, - ), - Break( - StmtBreak { - range: 70..75, - }, - ), - If( - StmtIf { - range: 77..86, - test: Name( - ExprName { - range: 80..81, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 83..86, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 83..86, - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - If( - StmtIf { - range: 87..100, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 90..94, - value: true, - }, - ), - body: [ - Pass( - StmtPass { - range: 96..100, - }, - ), - ], - elif_else_clauses: [], - }, - ), - Expr( - StmtExpr { - range: 101..102, - value: NumberLiteral( - ExprNumberLiteral { - range: 101..102, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 104..105, - value: NumberLiteral( - ExprNumberLiteral { - range: 104..105, - value: Int( - 2, - ), - }, - ), - }, - ), - Pass( - StmtPass { - range: 107..111, - }, - ), - Expr( - StmtExpr { - range: 112..113, - value: NumberLiteral( - ExprNumberLiteral { - range: 112..113, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 115..118, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 115..118, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 120..133, - value: If( - ExprIf { - range: 120..133, - test: Name( - ExprName { - range: 125..126, - id: "b", - ctx: Load, - }, - ), - body: Name( - ExprName { - range: 120..121, - id: "a", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 132..133, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - If( - StmtIf { - range: 135..157, - test: Name( - ExprName { - range: 138..139, - id: "c", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 141..142, - value: Name( - ExprName { - range: 141..142, - id: "B", - ctx: Load, - }, - ), - }, - ), - Delete( - StmtDelete { - range: 144..149, - targets: [ - Name( - ExprName { - range: 148..149, - id: "A", - ctx: Del, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 150..157, - test: None, - body: [ - Expr( - StmtExpr { - range: 156..157, - value: Name( - ExprName { - range: 156..157, - id: "C", - ctx: Load, - }, - ), - }, - ), - ], - }, - ], - }, - ), - If( - StmtIf { - range: 158..171, - test: Name( - ExprName { - range: 161..162, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 164..171, - value: Yield( - ExprYield { - range: 164..171, - value: Some( - Name( - ExprName { - range: 170..171, - id: "x", - ctx: Load, - }, - ), - ), - }, - ), - }, - ), - ], - elif_else_clauses: [], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap.new deleted file mode 100644 index ea9cce6376..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap.new +++ /dev/null @@ -1,1562 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/try.py ---- -## AST - -``` -Module( - ModModule { - range: 0..1223, - body: [ - Try( - StmtTry { - range: 0..28, - body: [ - Expr( - StmtExpr { - range: 9..12, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 9..12, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 13..28, - type_: None, - name: None, - body: [ - Expr( - StmtExpr { - range: 25..28, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 25..28, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 30..106, - body: [ - Expr( - StmtExpr { - range: 39..42, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 39..42, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 43..74, - type_: Some( - Name( - ExprName { - range: 50..60, - id: "Exception1", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 64..65, - }, - ), - body: [ - Expr( - StmtExpr { - range: 71..74, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 71..74, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 75..106, - type_: Some( - Name( - ExprName { - range: 82..92, - id: "Exception2", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 96..97, - }, - ), - body: [ - Expr( - StmtExpr { - range: 103..106, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 103..106, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 108..184, - body: [ - Expr( - StmtExpr { - range: 117..120, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 117..120, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 121..151, - type_: Some( - Name( - ExprName { - range: 128..137, - id: "Exception", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 141..142, - }, - ), - body: [ - Expr( - StmtExpr { - range: 148..151, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 148..151, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 152..167, - type_: None, - name: None, - body: [ - Expr( - StmtExpr { - range: 164..167, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 164..167, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [ - Expr( - StmtExpr { - range: 181..184, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 181..184, - }, - ), - }, - ), - ], - is_star: false, - }, - ), - Try( - StmtTry { - range: 186..228, - body: [ - Expr( - StmtExpr { - range: 195..198, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 195..198, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 199..214, - type_: None, - name: None, - body: [ - Expr( - StmtExpr { - range: 211..214, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 211..214, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [ - Expr( - StmtExpr { - range: 225..228, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 225..228, - }, - ), - }, - ), - ], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 230..289, - body: [ - Expr( - StmtExpr { - range: 239..242, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 239..242, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 243..258, - type_: None, - name: None, - body: [ - Expr( - StmtExpr { - range: 255..258, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 255..258, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [ - Expr( - StmtExpr { - range: 269..272, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 269..272, - }, - ), - }, - ), - ], - finalbody: [ - Expr( - StmtExpr { - range: 286..289, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 286..289, - }, - ), - }, - ), - ], - is_star: false, - }, - ), - Try( - StmtTry { - range: 291..320, - body: [ - Expr( - StmtExpr { - range: 300..303, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 300..303, - }, - ), - }, - ), - ], - handlers: [], - orelse: [], - finalbody: [ - Expr( - StmtExpr { - range: 317..320, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 317..320, - }, - ), - }, - ), - ], - is_star: false, - }, - ), - Try( - StmtTry { - range: 322..365, - body: [ - Expr( - StmtExpr { - range: 331..334, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 331..334, - }, - ), - }, - ), - ], - handlers: [], - orelse: [ - Expr( - StmtExpr { - range: 345..348, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 345..348, - }, - ), - }, - ), - ], - finalbody: [ - Expr( - StmtExpr { - range: 362..365, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 362..365, - }, - ), - }, - ), - ], - is_star: false, - }, - ), - Try( - StmtTry { - range: 367..441, - body: [ - Expr( - StmtExpr { - range: 376..379, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 376..379, - }, - ), - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 380..409, - type_: Some( - Name( - ExprName { - range: 388..394, - id: "GroupA", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "eg", - range: 398..400, - }, - ), - body: [ - Expr( - StmtExpr { - range: 406..409, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 406..409, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 410..441, - type_: Some( - Name( - ExprName { - range: 418..432, - id: "ExceptionGroup", - ctx: Load, - }, - ), - ), - name: None, - body: [ - Expr( - StmtExpr { - range: 438..441, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 438..441, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: true, - }, - ), - Try( - StmtTry { - range: 443..577, - body: [ - Raise( - StmtRaise { - range: 452..471, - exc: Some( - Call( - ExprCall { - range: 458..471, - func: Name( - ExprName { - range: 458..468, - id: "ValueError", - ctx: Load, - }, - ), - arguments: Arguments { - range: 468..471, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 469..470, - value: Int( - 1, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ), - cause: None, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 472..525, - type_: Some( - Name( - ExprName { - range: 479..488, - id: "TypeError", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 492..493, - }, - ), - body: [ - Expr( - StmtExpr { - range: 499..525, - value: Call( - ExprCall { - range: 499..525, - func: Name( - ExprName { - range: 499..504, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 504..525, - args: [ - FString( - ExprFString { - range: 505..524, - value: FStringValue { - inner: Single( - FString( - FString { - range: 505..524, - elements: [ - Literal( - FStringLiteralElement { - range: 507..514, - value: "caught ", - }, - ), - Expression( - FStringExpressionElement { - range: 514..523, - expression: Call( - ExprCall { - range: 515..522, - func: Name( - ExprName { - range: 515..519, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 519..522, - args: [ - Name( - ExprName { - range: 520..521, - id: "e", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 526..577, - type_: Some( - Name( - ExprName { - range: 533..540, - id: "OSError", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 544..545, - }, - ), - body: [ - Expr( - StmtExpr { - range: 551..577, - value: Call( - ExprCall { - range: 551..577, - func: Name( - ExprName { - range: 551..556, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 556..577, - args: [ - FString( - ExprFString { - range: 557..576, - value: FStringValue { - inner: Single( - FString( - FString { - range: 557..576, - elements: [ - Literal( - FStringLiteralElement { - range: 559..566, - value: "caught ", - }, - ), - Expression( - FStringExpressionElement { - range: 566..575, - expression: Call( - ExprCall { - range: 567..574, - func: Name( - ExprName { - range: 567..571, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 571..574, - args: [ - Name( - ExprName { - range: 572..573, - id: "e", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - Try( - StmtTry { - range: 579..831, - body: [ - Raise( - StmtRaise { - range: 588..669, - exc: Some( - Call( - ExprCall { - range: 594..669, - func: Name( - ExprName { - range: 594..608, - id: "ExceptionGroup", - ctx: Load, - }, - ), - arguments: Arguments { - range: 608..669, - args: [ - StringLiteral( - ExprStringLiteral { - range: 609..613, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 609..613, - value: "eg", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - List( - ExprList { - range: 615..668, - elts: [ - Call( - ExprCall { - range: 616..629, - func: Name( - ExprName { - range: 616..626, - id: "ValueError", - ctx: Load, - }, - ), - arguments: Arguments { - range: 626..629, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 627..628, - value: Int( - 1, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - Call( - ExprCall { - range: 631..643, - func: Name( - ExprName { - range: 631..640, - id: "TypeError", - ctx: Load, - }, - ), - arguments: Arguments { - range: 640..643, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 641..642, - value: Int( - 2, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - Call( - ExprCall { - range: 645..655, - func: Name( - ExprName { - range: 645..652, - id: "OSError", - ctx: Load, - }, - ), - arguments: Arguments { - range: 652..655, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 653..654, - value: Int( - 3, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - Call( - ExprCall { - range: 657..667, - func: Name( - ExprName { - range: 657..664, - id: "OSError", - ctx: Load, - }, - ), - arguments: Arguments { - range: 664..667, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 665..666, - value: Int( - 4, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ], - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - ), - cause: None, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 670..751, - type_: Some( - Name( - ExprName { - range: 678..687, - id: "TypeError", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 691..692, - }, - ), - body: [ - Expr( - StmtExpr { - range: 698..751, - value: Call( - ExprCall { - range: 698..751, - func: Name( - ExprName { - range: 698..703, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 703..751, - args: [ - FString( - ExprFString { - range: 704..750, - value: FStringValue { - inner: Single( - FString( - FString { - range: 704..750, - elements: [ - Literal( - FStringLiteralElement { - range: 706..713, - value: "caught ", - }, - ), - Expression( - FStringExpressionElement { - range: 713..722, - expression: Call( - ExprCall { - range: 714..721, - func: Name( - ExprName { - range: 714..718, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 718..721, - args: [ - Name( - ExprName { - range: 719..720, - id: "e", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 722..735, - value: " with nested ", - }, - ), - Expression( - FStringExpressionElement { - range: 735..749, - expression: Attribute( - ExprAttribute { - range: 736..748, - value: Name( - ExprName { - range: 736..737, - id: "e", - ctx: Load, - }, - ), - attr: Identifier { - id: "exceptions", - range: 738..748, - }, - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 752..831, - type_: Some( - Name( - ExprName { - range: 760..767, - id: "OSError", - ctx: Load, - }, - ), - ), - name: Some( - Identifier { - id: "e", - range: 771..772, - }, - ), - body: [ - Expr( - StmtExpr { - range: 778..831, - value: Call( - ExprCall { - range: 778..831, - func: Name( - ExprName { - range: 778..783, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 783..831, - args: [ - FString( - ExprFString { - range: 784..830, - value: FStringValue { - inner: Single( - FString( - FString { - range: 784..830, - elements: [ - Literal( - FStringLiteralElement { - range: 786..793, - value: "caught ", - }, - ), - Expression( - FStringExpressionElement { - range: 793..802, - expression: Call( - ExprCall { - range: 794..801, - func: Name( - ExprName { - range: 794..798, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 798..801, - args: [ - Name( - ExprName { - range: 799..800, - id: "e", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 802..815, - value: " with nested ", - }, - ), - Expression( - FStringExpressionElement { - range: 815..829, - expression: Attribute( - ExprAttribute { - range: 816..828, - value: Name( - ExprName { - range: 816..817, - id: "e", - ctx: Load, - }, - ), - attr: Identifier { - id: "exceptions", - range: 818..828, - }, - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - }, - }, - ), - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: true, - }, - ), - Try( - StmtTry { - range: 833..1075, - body: [ - Pass( - StmtPass { - range: 842..846, - }, - ), - ], - handlers: [ - ExceptHandler( - ExceptHandlerExceptHandler { - range: 847..875, - type_: Some( - StringLiteral( - ExprStringLiteral { - range: 854..865, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 854..865, - value: "exception", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 871..875, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 876..894, - type_: Some( - NumberLiteral( - ExprNumberLiteral { - range: 883..884, - value: Int( - 1, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 890..894, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 895..916, - type_: Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 902..906, - value: true, - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 912..916, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 917..939, - type_: Some( - BinOp( - ExprBinOp { - range: 924..929, - left: NumberLiteral( - ExprNumberLiteral { - range: 924..925, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 928..929, - value: Int( - 1, - ), - }, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 935..939, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 940..962, - type_: Some( - BinOp( - ExprBinOp { - range: 947..952, - left: Name( - ExprName { - range: 947..948, - id: "a", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 951..952, - id: "b", - ctx: Load, - }, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 958..962, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 963..987, - type_: Some( - BoolOp( - ExprBoolOp { - range: 970..977, - op: And, - values: [ - Name( - ExprName { - range: 970..971, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 976..977, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 983..987, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 988..1012, - type_: Some( - Await( - ExprAwait { - range: 995..1002, - value: Name( - ExprName { - range: 1001..1002, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 1008..1012, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 1013..1041, - type_: Some( - Lambda( - ExprLambda { - range: 1020..1031, - parameters: Some( - Parameters { - range: 1027..1028, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1027..1028, - parameter: Parameter { - range: 1027..1028, - name: Identifier { - id: "x", - range: 1027..1028, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 1030..1031, - id: "x", - ctx: Load, - }, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 1037..1041, - }, - ), - ], - }, - ), - ExceptHandler( - ExceptHandlerExceptHandler { - range: 1042..1075, - type_: Some( - If( - ExprIf { - range: 1049..1065, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 1054..1058, - value: true, - }, - ), - body: Name( - ExprName { - range: 1049..1050, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 1064..1065, - id: "y", - ctx: Load, - }, - ), - }, - ), - ), - name: None, - body: [ - Pass( - StmtPass { - range: 1071..1075, - }, - ), - ], - }, - ), - ], - orelse: [], - finalbody: [], - is_star: false, - }, - ), - If( - StmtIf { - range: 1077..1222, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 1080..1084, - value: true, - }, - ), - body: [ - Try( - StmtTry { - range: 1090..1133, - body: [ - Pass( - StmtPass { - range: 1103..1107, - }, - ), - ], - handlers: [], - orelse: [], - finalbody: [ - Pass( - StmtPass { - range: 1129..1133, - }, - ), - ], - is_star: false, - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 1208..1222, - test: None, - body: [ - Pass( - StmtPass { - range: 1218..1222, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap.new deleted file mode 100644 index be8d995ca1..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap.new +++ /dev/null @@ -1,2752 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/type.py ---- -## AST - -``` -Module( - ModModule { - range: 0..1828, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..12, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 9..12, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 13..31, - name: Name( - ExprName { - range: 18..19, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: BinOp( - ExprBinOp { - range: 22..31, - left: Name( - ExprName { - range: 22..25, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 28..31, - id: "str", - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 32..60, - name: Name( - ExprName { - range: 37..38, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: BinOp( - ExprBinOp { - range: 41..60, - left: Name( - ExprName { - range: 41..44, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: StringLiteral( - ExprStringLiteral { - range: 47..60, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 47..60, - value: "ForwardRefY", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 61..87, - name: Name( - ExprName { - range: 66..67, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 67..70, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 68..69, - name: Identifier { - id: "T", - range: 68..69, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: BinOp( - ExprBinOp { - range: 73..87, - left: Name( - ExprName { - range: 73..74, - id: "T", - ctx: Load, - }, - ), - op: BitOr, - right: Subscript( - ExprSubscript { - range: 77..87, - value: Name( - ExprName { - range: 77..81, - id: "list", - ctx: Load, - }, - ), - slice: Subscript( - ExprSubscript { - range: 82..86, - value: Name( - ExprName { - range: 82..83, - id: "X", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 84..85, - id: "T", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 101..116, - name: Name( - ExprName { - range: 106..107, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 107..110, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 108..109, - name: Identifier { - id: "T", - range: 108..109, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 113..116, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 117..145, - name: Name( - ExprName { - range: 122..123, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 123..126, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 124..125, - name: Identifier { - id: "T", - range: 124..125, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: BinOp( - ExprBinOp { - range: 129..145, - left: Subscript( - ExprSubscript { - range: 129..136, - value: Name( - ExprName { - range: 129..133, - id: "list", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 134..135, - id: "T", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - op: BitOr, - right: Subscript( - ExprSubscript { - range: 139..145, - value: Name( - ExprName { - range: 139..142, - id: "set", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 143..144, - id: "T", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 146..178, - name: Name( - ExprName { - range: 151..152, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 152..165, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 153..154, - name: Identifier { - id: "T", - range: 153..154, - }, - bound: None, - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 156..159, - name: Identifier { - id: "Ts", - range: 157..159, - }, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 161..164, - name: Identifier { - id: "P", - range: 163..164, - }, - default: None, - }, - ), - ], - }, - ), - value: Tuple( - ExprTuple { - range: 168..178, - elts: [ - Name( - ExprName { - range: 169..170, - id: "T", - ctx: Load, - }, - ), - Name( - ExprName { - range: 172..174, - id: "Ts", - ctx: Load, - }, - ), - Name( - ExprName { - range: 176..177, - id: "P", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 179..216, - name: Name( - ExprName { - range: 184..185, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 185..203, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 186..192, - name: Identifier { - id: "T", - range: 186..187, - }, - bound: Some( - Name( - ExprName { - range: 189..192, - id: "int", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 194..197, - name: Identifier { - id: "Ts", - range: 195..197, - }, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 199..202, - name: Identifier { - id: "P", - range: 201..202, - }, - default: None, - }, - ), - ], - }, - ), - value: Tuple( - ExprTuple { - range: 206..216, - elts: [ - Name( - ExprName { - range: 207..208, - id: "T", - ctx: Load, - }, - ), - Name( - ExprName { - range: 210..212, - id: "Ts", - ctx: Load, - }, - ), - Name( - ExprName { - range: 214..215, - id: "P", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 217..261, - name: Name( - ExprName { - range: 222..223, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 223..248, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 224..237, - name: Identifier { - id: "T", - range: 224..225, - }, - bound: Some( - Tuple( - ExprTuple { - range: 227..237, - elts: [ - Name( - ExprName { - range: 228..231, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 233..236, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 239..242, - name: Identifier { - id: "Ts", - range: 240..242, - }, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 244..247, - name: Identifier { - id: "P", - range: 246..247, - }, - default: None, - }, - ), - ], - }, - ), - value: Tuple( - ExprTuple { - range: 251..261, - elts: [ - Name( - ExprName { - range: 252..253, - id: "T", - ctx: Load, - }, - ), - Name( - ExprName { - range: 255..257, - id: "Ts", - ctx: Load, - }, - ), - Name( - ExprName { - range: 259..260, - id: "P", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 262..287, - name: Name( - ExprName { - range: 267..268, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 268..277, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 269..276, - name: Identifier { - id: "T", - range: 269..270, - }, - bound: None, - default: Some( - Name( - ExprName { - range: 273..276, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: BinOp( - ExprBinOp { - range: 280..287, - left: Name( - ExprName { - range: 280..281, - id: "T", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 284..287, - id: "str", - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 288..330, - name: Name( - ExprName { - range: 293..294, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 294..314, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 295..313, - name: Identifier { - id: "T", - range: 295..296, - }, - bound: Some( - BinOp( - ExprBinOp { - range: 298..307, - left: Name( - ExprName { - range: 298..301, - id: "int", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 304..307, - id: "str", - ctx: Load, - }, - ), - }, - ), - ), - default: Some( - Name( - ExprName { - range: 310..313, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: BinOp( - ExprBinOp { - range: 317..330, - left: BinOp( - ExprBinOp { - range: 317..324, - left: Name( - ExprName { - range: 317..318, - id: "T", - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 321..324, - id: "int", - ctx: Load, - }, - ), - }, - ), - op: BitOr, - right: Name( - ExprName { - range: 327..330, - id: "str", - ctx: Load, - }, - ), - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 331..384, - name: Name( - ExprName { - range: 336..337, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 337..361, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 338..360, - name: Identifier { - id: "Ts", - range: 339..341, - }, - default: Some( - Starred( - ExprStarred { - range: 344..360, - value: Subscript( - ExprSubscript { - range: 345..360, - value: Name( - ExprName { - range: 345..350, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 351..359, - elts: [ - Name( - ExprName { - range: 351..354, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 356..359, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 364..384, - value: Name( - ExprName { - range: 364..369, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 370..383, - elts: [ - Name( - ExprName { - range: 370..373, - id: "int", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 375..378, - value: Name( - ExprName { - range: 376..378, - id: "Ts", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 380..383, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 385..428, - name: Name( - ExprName { - range: 390..391, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 391..409, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 392..408, - name: Identifier { - id: "P", - range: 394..395, - }, - default: Some( - List( - ExprList { - range: 398..408, - elts: [ - Name( - ExprName { - range: 399..402, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 404..407, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 412..428, - value: Name( - ExprName { - range: 412..420, - id: "Callable", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 421..427, - elts: [ - Name( - ExprName { - range: 421..422, - id: "P", - ctx: Load, - }, - ), - Name( - ExprName { - range: 424..427, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 459..474, - name: Name( - ExprName { - range: 464..468, - id: "type", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 471..474, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 475..491, - name: Name( - ExprName { - range: 480..485, - id: "match", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 488..491, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 492..507, - name: Name( - ExprName { - range: 497..501, - id: "case", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 504..507, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 533..548, - name: Name( - ExprName { - range: 538..541, - id: "foo", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 544..548, - id: "type", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 549..565, - name: Name( - ExprName { - range: 554..557, - id: "foo", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 560..565, - id: "match", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 566..581, - name: Name( - ExprName { - range: 571..574, - id: "foo", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 577..581, - id: "case", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 605..620, - name: Name( - ExprName { - range: 613..614, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 617..620, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 621..636, - name: Name( - ExprName { - range: 626..627, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 633..636, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 637..652, - name: Name( - ExprName { - range: 642..643, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 649..652, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 653..673, - name: Name( - ExprName { - range: 658..659, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 668..671, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 674..693, - name: Name( - ExprName { - range: 685..686, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 686..689, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 687..688, - name: Identifier { - id: "T", - range: 687..688, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 692..693, - id: "T", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 694..714, - name: Name( - ExprName { - range: 699..700, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 707..710, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 708..709, - name: Identifier { - id: "T", - range: 708..709, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 713..714, - id: "T", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 715..734, - name: Name( - ExprName { - range: 720..721, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 721..724, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 722..723, - name: Identifier { - id: "T", - range: 722..723, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 733..734, - id: "T", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 756..768, - name: Name( - ExprName { - range: 761..762, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 765..768, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 770..782, - name: Name( - ExprName { - range: 775..776, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 779..782, - id: "str", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 784..797, - name: Name( - ExprName { - range: 789..790, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 793..797, - id: "type", - ctx: Load, - }, - ), - }, - ), - ClassDef( - StmtClassDef { - range: 798..819, - decorator_list: [], - name: Identifier { - id: "X", - range: 804..805, - }, - type_params: None, - arguments: None, - body: [ - TypeAlias( - StmtTypeAlias { - range: 807..819, - name: Name( - ExprName { - range: 812..813, - id: "X", - ctx: Store, - }, - ), - type_params: None, - value: Name( - ExprName { - range: 816..819, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, - ), - TypeAlias( - StmtTypeAlias { - range: 821..853, - name: Name( - ExprName { - range: 826..831, - id: "Point", - ctx: Store, - }, - ), - type_params: None, - value: Subscript( - ExprSubscript { - range: 834..853, - value: Name( - ExprName { - range: 834..839, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 840..852, - elts: [ - Name( - ExprName { - range: 840..845, - id: "float", - ctx: Load, - }, - ), - Name( - ExprName { - range: 847..852, - id: "float", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 854..881, - name: Name( - ExprName { - range: 859..864, - id: "Point", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 864..867, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 865..866, - name: Identifier { - id: "T", - range: 865..866, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 870..881, - value: Name( - ExprName { - range: 870..875, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 876..880, - elts: [ - Name( - ExprName { - range: 876..877, - id: "T", - ctx: Load, - }, - ), - Name( - ExprName { - range: 879..880, - id: "T", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 882..918, - name: Name( - ExprName { - range: 887..894, - id: "IntFunc", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 894..899, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 895..898, - name: Identifier { - id: "P", - range: 897..898, - }, - default: None, - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 902..918, - value: Name( - ExprName { - range: 902..910, - id: "Callable", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 911..917, - elts: [ - Name( - ExprName { - range: 911..912, - id: "P", - ctx: Load, - }, - ), - Name( - ExprName { - range: 914..917, - id: "int", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 932..972, - name: Name( - ExprName { - range: 937..949, - id: "LabeledTuple", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 949..954, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 950..953, - name: Identifier { - id: "Ts", - range: 951..953, - }, - default: None, - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 957..972, - value: Name( - ExprName { - range: 957..962, - id: "tuple", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 963..971, - elts: [ - Name( - ExprName { - range: 963..966, - id: "str", - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 968..971, - value: Name( - ExprName { - range: 969..971, - id: "Ts", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 989..1037, - name: Name( - ExprName { - range: 994..1010, - id: "HashableSequence", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 1010..1023, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1011..1022, - name: Identifier { - id: "T", - range: 1011..1012, - }, - bound: Some( - Name( - ExprName { - range: 1014..1022, - id: "Hashable", - ctx: Load, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 1026..1037, - value: Name( - ExprName { - range: 1026..1034, - id: "Sequence", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 1035..1036, - id: "T", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 1060..1110, - name: Name( - ExprName { - range: 1065..1081, - id: "IntOrStrSequence", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 1081..1096, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 1082..1095, - name: Identifier { - id: "T", - range: 1082..1083, - }, - bound: Some( - Tuple( - ExprTuple { - range: 1085..1095, - elts: [ - Name( - ExprName { - range: 1086..1089, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 1091..1094, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: None, - }, - ), - ], - }, - ), - value: Subscript( - ExprSubscript { - range: 1099..1110, - value: Name( - ExprName { - range: 1099..1107, - id: "Sequence", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 1108..1109, - id: "T", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1164..1178, - value: Tuple( - ExprTuple { - range: 1164..1178, - elts: [ - BinOp( - ExprBinOp { - range: 1164..1175, - left: BinOp( - ExprBinOp { - range: 1164..1171, - left: Name( - ExprName { - range: 1164..1168, - id: "type", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 1170..1171, - id: "a", - ctx: Load, - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 1174..1175, - id: "b", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 1177..1178, - id: "c", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1203..1219, - value: Tuple( - ExprTuple { - range: 1203..1219, - elts: [ - BinOp( - ExprBinOp { - range: 1203..1216, - left: Name( - ExprName { - range: 1203..1207, - id: "type", - ctx: Load, - }, - ), - op: Mult, - right: BinOp( - ExprBinOp { - range: 1210..1215, - left: Name( - ExprName { - range: 1210..1211, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 1214..1215, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - Name( - ExprName { - range: 1218..1219, - id: "c", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1244..1260, - value: Call( - ExprCall { - range: 1244..1260, - func: Name( - ExprName { - range: 1244..1248, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1249..1260, - args: [ - Starred( - ExprStarred { - range: 1250..1256, - value: BinOp( - ExprBinOp { - range: 1251..1256, - left: Name( - ExprName { - range: 1251..1252, - id: "a", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 1255..1256, - id: "b", - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 1258..1259, - id: "c", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1286..1301, - value: BinOp( - ExprBinOp { - range: 1286..1301, - left: BinOp( - ExprBinOp { - range: 1286..1297, - left: Name( - ExprName { - range: 1286..1290, - id: "type", - ctx: Load, - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 1292..1297, - left: Name( - ExprName { - range: 1292..1293, - id: "a", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 1296..1297, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 1300..1301, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1327..1344, - value: BinOp( - ExprBinOp { - range: 1327..1344, - left: BinOp( - ExprBinOp { - range: 1327..1340, - left: Name( - ExprName { - range: 1327..1331, - id: "type", - ctx: Load, - }, - ), - op: Sub, - right: BinOp( - ExprBinOp { - range: 1334..1339, - left: Name( - ExprName { - range: 1334..1335, - id: "a", - ctx: Load, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 1338..1339, - id: "b", - ctx: Load, - }, - ), - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 1343..1344, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1370..1387, - value: BinOp( - ExprBinOp { - range: 1370..1387, - left: BinOp( - ExprBinOp { - range: 1370..1383, - left: Call( - ExprCall { - range: 1370..1379, - func: Name( - ExprName { - range: 1370..1374, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1375..1379, - args: [ - UnaryOp( - ExprUnaryOp { - range: 1376..1378, - op: USub, - operand: Name( - ExprName { - range: 1377..1378, - id: "a", - ctx: Load, - }, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - op: Mult, - right: Name( - ExprName { - range: 1382..1383, - id: "b", - ctx: Load, - }, - ), - }, - ), - op: Add, - right: Name( - ExprName { - range: 1386..1387, - id: "c", - ctx: Load, - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1414..1423, - value: Attribute( - ExprAttribute { - range: 1414..1423, - value: Call( - ExprCall { - range: 1414..1421, - func: Name( - ExprName { - range: 1414..1418, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1419..1421, - args: [], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 1422..1423, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1439..1450, - value: Attribute( - ExprAttribute { - range: 1439..1450, - value: Call( - ExprCall { - range: 1439..1448, - func: Name( - ExprName { - range: 1439..1443, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1444..1448, - args: [ - Tuple( - ExprTuple { - range: 1445..1447, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 1449..1450, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1468..1480, - value: Attribute( - ExprAttribute { - range: 1468..1480, - value: Call( - ExprCall { - range: 1468..1478, - func: Name( - ExprName { - range: 1468..1472, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1473..1478, - args: [ - Tuple( - ExprTuple { - range: 1474..1476, - elts: [], - ctx: Load, - parenthesized: true, - }, - ), - ], - keywords: [], - }, - }, - ), - attr: Identifier { - id: "a", - range: 1479..1480, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1498..1508, - value: Attribute( - ExprAttribute { - range: 1498..1508, - value: Subscript( - ExprSubscript { - range: 1498..1506, - value: Name( - ExprName { - range: 1498..1502, - id: "type", - ctx: Load, - }, - ), - slice: Name( - ExprName { - range: 1504..1505, - id: "a", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 1507..1508, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1525..1536, - value: Attribute( - ExprAttribute { - range: 1525..1536, - value: Subscript( - ExprSubscript { - range: 1525..1534, - value: Name( - ExprName { - range: 1525..1529, - id: "type", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 1531..1533, - elts: [ - Name( - ExprName { - range: 1531..1532, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 1535..1536, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1575..1588, - value: Attribute( - ExprAttribute { - range: 1575..1588, - value: Subscript( - ExprSubscript { - range: 1575..1586, - value: Name( - ExprName { - range: 1575..1579, - id: "type", - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - range: 1581..1585, - elts: [ - Name( - ExprName { - range: 1582..1583, - id: "a", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: "b", - range: 1587..1588, - }, - ctx: Load, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1608..1624, - value: Subscript( - ExprSubscript { - range: 1608..1624, - value: Call( - ExprCall { - range: 1608..1614, - func: Name( - ExprName { - range: 1608..1612, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1612..1614, - args: [], - keywords: [], - }, - }, - ), - slice: Slice( - ExprSlice { - range: 1615..1623, - lower: Some( - Name( - ExprName { - range: 1615..1616, - id: "a", - ctx: Load, - }, - ), - ), - upper: Some( - Name( - ExprName { - range: 1622..1623, - id: "b", - ctx: Load, - }, - ), - ), - step: None, - }, - ), - ctx: Load, - }, - ), - }, - ), - If( - StmtIf { - range: 1643..1661, - test: Named( - ExprNamed { - range: 1646..1655, - target: Name( - ExprName { - range: 1646..1650, - id: "type", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 1654..1655, - value: Int( - 1, - ), - }, - ), - }, - ), - body: [ - Pass( - StmtPass { - range: 1657..1661, - }, - ), - ], - elif_else_clauses: [], - }, - ), - Assign( - StmtAssign { - range: 1662..1697, - targets: [ - Name( - ExprName { - range: 1662..1666, - id: "type", - ctx: Store, - }, - ), - ], - value: Lambda( - ExprLambda { - range: 1669..1697, - parameters: Some( - Parameters { - range: 1676..1681, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1676..1681, - parameter: Parameter { - range: 1676..1681, - name: Identifier { - id: "query", - range: 1676..1681, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Compare( - ExprCompare { - range: 1683..1697, - left: Name( - ExprName { - range: 1683..1688, - id: "query", - ctx: Load, - }, - ), - ops: [ - Eq, - ], - comparators: [ - Name( - ExprName { - range: 1692..1697, - id: "event", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1698..1713, - value: Call( - ExprCall { - range: 1698..1713, - func: Name( - ExprName { - range: 1698..1703, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1703..1713, - args: [ - Call( - ExprCall { - range: 1704..1712, - func: Name( - ExprName { - range: 1704..1708, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1708..1712, - args: [ - NumberLiteral( - ExprNumberLiteral { - range: 1709..1711, - value: Int( - 12, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1714..1724, - value: Call( - ExprCall { - range: 1714..1724, - func: Name( - ExprName { - range: 1714..1718, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1718..1724, - args: [ - Name( - ExprName { - range: 1719..1723, - id: "type", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 1725..1743, - targets: [ - Name( - ExprName { - range: 1725..1726, - id: "a", - ctx: Store, - }, - ), - ], - value: Compare( - ExprCompare { - range: 1732..1741, - left: Name( - ExprName { - range: 1732..1736, - id: "type", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( - ExprName { - range: 1740..1741, - id: "C", - ctx: Load, - }, - ), - ], - }, - ), - }, - ), - Assign( - StmtAssign { - range: 1744..1760, - targets: [ - Name( - ExprName { - range: 1744..1745, - id: "a", - ctx: Store, - }, - ), - ], - value: Call( - ExprCall { - range: 1751..1758, - func: Name( - ExprName { - range: 1751..1755, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1755..1758, - args: [ - Name( - ExprName { - range: 1756..1757, - id: "b", - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1761..1778, - value: Call( - ExprCall { - range: 1761..1778, - func: Name( - ExprName { - range: 1761..1765, - id: "type", - ctx: Load, - }, - ), - arguments: Arguments { - range: 1766..1778, - args: [], - keywords: [ - Keyword { - range: 1769..1776, - arg: Some( - Identifier { - id: "X", - range: 1769..1770, - }, - ), - value: Name( - ExprName { - range: 1773..1776, - id: "int", - ctx: Load, - }, - ), - }, - ], - }, - }, - ), - }, - ), - Assign( - StmtAssign { - range: 1779..1787, - targets: [ - Name( - ExprName { - range: 1779..1783, - id: "type", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1786..1787, - value: Int( - 1, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 1788..1800, - targets: [ - Name( - ExprName { - range: 1788..1792, - id: "type", - ctx: Store, - }, - ), - Name( - ExprName { - range: 1795..1796, - id: "x", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1799..1800, - value: Int( - 1, - ), - }, - ), - }, - ), - Assign( - StmtAssign { - range: 1801..1813, - targets: [ - Name( - ExprName { - range: 1801..1802, - id: "x", - ctx: Store, - }, - ), - Name( - ExprName { - range: 1805..1809, - id: "type", - ctx: Store, - }, - ), - ], - value: NumberLiteral( - ExprNumberLiteral { - range: 1812..1813, - value: Int( - 1, - ), - }, - ), - }, - ), - Expr( - StmtExpr { - range: 1814..1828, - value: Lambda( - ExprLambda { - range: 1814..1828, - parameters: Some( - Parameters { - range: 1821..1822, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 1821..1822, - parameter: Parameter { - range: 1821..1822, - name: Identifier { - id: "x", - range: 1821..1822, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 1824..1828, - id: "type", - ctx: Load, - }, - ), - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap.new deleted file mode 100644 index 65db231ca5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap.new +++ /dev/null @@ -1,462 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/while.py ---- -## AST - -``` -Module( - ModModule { - range: 0..314, - body: [ - While( - StmtWhile { - range: 0..16, - test: Name( - ExprName { - range: 6..7, - id: "x", - ctx: Load, - }, - ), - body: [ - Expr( - StmtExpr { - range: 13..16, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 13..16, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 18..61, - test: BoolOp( - ExprBoolOp { - range: 24..37, - op: And, - values: [ - Compare( - ExprCompare { - range: 25..30, - left: Name( - ExprName { - range: 25..26, - id: "x", - ctx: Load, - }, - ), - ops: [ - Gt, - ], - comparators: [ - NumberLiteral( - ExprNumberLiteral { - range: 29..30, - value: Int( - 1, - ), - }, - ), - ], - }, - ), - Name( - ExprName { - range: 36..37, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Pass( - StmtPass { - range: 43..47, - }, - ), - ], - orelse: [ - Expr( - StmtExpr { - range: 58..61, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 58..61, - }, - ), - }, - ), - ], - }, - ), - While( - StmtWhile { - range: 63..152, - test: BoolOp( - ExprBoolOp { - range: 69..76, - op: And, - values: [ - Name( - ExprName { - range: 69..70, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 75..76, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 82..85, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 82..85, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 90..111, - value: Call( - ExprCall { - range: 90..111, - func: Name( - ExprName { - range: 90..95, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 95..111, - args: [ - StringLiteral( - ExprStringLiteral { - range: 96..110, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 96..110, - value: "Hello World!", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - ], - orelse: [ - Expr( - StmtExpr { - range: 123..144, - value: Call( - ExprCall { - range: 123..144, - func: Name( - ExprName { - range: 123..128, - id: "print", - ctx: Load, - }, - ), - arguments: Arguments { - range: 128..144, - args: [ - StringLiteral( - ExprStringLiteral { - range: 129..143, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 129..143, - value: "Olá, Mundo!", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ], - keywords: [], - }, - }, - ), - }, - ), - Expr( - StmtExpr { - range: 149..152, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 149..152, - }, - ), - }, - ), - ], - }, - ), - While( - StmtWhile { - range: 154..171, - test: Named( - ExprNamed { - range: 160..166, - target: Name( - ExprName { - range: 160..161, - id: "a", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 165..166, - id: "b", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 168..171, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 168..171, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 172..197, - test: BoolOp( - ExprBoolOp { - range: 178..192, - op: And, - values: [ - Named( - ExprNamed { - range: 179..185, - target: Name( - ExprName { - range: 179..180, - id: "a", - ctx: Store, - }, - ), - value: Name( - ExprName { - range: 184..185, - id: "b", - ctx: Load, - }, - ), - }, - ), - Name( - ExprName { - range: 191..192, - id: "c", - ctx: Load, - }, - ), - ], - }, - ), - body: [ - Expr( - StmtExpr { - range: 194..197, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 194..197, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 198..220, - test: Lambda( - ExprLambda { - range: 204..215, - parameters: Some( - Parameters { - range: 211..212, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 211..212, - parameter: Parameter { - range: 211..212, - name: Identifier { - id: "x", - range: 211..212, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 214..215, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 217..220, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 217..220, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - While( - StmtWhile { - range: 221..239, - test: Await( - ExprAwait { - range: 227..234, - value: Name( - ExprName { - range: 233..234, - id: "x", - ctx: Load, - }, - ), - }, - ), - body: [ - Expr( - StmtExpr { - range: 236..239, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 236..239, - }, - ), - }, - ), - ], - orelse: [], - }, - ), - If( - StmtIf { - range: 241..313, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 244..248, - value: true, - }, - ), - body: [ - While( - StmtWhile { - range: 254..298, - test: Name( - ExprName { - range: 260..261, - id: "x", - ctx: Load, - }, - ), - body: [ - Pass( - StmtPass { - range: 271..275, - }, - ), - ], - orelse: [ - Pass( - StmtPass { - range: 294..298, - }, - ), - ], - }, - ), - ], - elif_else_clauses: [ - ElifElseClause { - range: 299..313, - test: None, - body: [ - Pass( - StmtPass { - range: 309..313, - }, - ), - ], - }, - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap.new deleted file mode 100644 index 161d2e1591..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap.new +++ /dev/null @@ -1,400 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/valid/statement/with.py ---- -## AST - -``` -Module( - ModModule { - range: 0..361, - body: [ - With( - StmtWith { - range: 137..151, - is_async: false, - items: [ - WithItem { - range: 142..146, - context_expr: Name( - ExprName { - range: 142..146, - id: "item", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 148..151, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 148..151, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 152..171, - is_async: false, - items: [ - WithItem { - range: 157..166, - context_expr: Name( - ExprName { - range: 157..161, - id: "item", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 165..166, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 168..171, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 168..171, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 172..194, - is_async: false, - items: [ - WithItem { - range: 177..182, - context_expr: Name( - ExprName { - range: 177..182, - id: "item1", - ctx: Load, - }, - ), - optional_vars: None, - }, - WithItem { - range: 184..189, - context_expr: Name( - ExprName { - range: 184..189, - id: "item2", - ctx: Load, - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 191..194, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 191..194, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 195..229, - is_async: false, - items: [ - WithItem { - range: 200..211, - context_expr: Name( - ExprName { - range: 200..205, - id: "item1", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 209..211, - id: "f1", - ctx: Store, - }, - ), - ), - }, - WithItem { - range: 213..224, - context_expr: Name( - ExprName { - range: 213..218, - id: "item2", - ctx: Load, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 222..224, - id: "f2", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 226..229, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 226..229, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 231..257, - is_async: false, - items: [ - WithItem { - range: 236..252, - context_expr: If( - ExprIf { - range: 236..252, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 241..245, - value: true, - }, - ), - body: Name( - ExprName { - range: 236..237, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 251..252, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: None, - }, - ], - body: [ - Expr( - StmtExpr { - range: 254..257, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 254..257, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 258..289, - is_async: false, - items: [ - WithItem { - range: 263..284, - context_expr: If( - ExprIf { - range: 263..279, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 268..272, - value: true, - }, - ), - body: Name( - ExprName { - range: 263..264, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 278..279, - id: "y", - ctx: Load, - }, - ), - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 283..284, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 286..289, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 286..289, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 313..334, - is_async: false, - items: [ - WithItem { - range: 318..329, - context_expr: Call( - ExprCall { - range: 318..324, - func: Name( - ExprName { - range: 318..322, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 322..324, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Name( - ExprName { - range: 328..329, - id: "f", - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 331..334, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 331..334, - }, - ), - }, - ), - ], - }, - ), - With( - StmtWith { - range: 335..361, - is_async: false, - items: [ - WithItem { - range: 340..356, - context_expr: Call( - ExprCall { - range: 340..346, - func: Name( - ExprName { - range: 340..344, - id: "open", - ctx: Load, - }, - ), - arguments: Arguments { - range: 344..346, - args: [], - keywords: [], - }, - }, - ), - optional_vars: Some( - Attribute( - ExprAttribute { - range: 350..356, - value: Name( - ExprName { - range: 350..351, - id: "f", - ctx: Load, - }, - ), - attr: Identifier { - id: "attr", - range: 352..356, - }, - ctx: Store, - }, - ), - ), - }, - ], - body: [ - Expr( - StmtExpr { - range: 358..361, - value: EllipsisLiteral( - ExprEllipsisLiteral { - range: 358..361, - }, - ), - }, - ), - ], - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap.new deleted file mode 100644 index 7d36dd55b5..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap.new +++ /dev/null @@ -1,198 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/type_param_param_spec.py ---- -## AST - -``` -Module( - ModModule { - range: 0..90, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..17, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..11, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 7..10, - name: Identifier { - id: "P", - range: 9..10, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 18..41, - name: Name( - ExprName { - range: 23..24, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 24..35, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 25..34, - name: Identifier { - id: "P", - range: 27..28, - }, - default: Some( - Name( - ExprName { - range: 31..34, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 38..41, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 42..62, - name: Name( - ExprName { - range: 47..48, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 48..56, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 49..50, - name: Identifier { - id: "T", - range: 49..50, - }, - bound: None, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 52..55, - name: Identifier { - id: "P", - range: 54..55, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 59..62, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 63..89, - name: Name( - ExprName { - range: 68..69, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 69..83, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 70..71, - name: Identifier { - id: "T", - range: 70..71, - }, - bound: None, - default: None, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 73..82, - name: Identifier { - id: "P", - range: 75..76, - }, - default: Some( - Name( - ExprName { - range: 79..82, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 86..89, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap.new deleted file mode 100644 index cf9dacb179..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap.new +++ /dev/null @@ -1,316 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/type_param_type_var.py ---- -## AST - -``` -Module( - ModModule { - range: 0..147, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..15, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..9, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 7..8, - name: Identifier { - id: "T", - range: 7..8, - }, - bound: None, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 12..15, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 16..37, - name: Name( - ExprName { - range: 21..22, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 22..31, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 23..30, - name: Identifier { - id: "T", - range: 23..24, - }, - bound: None, - default: Some( - Name( - ExprName { - range: 27..30, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 34..37, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 38..64, - name: Name( - ExprName { - range: 43..44, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 44..58, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 45..57, - name: Identifier { - id: "T", - range: 45..46, - }, - bound: Some( - Name( - ExprName { - range: 48..51, - id: "int", - ctx: Load, - }, - ), - ), - default: Some( - Name( - ExprName { - range: 54..57, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 61..64, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 65..98, - name: Name( - ExprName { - range: 70..71, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 71..92, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 72..91, - name: Identifier { - id: "T", - range: 72..73, - }, - bound: Some( - Tuple( - ExprTuple { - range: 75..85, - elts: [ - Name( - ExprName { - range: 76..79, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 81..84, - id: "int", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: Some( - Name( - ExprName { - range: 88..91, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 95..98, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 99..146, - name: Name( - ExprName { - range: 104..105, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 105..140, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 106..118, - name: Identifier { - id: "T", - range: 106..107, - }, - bound: Some( - Name( - ExprName { - range: 109..112, - id: "int", - ctx: Load, - }, - ), - ), - default: Some( - Name( - ExprName { - range: 115..118, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - TypeVar( - TypeParamTypeVar { - range: 120..139, - name: Identifier { - id: "U", - range: 120..121, - }, - bound: Some( - Tuple( - ExprTuple { - range: 123..133, - elts: [ - Name( - ExprName { - range: 124..127, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 129..132, - id: "int", - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ), - default: Some( - Name( - ExprName { - range: 136..139, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 143..146, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -``` diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap.new b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap.new deleted file mode 100644 index 59375c4149..0000000000 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap.new +++ /dev/null @@ -1,248 +0,0 @@ ---- -source: crates/ruff_python_parser/tests/fixtures.rs -assertion_line: 76 -input_file: crates/ruff_python_parser/resources/inline/ok/type_param_type_var_tuple.py ---- -## AST - -``` -Module( - ModModule { - range: 0..115, - body: [ - TypeAlias( - StmtTypeAlias { - range: 0..17, - name: Name( - ExprName { - range: 5..6, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 6..11, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 7..10, - name: Identifier { - id: "Ts", - range: 8..10, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 14..17, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 18..41, - name: Name( - ExprName { - range: 23..24, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 24..35, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 25..34, - name: Identifier { - id: "Ts", - range: 26..28, - }, - default: Some( - Name( - ExprName { - range: 31..34, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 38..41, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 42..66, - name: Name( - ExprName { - range: 47..48, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 48..60, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 49..59, - name: Identifier { - id: "Ts", - range: 50..52, - }, - default: Some( - Starred( - ExprStarred { - range: 55..59, - value: Name( - ExprName { - range: 56..59, - id: "int", - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 63..66, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 67..87, - name: Name( - ExprName { - range: 72..73, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 73..81, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 74..75, - name: Identifier { - id: "T", - range: 74..75, - }, - bound: None, - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 77..80, - name: Identifier { - id: "Ts", - range: 78..80, - }, - default: None, - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 84..87, - id: "int", - ctx: Load, - }, - ), - }, - ), - TypeAlias( - StmtTypeAlias { - range: 88..114, - name: Name( - ExprName { - range: 93..94, - id: "X", - ctx: Store, - }, - ), - type_params: Some( - TypeParams { - range: 94..108, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 95..96, - name: Identifier { - id: "T", - range: 95..96, - }, - bound: None, - default: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 98..107, - name: Identifier { - id: "Ts", - range: 99..101, - }, - default: Some( - Name( - ExprName { - range: 104..107, - id: "int", - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), - value: Name( - ExprName { - range: 111..114, - id: "int", - ctx: Load, - }, - ), - }, - ), - ], - }, -) -```