From da2cd613b593bcd181f880cac8d8fe79fb7ba3cb Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 12 Nov 2026 09:55:17 +0000 Subject: [PATCH] Store call arguments in source order Store positional and keyword arguments in one list for calls and class headers. Source-order visitors can walk the list directly, and evaluation-order visitors visit starred arguments before keywords. Box keyword values so a positional argument does not carry the full size of a keyword entry. --- .../resources/test/fixtures/refurb/FURB105.py | 1 + .../test/fixtures/ruff/RUF061_raises.py | 4 + .../src/checkers/ast/analyze/expression.rs | 62 +- crates/ruff_linter/src/checkers/ast/mod.rs | 45 +- crates/ruff_linter/src/fix/edits.rs | 2 +- .../rules/function_signature_change_in_3.rs | 2 +- .../src/rules/airflow/rules/removal_in_3.rs | 2 +- .../rules/runtime_value_in_dag_or_task.rs | 8 +- .../rules/task_branch_as_short_circuit.rs | 2 +- .../rules/fastapi_non_annotated_dependency.rs | 3 +- .../rules/fastapi_unused_path_parameter.rs | 5 +- .../rules/pytest_raises_exception_group.rs | 6 +- .../rules/hardcoded_password_func_arg.rs | 7 +- .../rules/jinja2_autoescape_false.rs | 2 +- .../flake8_bandit/rules/shell_injection.rs | 8 +- .../rules/snmp_insecure_version.rs | 2 +- .../rules/ssl_insecure_version.rs | 2 +- .../rules/suspicious_function_call.rs | 17 +- .../flake8_bandit/rules/unsafe_markup_use.rs | 3 +- .../src/rules/flake8_boolean_trap/helpers.rs | 2 +- .../rules/boolean_positional_value_in_call.rs | 3 +- .../src/rules/flake8_bugbear/helpers.rs | 16 +- .../rules/abstract_base_class.rs | 16 +- .../flake8_bugbear/rules/assert_false.rs | 11 +- .../rules/assert_raises_exception.rs | 2 +- .../rules/delattr_with_constant.rs | 18 +- .../rules/function_uses_loop_variable.rs | 6 +- .../rules/getattr_with_constant.rs | 10 +- .../rules/loop_iterator_mutation.rs | 2 +- .../rules/map_without_explicit_strict.rs | 6 +- .../rules/mutable_contextvar_default.rs | 2 +- .../rules/no_explicit_stacklevel.rs | 8 +- .../rules/re_sub_positional_args.rs | 2 +- .../rules/setattr_with_constant.rs | 10 +- .../star_arg_unpacking_after_keyword_arg.rs | 24 +- .../rules/strip_with_multi_characters.rs | 6 +- .../rules/unreliable_callable_check.rs | 12 +- .../rules/useless_contextlib_suppress.rs | 2 +- .../rules/zip_without_explicit_strict.rs | 6 +- .../rules/flake8_comprehensions/helpers.rs | 16 +- .../rules/unnecessary_call_around_sorted.rs | 4 +- .../rules/unnecessary_collection_call.rs | 12 +- .../unnecessary_comprehension_in_call.rs | 11 +- ...cessary_dict_comprehension_for_iterable.rs | 10 +- .../unnecessary_double_cast_or_process.rs | 19 +- .../rules/unnecessary_generator_dict.rs | 7 +- .../rules/unnecessary_generator_list.rs | 9 +- .../rules/unnecessary_generator_set.rs | 9 +- .../rules/unnecessary_list_call.rs | 16 +- .../unnecessary_list_comprehension_dict.rs | 7 +- .../unnecessary_list_comprehension_set.rs | 9 +- .../rules/unnecessary_literal_dict.rs | 7 +- .../rules/unnecessary_literal_set.rs | 9 +- .../unnecessary_literal_within_dict_call.rs | 6 +- .../unnecessary_literal_within_list_call.rs | 6 +- .../unnecessary_literal_within_tuple_call.rs | 11 +- .../rules/unnecessary_map.rs | 11 +- .../rules/unnecessary_subscript_reversal.rs | 2 +- .../call_datetime_strptime_without_zone.rs | 9 +- .../rules/model_without_dunder_str.rs | 2 +- .../rules/nullable_model_string_field.rs | 2 +- .../rules/string_in_exception.rs | 8 +- .../rules/f_string_in_gettext_func_call.rs | 7 +- .../rules/format_in_gettext_func_call.rs | 7 +- .../rules/printf_in_gettext_func_call.rs | 10 +- .../rules/exception_without_exc_info.rs | 2 +- .../rules/logging_call.rs | 10 +- .../rules/multiple_starts_ends_with.rs | 28 +- .../flake8_pie/rules/non_unique_enums.rs | 9 +- .../rules/unnecessary_dict_kwargs.rs | 12 +- .../rules/unnecessary_range_start.rs | 5 +- .../rules/generic_not_last_base_class.rs | 5 +- .../rules/unused_private_type_definition.rs | 4 +- .../src/rules/flake8_pytest_style/helpers.rs | 2 +- .../flake8_pytest_style/rules/assertion.rs | 68 +- .../flake8_pytest_style/rules/fixture.rs | 6 +- .../rules/flake8_pytest_style/rules/marks.rs | 13 +- .../rules/unittest_assert.rs | 36 +- .../flake8_simplify/rules/ast_bool_op.rs | 44 +- .../rules/flake8_simplify/rules/ast_expr.rs | 16 +- .../rules/flake8_simplify/rules/ast_ifexp.rs | 3 +- .../flake8_simplify/rules/ast_unary_op.rs | 3 +- .../if_else_block_instead_of_dict_get.rs | 8 +- .../flake8_simplify/rules/key_in_dict.rs | 6 +- .../flake8_simplify/rules/needless_bool.rs | 3 +- .../rules/reimplemented_builtin.rs | 3 +- .../rules/zip_dict_keys_and_values.rs | 21 +- .../rules/no_slots_in_namedtuple_subclass.rs | 8 +- .../rules/no_slots_in_str_subclass.rs | 12 +- .../rules/no_slots_in_tuple_subclass.rs | 6 +- .../rules/unused_arguments.rs | 3 +- .../src/rules/flake8_use_pathlib/helpers.rs | 4 +- .../rules/flake8_use_pathlib/rules/os_stat.rs | 2 +- .../path_constructor_current_directory.rs | 5 +- .../rules/replaceable_by_pathlib.rs | 2 +- crates/ruff_linter/src/rules/flynt/helpers.rs | 12 +- .../flynt/rules/static_join_to_fstring.rs | 13 +- .../pandas_vet/rules/inplace_argument.rs | 2 +- .../src/rules/pandas_vet/rules/read_table.rs | 2 +- .../src/rules/pep8_naming/helpers.rs | 2 +- .../rules/error_suffix_on_exception_name.rs | 2 +- .../perflint/rules/incorrect_dict_iterator.rs | 8 +- .../rules/manual_list_comprehension.rs | 16 +- .../rules/perflint/rules/manual_list_copy.rs | 16 +- .../perflint/rules/unnecessary_list_cast.rs | 13 +- .../src/rules/pyflakes/rules/strings.rs | 42 +- .../rules/pylint/rules/bad_str_strip_call.rs | 5 +- .../pylint/rules/comparison_with_itself.rs | 11 +- .../src/rules/pylint/rules/duplicate_bases.rs | 5 +- .../src/rules/pylint/rules/len_test.rs | 7 +- .../src/rules/pylint/rules/logging.rs | 9 +- .../pylint/rules/missing_maxsplit_arg.rs | 11 +- .../src/rules/pylint/rules/nan_comparison.rs | 10 +- .../src/rules/pylint/rules/nested_min_max.rs | 65 +- .../rules/pylint/rules/no_method_decorator.rs | 23 +- .../rules/pylint/rules/non_slot_assignment.rs | 1 - .../rules/pylint/rules/redefined_loop_name.rs | 13 +- .../rules/redefined_slots_in_subclass.rs | 2 +- .../pylint/rules/repeated_keyword_argument.rs | 11 +- .../pylint/rules/shallow_copy_environ.rs | 5 +- .../src/rules/pylint/rules/sys_exit_alias.rs | 6 +- .../src/rules/pylint/rules/type_bivariance.rs | 4 +- .../rules/type_name_incorrect_variance.rs | 4 +- .../pylint/rules/unnecessary_dunder_call.rs | 13 +- .../rules/pylint/rules/unnecessary_lambda.rs | 2 +- .../rules/unnecessary_list_index_lookup.rs | 2 +- .../pylint/rules/unspecified_encoding.rs | 5 +- ...convert_named_tuple_functional_to_class.rs | 34 +- .../convert_typed_dict_functional_to_class.rs | 86 +- .../src/rules/pyupgrade/rules/f_strings.rs | 8 +- .../rules/pyupgrade/rules/format_literals.rs | 7 +- .../rules/lru_cache_with_maxsize_none.rs | 15 +- .../rules/lru_cache_without_parameters.rs | 4 +- .../rules/pyupgrade/rules/native_literals.rs | 18 +- .../src/rules/pyupgrade/rules/pep695/mod.rs | 12 +- .../rules/pep695/non_pep695_generic_class.rs | 2 +- .../rules/pep695/non_pep695_type_alias.rs | 22 +- .../rules/pyupgrade/rules/replace_str_enum.rs | 2 +- .../rules/super_call_with_parameters.rs | 7 +- .../pyupgrade/rules/type_of_primitive.rs | 11 +- .../rules/unnecessary_class_parentheses.rs | 2 +- .../rules/unnecessary_encode_utf8.rs | 8 +- .../pyupgrade/rules/use_pep604_isinstance.rs | 10 +- .../rules/useless_class_metaclass_type.rs | 2 +- .../rules/useless_object_inheritance.rs | 2 +- .../ruff_linter/src/rules/refurb/helpers.rs | 44 +- .../src/rules/refurb/rules/bit_count.rs | 9 +- .../refurb/rules/check_and_remove_from_set.rs | 12 +- .../refurb/rules/for_loop_set_mutations.rs | 5 +- .../src/rules/refurb/rules/for_loop_writes.rs | 5 +- .../refurb/rules/fromisoformat_replace_z.rs | 15 +- .../refurb/rules/fstring_number_format.rs | 5 +- .../src/rules/refurb/rules/implicit_cwd.rs | 7 +- .../rules/refurb/rules/int_on_sliced_str.rs | 15 +- .../refurb/rules/isinstance_type_none.rs | 12 +- .../rules/refurb/rules/list_reverse_copy.rs | 11 +- .../rules/refurb/rules/metaclass_abcmeta.rs | 10 +- .../rules/refurb/rules/print_empty_string.rs | 64 +- .../src/rules/refurb/rules/read_whole_file.rs | 13 +- .../rules/refurb/rules/redundant_log_base.rs | 5 +- .../refurb/rules/reimplemented_starmap.rs | 22 +- .../src/rules/refurb/rules/repeated_append.rs | 10 +- .../rules/slice_to_remove_prefix_or_suffix.rs | 7 +- .../src/rules/refurb/rules/sorted_min_max.rs | 5 +- .../rules/refurb/rules/subclass_builtin.rs | 7 +- .../refurb/rules/unnecessary_enumerate.rs | 8 +- .../refurb/rules/unnecessary_from_float.rs | 7 +- .../rules/verbose_decimal_constructor.rs | 4 +- .../rules/refurb/rules/write_whole_file.rs | 6 +- ..._tests__print-empty-string_FURB105.py.snap | 178 +- .../access_annotations_from_class_dict.rs | 2 +- .../ruff/rules/assert_with_print_message.rs | 7 +- .../ruff/rules/decimal_from_float_literal.rs | 2 +- .../rules/ruff/rules/default_factory_kwarg.rs | 6 +- .../rules/duplicate_entry_in_dunder_all.rs | 6 +- .../explicit_f_string_type_conversion.rs | 5 +- .../ruff/rules/falsy_dict_get_fallback.rs | 4 +- .../ruff/rules/float_equality_comparison.rs | 4 +- .../ruff/rules/legacy_form_pytest_raises.rs | 42 +- .../ruff/rules/logging_eager_conversion.rs | 3 +- .../ruff/rules/map_int_version_parsing.rs | 18 +- .../ruff/rules/missing_fstring_syntax.rs | 6 +- .../ruff/rules/mutable_fromkeys_value.rs | 3 +- .../rules/ruff/rules/non_octal_permissions.rs | 4 +- .../rules/pytest_raises_ambiguous_pattern.rs | 2 +- .../ruff/rules/quadratic_list_summation.rs | 2 +- .../src/rules/ruff/rules/sort_dunder_all.rs | 6 +- .../src/rules/ruff/rules/starmap_zip.rs | 20 +- .../ruff/rules/unnecessary_cast_to_int.rs | 7 +- ...y_iterable_allocation_for_first_element.rs | 15 +- .../unnecessary_literal_within_deque_call.rs | 2 +- .../rules/unnecessary_regular_expression.rs | 4 +- .../unnecessary_regular_expression_compile.rs | 10 +- .../src/rules/ruff/rules/unnecessary_round.rs | 4 +- .../src/rules/ruff/rules/unraw_re_pattern.rs | 2 +- .../ruff/rules/zip_instead_of_pairwise.rs | 9 +- ...y-form-pytest-raises_RUF061_raises.py.snap | 50 +- .../tryceratops/rules/raise_vanilla_args.rs | 8 +- .../tryceratops/rules/verbose_log_message.rs | 3 +- crates/ruff_python_ast/src/comparable.rs | 56 +- crates/ruff_python_ast/src/helpers.rs | 38 +- crates/ruff_python_ast/src/nodes.rs | 156 +- crates/ruff_python_ast/src/visitor.rs | 29 +- .../src/visitor/transformer.rs | 12 +- .../tests/comparable.rs | 1 + .../tests/parentheses.rs | 10 +- ...rce_order__interleaved_call_arguments.snap | 17 + .../visitor__interleaved_call_arguments.snap | 14 + .../tests/source_order.rs | 6 + .../tests/visitor.rs | 6 + crates/ruff_python_codegen/src/generator.rs | 21 +- crates/ruff_python_edits/src/call.rs | 2 +- .../src/other/arguments.rs | 19 +- .../src/parser/expression.rs | 44 +- crates/ruff_python_parser/src/parser/mod.rs | 6 +- .../ruff_python_parser/src/parser/recovery.rs | 32 +- ...arser__tests__ipython_escape_commands.snap | 21 +- .../ruff_python_parser/src/semantic_errors.rs | 18 +- ...tax@ann_assign_stmt_invalid_target.py.snap | 3 +- ...tax@args_unparenthesized_generator.py.snap | 438 ++-- ...tax@assign_stmt_starred_expr_value.py.snap | 3 +- ...nvalid_syntax@class_def_empty_body.py.snap | 3 +- ...alid_syntax@class_def_missing_name.py.snap | 46 +- ...class_def_unclosed_type_param_list.py.snap | 35 +- ...unparenthesized_generator_argument.py.snap | 81 +- ...ntax@comma_separated_missing_comma.py.snap | 38 +- ...ma_separated_missing_first_element.py.snap | 21 +- .../invalid_syntax@debug_shadow_with.py.snap | 41 +- ...ax@decorator_named_expression_py37.py.snap | 19 +- ..._non_toplevel_call_expression_py38.py.snap | 6 +- ...alid_syntax@duplicate_keyword_args.py.snap | 229 +- ...essions__arguments__double_starred.py.snap | 173 +- ...ments__duplicate_keyword_arguments.py.snap | 213 +- ...ons__arguments__invalid_expression.py.snap | 154 +- ...uments__invalid_keyword_expression.py.snap | 226 +- ...ressions__arguments__invalid_order.py.snap | 238 +- ...sions__arguments__missing_argument.py.snap | 35 +- ...ressions__arguments__missing_comma.py.snap | 35 +- ...ons__arguments__missing_expression.py.snap | 113 +- ...ax@expressions__arguments__starred.py.snap | 187 +- ...expressions__arguments__unclosed_0.py.snap | 3 +- ...expressions__arguments__unclosed_1.py.snap | 19 +- ...expressions__arguments__unclosed_2.py.snap | 19 +- ...x@expressions__dict__comprehension.py.snap | 3 +- ...ons__dict__missing_closing_brace_0.py.snap | 3 +- ...x@expressions__list__comprehension.py.snap | 3 +- ...sions__named__missing_expression_2.py.snap | 3 +- ...ax@expressions__set__comprehension.py.snap | 3 +- ...sions__subscript__unclosed_slice_1.py.snap | 3 +- ...for_stmt_invalid_target_in_keyword.py.snap | 60 +- ...id_syntax@invalid_annotation_class.py.snap | 148 +- ...x@nested_async_comprehension_py310.py.snap | 246 +- ...id_syntax@parenthesized_kwarg_py38.py.snap | 135 +- ...valid_syntax@pep701_f_string_py311.py.snap | 154 +- ...798_unpacking_comprehensions_py314.py.snap | 95 +- ...nvalid_syntax@re_lex_logical_token.py.snap | 431 ++-- ...yntax@re_lex_logical_token_mac_eol.py.snap | 69 +- ...x@re_lex_logical_token_windows_eol.py.snap | 69 +- ...tax@re_lexing__line_continuation_1.py.snap | 35 +- ...ing__line_continuation_windows_eol.py.snap | 35 +- ...re_lexing__triple_quoted_fstring_3.py.snap | 105 +- .../invalid_syntax@re_lexing__ty_1828.py.snap | 3 +- ...tax@rebound_comprehension_variable.py.snap | 252 +- ...x@semicolon_before_match_statement.py.snap | 6 +- ...signed_pattern_non_literal_operand.py.snap | 3 +- .../invalid_syntax@star_index_py310.py.snap | 99 +- ..._syntax@starred_starred_expression.py.snap | 94 +- ...syntax@statements__if_extra_indent.py.snap | 3 +- ...ements__invalid_assignment_targets.py.snap | 12 +- ...nvalid_augmented_assignment_target.py.snap | 12 +- ..._match__invalid_lhs_or_rhs_pattern.py.snap | 50 +- ...ts__match__invalid_mapping_pattern.py.snap | 19 +- ...s__with__ambiguous_lpar_with_items.py.snap | 42 +- ...id_syntax@type_param_default_py312.py.snap | 6 +- ...nthesized_named_expr_set_comp_py38.py.snap | 21 +- ...ntax@all_async_comprehension_py310.py.snap | 40 +- ...tax@args_unparenthesized_generator.py.snap | 485 ++-- ...syntax@bare_raise_before_semicolon.py.snap | 6 +- .../valid_syntax@class_def_arguments.py.snap | 179 +- ...ecorator_expression_eval_hack_py38.py.snap | 41 +- ...ator_expression_identity_hack_py38.py.snap | 95 +- ...d_syntax@decorator_expression_py39.py.snap | 19 +- ...alid_syntax@expressions__arguments.py.snap | 2166 +++++++++-------- ...alid_syntax@expressions__attribute.py.snap | 15 +- .../valid_syntax@expressions__await.py.snap | 3 +- .../valid_syntax@expressions__call.py.snap | 48 +- ...lid_syntax@expressions__dictionary.py.snap | 45 +- ...ressions__dictionary_comprehension.py.snap | 21 +- ...valid_syntax@expressions__f_string.py.snap | 3 +- ...alid_syntax@expressions__generator.py.snap | 301 +-- .../valid_syntax@expressions__if.py.snap | 3 +- .../valid_syntax@expressions__lambda.py.snap | 9 +- .../valid_syntax@expressions__list.py.snap | 149 +- ...ax@expressions__list_comprehension.py.snap | 82 +- ...syntax@expressions__number_literal.py.snap | 98 +- ..._syntax@expressions__parenthesized.py.snap | 12 +- ...valid_syntax@expressions__t_string.py.snap | 3 +- .../valid_syntax@expressions__yield.py.snap | 3 +- ...lid_syntax@expressions__yield_from.py.snap | 3 +- ...ntax@lazy_import_semantic_ok_py315.py.snap | 6 +- ...syntax@match_classify_as_keyword_1.py.snap | 3 +- ..._classify_as_keyword_or_identifier.py.snap | 39 +- ...x@nested_async_comprehension_py310.py.snap | 63 +- ...x@nested_async_comprehension_py311.py.snap | 120 +- ..._syntax@non_duplicate_keyword_args.py.snap | 188 +- ...non_rebound_comprehension_variable.py.snap | 21 +- ...id_syntax@parenthesized_kwarg_py37.py.snap | 45 +- ...ntax@parenthesized_named_expr_py38.py.snap | 21 +- ...tax@parenthesized_star_index_py310.py.snap | 36 +- ...valid_syntax@pep701_f_string_py312.py.snap | 19 +- ...valid_syntax@pep750_t_string_py314.py.snap | 19 +- ...798_unpacking_comprehensions_py315.py.snap | 95 +- ...@semicolon_before_match_identifier.py.snap | 31 +- ...thesized_item_context_manager_py38.py.snap | 82 +- .../valid_syntax@star_index_py311.py.snap | 99 +- ...atement__ambiguous_lpar_with_items.py.snap | 232 +- .../valid_syntax@statement__assert.py.snap | 3 +- .../valid_syntax@statement__class.py.snap | 161 +- .../valid_syntax@statement__for.py.snap | 3 +- .../valid_syntax@statement__function.py.snap | 3 +- .../valid_syntax@statement__if.py.snap | 3 +- .../valid_syntax@statement__match.py.snap | 259 +- .../valid_syntax@statement__return.py.snap | 6 +- .../valid_syntax@statement__try.py.snap | 960 ++++---- .../valid_syntax@statement__type.py.snap | 299 +-- .../valid_syntax@statement__while.py.snap | 82 +- .../valid_syntax@statement__with.py.snap | 6 +- ...id_syntax@type_param_default_py313.py.snap | 3 +- ...ax@unparenthesized_named_expr_py39.py.snap | 21 +- ...alid_syntax@valid_annotation_class.py.snap | 148 +- .../ruff_python_semantic/src/analyze/class.rs | 8 +- crates/ruff_python_semantic/src/model.rs | 1 - crates/ruff_python_semantic/src/model/all.rs | 13 +- crates/ty_ide/src/completion.rs | 6 +- crates/ty_ide/src/inlay_hints.rs | 15 +- crates/ty_python_core/src/builder.rs | 20 +- crates/ty_python_core/src/place.rs | 17 +- crates/ty_python_semantic/src/types.rs | 8 +- .../src/types/call/arguments.rs | 2 +- .../src/types/class/dynamic_literal.rs | 7 +- .../src/types/class/named_tuple.rs | 5 +- .../src/types/class/static_literal.rs | 8 +- .../src/types/dedicated/pydantic.rs | 11 +- .../src/types/dedicated/pytest/fixtures.rs | 3 +- .../src/types/diagnostic.rs | 17 +- .../src/types/ide_support.rs | 2 +- .../src/types/infer/builder.rs | 155 +- .../src/types/infer/builder/class.rs | 3 +- .../src/types/infer/builder/dict.rs | 16 +- .../src/types/infer/builder/dynamic_class.rs | 2 +- .../src/types/infer/builder/enum_call.rs | 38 +- .../src/types/infer/builder/function.rs | 2 +- .../src/types/infer/builder/named_tuple.rs | 115 +- .../src/types/infer/builder/new_class.rs | 37 +- .../builder/post_inference/dynamic_class.rs | 2 +- .../builder/post_inference/static_class.rs | 32 +- .../suspicious_conditions/diagnostic.rs | 6 +- .../src/types/infer/builder/type_call.rs | 51 +- .../src/types/infer/builder/type_form.rs | 7 +- .../src/types/infer/builder/typed_dict.rs | 114 +- .../src/types/infer/builder/typeguard.rs | 4 +- .../src/types/infer/builder/typevar.rs | 110 +- .../src/types/infer/expression_truthiness.rs | 9 +- crates/ty_python_semantic/src/types/narrow.rs | 46 +- .../ty_python_semantic/src/types/newtype.rs | 2 +- .../src/types/type_alias.rs | 4 +- .../src/types/typed_dict.rs | 55 +- .../ty_python_semantic/src/types/typevar.rs | 3 +- 368 files changed, 7688 insertions(+), 7539 deletions(-) create mode 100644 crates/ruff_python_ast_integration_tests/tests/snapshots/source_order__interleaved_call_arguments.snap create mode 100644 crates/ruff_python_ast_integration_tests/tests/snapshots/visitor__interleaved_call_arguments.snap diff --git a/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py b/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py index 51eae16737..692f46e686 100644 --- a/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py +++ b/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py @@ -16,6 +16,7 @@ print("foo", "", sep="") print("foo", "", "bar", sep="") print("", *args) print("", *args, sep="") +print("", end="!", *args, sep="") print("", **kwargs) print(sep="\t") print(sep=print(1)) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF061_raises.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF061_raises.py index d4e3d900cd..277022f5a5 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF061_raises.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF061_raises.py @@ -31,6 +31,10 @@ def test_error_kwargs(): pytest.raises(func=func, expected_exception=ZeroDivisionError) +def test_error_mixed_argument_order(args): + pytest.raises(ZeroDivisionError, func, b=0, *args) + + def test_error_multi_statement(): excinfo = pytest.raises(ValueError, int, "hello") assert excinfo.match("^invalid literal") diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index bdb435b214..98ef625598 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Operator}; +use ruff_python_ast::{self as ast, Expr, ExprContext, Operator}; use ruff_python_literal::cformat::{CFormatError, CFormatErrorType}; use ruff_python_ast::types::Node; @@ -535,13 +535,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { Expr::Call( call @ ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }, @@ -611,21 +605,21 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { .is_rule_enabled(Rule::StringDotFormatExtraNamedArguments) { pyflakes::rules::string_dot_format_extra_named_arguments( - checker, call, &summary, keywords, + checker, call, &summary, ); } if checker.is_rule_enabled( Rule::StringDotFormatExtraPositionalArguments, ) { pyflakes::rules::string_dot_format_extra_positional_arguments( - checker, call, &summary, args, + checker, call, &summary, ); } if checker .is_rule_enabled(Rule::StringDotFormatMissingArguments) { pyflakes::rules::string_dot_format_missing_argument( - checker, call, &summary, args, keywords, + checker, call, &summary, ); } if checker.is_rule_enabled(Rule::StringDotFormatMixingAutomatic) @@ -664,7 +658,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { refurb::rules::bit_count(checker, call); } if checker.is_rule_enabled(Rule::TypeOfPrimitive) { - pyupgrade::rules::type_of_primitive(checker, expr, func, args); + pyupgrade::rules::type_of_primitive(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::DeprecatedUnittestAlias) { pyupgrade::rules::deprecated_unittest_alias(checker, func); @@ -690,7 +684,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::NonPEP604Isinstance) { if checker.target_version() >= PythonVersion::PY310 { - pyupgrade::rules::use_pep604_isinstance(checker, expr, func, args); + pyupgrade::rules::use_pep604_isinstance(checker, expr, func, arguments); } } if checker.is_rule_enabled(Rule::BlockingHttpCallInAsyncFunction) { @@ -750,28 +744,24 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { flake8_bandit::rules::suspicious_function_call(checker, call); } if checker.is_rule_enabled(Rule::UnreliableCallableCheck) { - flake8_bugbear::rules::unreliable_callable_check( - checker, expr, func, args, keywords, - ); + flake8_bugbear::rules::unreliable_callable_check(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::StripWithMultiCharacters) { - flake8_bugbear::rules::strip_with_multi_characters(checker, expr, func, args); + flake8_bugbear::rules::strip_with_multi_characters(checker, expr, func, arguments); } - if keywords.is_empty() { + if arguments.keywords().next().is_none() { if checker.is_rule_enabled(Rule::GetattrWithConstant) { - flake8_bugbear::rules::getattr_with_constant(checker, expr, func, args); + flake8_bugbear::rules::getattr_with_constant(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::DelattrWithConstant) { - flake8_bugbear::rules::delattr_with_constant(checker, expr, func, args); + flake8_bugbear::rules::delattr_with_constant(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::SetattrWithConstant) { - flake8_bugbear::rules::setattr_with_constant(checker, expr, func, args); + flake8_bugbear::rules::setattr_with_constant(checker, expr, func, arguments); } } if checker.is_rule_enabled(Rule::StarArgAfterKeyword) { - flake8_bugbear::rules::star_arg_unpacking_after_keyword_arg( - checker, args, keywords, - ); + flake8_bugbear::rules::star_arg_unpacking_after_keyword_arg(checker, arguments); } if checker.is_rule_enabled(Rule::ZipWithoutExplicitStrict) { if checker.target_version() >= PythonVersion::PY310 { @@ -796,7 +786,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { flake8_bandit::rules::exec_used(checker, func); } if checker.is_rule_enabled(Rule::HardcodedPasswordFuncArg) { - flake8_bandit::rules::hardcoded_password_func_arg(checker, keywords); + flake8_bandit::rules::hardcoded_password_func_arg(checker, arguments); } if checker.is_rule_enabled(Rule::HardcodedSQLExpression) { flake8_bandit::rules::hardcoded_sql_expression(checker, expr); @@ -847,7 +837,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::UnnecessaryGeneratorDict) { flake8_comprehensions::rules::unnecessary_generator_dict( - checker, expr, func, args, keywords, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::UnnecessaryListComprehensionSet) { @@ -855,7 +845,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::UnnecessaryListComprehensionDict) { flake8_comprehensions::rules::unnecessary_list_comprehension_dict( - checker, expr, func, args, keywords, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::UnnecessaryLiteralSet) { @@ -863,7 +853,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::UnnecessaryLiteralDict) { flake8_comprehensions::rules::unnecessary_literal_dict( - checker, expr, func, args, keywords, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::UnnecessaryCollectionCall) { @@ -887,12 +877,12 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::UnnecessaryCallAroundSorted) { flake8_comprehensions::rules::unnecessary_call_around_sorted( - checker, expr, func, args, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::UnnecessaryDoubleCastOrProcess) { flake8_comprehensions::rules::unnecessary_double_cast_or_process( - checker, expr, func, args, keywords, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::UnnecessarySubscriptReversal) { @@ -903,7 +893,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } if checker.is_rule_enabled(Rule::UnnecessaryComprehensionInCall) { flake8_comprehensions::rules::unnecessary_comprehension_in_call( - checker, expr, func, args, keywords, + checker, expr, func, arguments, ); } if checker.is_rule_enabled(Rule::BooleanPositionalValueInCall) { @@ -932,7 +922,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { pylint::rules::shallow_copy_environ(checker, call); } if checker.is_rule_enabled(Rule::NestedMinMax) { - pylint::rules::nested_min_max(checker, expr, func, args, keywords); + pylint::rules::nested_min_max(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::RepeatedKeywordArgument) { pylint::rules::repeated_keyword_argument(checker, call); @@ -944,7 +934,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { ruff::rules::shared_clock_mock(checker, call); } if checker.is_rule_enabled(Rule::PytestUnittestAssertion) { - flake8_pytest_style::rules::unittest_assertion(checker, expr, func, args, keywords); + flake8_pytest_style::rules::unittest_assertion(checker, expr, func, arguments); } if checker.is_rule_enabled(Rule::PytestUnittestRaisesAssertion) { flake8_pytest_style::rules::unittest_raises_assertion_call(checker, call); @@ -973,13 +963,13 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { &checker.settings().flake8_gettext.function_names, ) { if checker.is_rule_enabled(Rule::FStringInGettextCall) { - flake8_gettext::rules::f_string_in_gettext_func_call(checker, func, args); + flake8_gettext::rules::f_string_in_gettext_func_call(checker, func, arguments); } if checker.is_rule_enabled(Rule::FormatInGettextCall) { - flake8_gettext::rules::format_in_gettext_func_call(checker, func, args); + flake8_gettext::rules::format_in_gettext_func_call(checker, func, arguments); } if checker.is_rule_enabled(Rule::PrintfInGettextCall) { - flake8_gettext::rules::printf_in_gettext_func_call(checker, func, args); + flake8_gettext::rules::printf_in_gettext_func_call(checker, func, arguments); } } if checker.is_rule_enabled(Rule::UncapitalizedEnvironmentVariables) { diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 93c0a6ccde..1a1dfa6a43 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1511,10 +1511,10 @@ impl<'a> Visitor<'a> for Checker<'a> { if let Some(arguments) = arguments { self.semantic.flags |= SemanticModelFlags::CLASS_BASE; - for base in &*arguments.args { + for base in arguments.args() { self.visit_expr(base); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { if keyword.arg.as_ref().is_some_and(|arg| arg == "extra_items") && self.is_typed_dict(class_def) { @@ -2002,7 +2002,7 @@ impl<'a> Visitor<'a> for Checker<'a> { }); match callable { Some(typing::Callable::Bool) => { - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { self.visit_boolean_test(arg); } @@ -2028,14 +2028,14 @@ impl<'a> Visitor<'a> for Checker<'a> { } } Some(typing::Callable::TypeForm) => { - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { self.visit_type_definition(arg); } for arg in args { self.visit_non_type_definition(arg); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { self.visit_non_type_definition(&keyword.value); } } @@ -2057,14 +2057,14 @@ impl<'a> Visitor<'a> for Checker<'a> { } } Some(typing::Callable::TypeVar) => { - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { self.visit_non_type_definition(arg); } for arg in args { self.visit_type_definition(arg); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { arg, value, @@ -2103,7 +2103,7 @@ impl<'a> Visitor<'a> for Checker<'a> { } Some(typing::Callable::NamedTuple) => { // Ex) NamedTuple("a", [("a", int)]) - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { self.visit_non_type_definition(arg); } @@ -2132,9 +2132,9 @@ impl<'a> Visitor<'a> for Checker<'a> { } } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { arg, value, .. } = keyword; - match (arg.as_ref(), value) { + match (arg.as_ref(), value.as_ref()) { // Ex) NamedTuple("a", **{"a": int}) (None, Expr::Dict(dict)) => { for ast::DictItem { key, value } in dict { @@ -2159,7 +2159,7 @@ impl<'a> Visitor<'a> for Checker<'a> { } Some(typing::Callable::TypedDict) => { // Ex) TypedDict("a", {"a": int}) - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { self.visit_non_type_definition(arg); } @@ -2191,10 +2191,15 @@ impl<'a> Visitor<'a> for Checker<'a> { // >>> TypedDict("a", None, closed=int).__required_keys__ // frozenset({'closed'}) // ``` - let legacy_fields = self.target_version() < PythonVersion::PY313 - && matches!(&*arguments.args, [_] | [_, Expr::NoneLiteral(_)]); + let legacy_fields = self.target_version() < PythonVersion::PY313 && { + let mut args = arguments.args(); + matches!( + (args.next(), args.next(), args.next()), + (Some(_), None, _) | (Some(_), Some(Expr::NoneLiteral(_)), None) + ) + }; - for Keyword { arg, value, .. } in &*arguments.keywords { + for Keyword { arg, value, .. } in arguments.keywords() { let is_type = match arg.as_deref() { // `total` is a boolean argument available since `TypedDict` was // introduced. @@ -2219,7 +2224,7 @@ impl<'a> Visitor<'a> for Checker<'a> { } } Some(typing::Callable::MypyExtension) => { - let mut args = arguments.args.iter(); + let mut args = arguments.args(); if let Some(arg) = args.next() { // Ex) DefaultNamedArg(bool | None, name="some_prop_name") self.visit_type_definition(arg); @@ -2227,13 +2232,13 @@ impl<'a> Visitor<'a> for Checker<'a> { for arg in args { self.visit_non_type_definition(arg); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { value, .. } = keyword; self.visit_non_type_definition(value); } } else { // Ex) DefaultNamedArg(type="bool", name="some_prop_name") - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { value, arg, @@ -2252,10 +2257,10 @@ impl<'a> Visitor<'a> for Checker<'a> { // If we're in a type definition, we need to treat the arguments to any // other callables as non-type definitions (i.e., we don't want to treat // any strings as deferred type definitions). - for arg in &*arguments.args { + for arg in arguments.args() { self.visit_non_type_definition(arg); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { value, .. } = keyword; self.visit_non_type_definition(value); } @@ -3082,7 +3087,7 @@ impl<'a> Checker<'a> { self.semantic.flags |= SemanticModelFlags::DEFERRED_CLASS_BASE; // A forward base may only now identify this class as a `TypedDict`. if let Stmt::ClassDef(class_def) = self.semantic.current_statement() - && class_def.keywords().iter().any(|keyword| { + && class_def.keywords().any(|keyword| { keyword.arg.as_ref().is_some_and(|arg| arg == "extra_items") && keyword.value.range() == expr.range() }) diff --git a/crates/ruff_linter/src/fix/edits.rs b/crates/ruff_linter/src/fix/edits.rs index be3cee33dc..782862d455 100644 --- a/crates/ruff_linter/src/fix/edits.rs +++ b/crates/ruff_linter/src/fix/edits.rs @@ -276,7 +276,7 @@ pub(crate) fn remove_argument( /// The new argument will be inserted before the first existing keyword argument in `arguments`, if /// there are any present. Otherwise, the new argument is added to the end of the argument list. pub(crate) fn add_argument(argument: &str, arguments: &Arguments, tokens: &Tokens) -> Edit { - if let Some(keyword) = arguments.keywords.first() { + if let Some(keyword) = arguments.keywords().next() { // The keyword's range starts at its name, even if its value is parenthesized. Edit::insertion(format!("{argument}, "), keyword.start()) } else if let Some(last) = arguments.iter_source_order().last() { diff --git a/crates/ruff_linter/src/rules/airflow/rules/function_signature_change_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/function_signature_change_in_3.rs index 3a88c64f8a..bb360a7005 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/function_signature_change_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/function_signature_change_in_3.rs @@ -162,7 +162,7 @@ fn check_method_arguments( arguments: &Arguments, ) { let has_positional_args = - arguments.find_positional(0).is_some() || arguments.args.iter().any(Expr::is_starred_expr); + arguments.find_positional(0).is_some() || arguments.args().any(Expr::is_starred_expr); if let ["airflow", "lineage", "hook", "HookLineageCollector"] = qualified_name.segments() { if attr.as_str() == "create_asset" && has_positional_args { diff --git a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs index baccbd1b4a..1bcca22eee 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs @@ -1122,7 +1122,7 @@ fn check_airflow_plugin_extension( class_def: &StmtClassDef, ) { if matches!(name, "executors" | "operators" | "sensors" | "hooks") { - if class_def.bases().iter().any(|class_base| { + if class_def.bases().any(|class_base| { checker.semantic().matches_qualified_name( class_base, &["airflow", "plugins_manager", "AirflowPlugin"], diff --git a/crates/ruff_linter/src/rules/airflow/rules/runtime_value_in_dag_or_task.rs b/crates/ruff_linter/src/rules/airflow/rules/runtime_value_in_dag_or_task.rs index 26f2207572..ca1064992a 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/runtime_value_in_dag_or_task.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/runtime_value_in_dag_or_task.rs @@ -69,7 +69,7 @@ pub(crate) fn airflow_3_dag_dynamic_value(checker: &Checker, call: &ExprCall) { return; } - for keyword in &call.arguments.keywords { + for keyword in call.arguments.keywords() { if let Some((expr, name)) = find_runtime_varying_call(&keyword.value, checker.semantic()) { checker.report_diagnostic( Airflow3DagDynamicValue { @@ -135,14 +135,12 @@ fn find_runtime_varying_call<'a>( find_runtime_varying_call(func, semantic) .or_else(|| { arguments - .args - .iter() + .args() .find_map(|arg| find_runtime_varying_call(arg, semantic)) }) .or_else(|| { arguments - .keywords - .iter() + .keywords() .find_map(|kw| find_runtime_varying_call(&kw.value, semantic)) }) } diff --git a/crates/ruff_linter/src/rules/airflow/rules/task_branch_as_short_circuit.rs b/crates/ruff_linter/src/rules/airflow/rules/task_branch_as_short_circuit.rs index c0fe9f391a..8075b65005 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/task_branch_as_short_circuit.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/task_branch_as_short_circuit.rs @@ -151,7 +151,7 @@ pub(crate) fn branch_python_operator_as_short_circuit(checker: &Checker, call: & return; }; - let Expr::Name(name_expr) = &keyword.value else { + let Expr::Name(name_expr) = keyword.value.as_ref() else { return; }; diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs index 708edbfb6a..7fe20bd7c6 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs @@ -180,8 +180,7 @@ impl<'a> DependencyCall<'a> { let default_argument = call.arguments.find_argument("default", 0)?; let keyword_arguments = call .arguments - .keywords - .iter() + .keywords() .filter(|kwarg| kwarg.arg.as_ref().is_some_and(|name| name != "default")) .collect(); diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs index 73809fc258..ac5377ee98 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs @@ -126,7 +126,7 @@ pub(crate) fn fastapi_unused_path_parameter( return; }; - let Some(path_arg) = route_decorator.arguments.args.first() else { + let Some(path_arg) = route_decorator.arguments.args().next() else { return; }; let diagnostic_range = path_arg.range(); @@ -388,7 +388,6 @@ impl<'a> Dependency<'a> { let parameter_names = if class_def .bases() - .iter() .any(|expr| is_pydantic_base_model(expr, semantic)) { class_def @@ -468,7 +467,7 @@ fn parameter_alias<'a>(parameter: &'a Parameter, semantic: &SemanticModel) -> Op .map(|alias| &alias.value)?; // Ensure that it's a literal string. - let Expr::StringLiteral(alias) = alias else { + let Expr::StringLiteral(alias) = alias.as_ref() else { return None; }; diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/pytest_raises_exception_group.rs b/crates/ruff_linter/src/rules/flake8_async/rules/pytest_raises_exception_group.rs index cd56a3a1db..de758f0b54 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/pytest_raises_exception_group.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/pytest_raises_exception_group.rs @@ -94,14 +94,14 @@ pub(crate) fn pytest_raises_exception_group(checker: &Checker, call: &ExprCall) false, ), ["pytest", "RaisesExc"] => ( - call.arguments.args.first().filter(is_exception_group), + call.arguments.args().next().filter(is_exception_group), false, ), - ["pytest", "RaisesGroup"] => (call.arguments.args.iter().find(is_exception_group), true), + ["pytest", "RaisesGroup"] => (call.arguments.args().find(is_exception_group), true), ["pytest", "mark", "xfail"] => ( call.arguments .find_keyword("raises") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) .filter(is_exception_group), false, ), diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs index 7021fdb5d8..edbde15b38 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs @@ -1,6 +1,5 @@ -use ruff_python_ast::Keyword; - use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::Arguments; use ruff_text_size::Ranged; use crate::Violation; @@ -53,8 +52,8 @@ impl Violation for HardcodedPasswordFuncArg { } /// S106 -pub(crate) fn hardcoded_password_func_arg(checker: &Checker, keywords: &[Keyword]) { - for keyword in keywords { +pub(crate) fn hardcoded_password_func_arg(checker: &Checker, arguments: &Arguments) { + for keyword in arguments.keywords() { if string_literal(&keyword.value).is_none_or(str::is_empty) { continue; } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs index f88a2e7d8b..d786cdc301 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs @@ -66,7 +66,7 @@ pub(crate) fn jinja2_autoescape_false( ) { if matches!(qualified_name.segments(), ["jinja2", "Environment"]) { if let Some(keyword) = call.arguments.find_keyword("autoescape") { - match &keyword.value { + match keyword.value.as_ref() { Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: true, .. }) => (), Expr::Call(ast::ExprCall { func, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs index 1833ce0e5c..f0272d5a3d 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs @@ -335,7 +335,7 @@ pub(crate) fn shell_injection(checker: &Checker, call: &ast::ExprCall) { let shell_keyword = find_shell_keyword(&call.arguments, checker.semantic()); let command_argument = match call_kind { Some(CallKind::Subprocess) => find_subprocess_argument(&call.arguments), - Some(CallKind::Shell | CallKind::NoShell) => call.arguments.args.first(), + Some(CallKind::Shell | CallKind::NoShell) => call.arguments.args().next(), None => None, }; @@ -381,7 +381,7 @@ pub(crate) fn shell_injection(checker: &Checker, call: &ast::ExprCall) { // S605 if checker.is_rule_enabled(Rule::StartProcessWithAShell) { if matches!(call_kind, Some(CallKind::Shell)) { - if let Some(arg) = call.arguments.args.first() { + if let Some(arg) = call.arguments.args().next() { checker.report_diagnostic( StartProcessWithAShell { safety: Safety::from(arg), @@ -436,8 +436,8 @@ fn find_subprocess_argument(arguments: &Arguments) -> Option<&Expr> { // A starred first argument (`subprocess.run(*cmd)`) prevents us from locating the // command with `find_argument_value`; treat it as untrusted input. arguments - .args - .first() + .args() + .next() .filter(|argument| argument.is_starred_expr()) }) } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs index 5a515ca60a..02d843d3a5 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs @@ -55,7 +55,7 @@ pub(crate) fn snmp_insecure_version( ) { if let Some(keyword) = call.arguments.find_keyword("mpModel") { if matches!( - keyword.value, + keyword.value.as_ref(), Expr::NumberLiteral(ast::ExprNumberLiteral { value: ast::Number::Int(Int::ZERO | Int::ONE), .. diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs index dc1a078651..efc8e51474 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs @@ -66,7 +66,7 @@ pub(crate) fn ssl_insecure_version( return; }; - match &keyword.value { + match keyword.value.as_ref() { Expr::Name(ast::ExprName { id, .. }) if is_insecure_protocol(id) => { checker.report_diagnostic( SslInsecureVersion { diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs index bc3005764c..18b20eb1b7 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs @@ -2,6 +2,7 @@ //! //! See: use itertools::Either; +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Arguments, Decorator, Expr, ExprCall, Operator}; use ruff_python_semantic::SemanticModel; @@ -1163,7 +1164,7 @@ fn suspicious_function( // MarkSafe ["django", "utils", "safestring" | "html", "mark_safe"] => { if let Some(arguments) = arguments { - if let [single] = &*arguments.args { + if let Some([single]) = arguments.args().collect_array() { if single.is_string_literal_expr() { return; } @@ -1176,11 +1177,8 @@ fn suspicious_function( ["urllib", "request", "Request"] | ["six", "moves", "urllib", "request", "Request"] => { if let Some(arguments) = arguments { // If the `url` argument is a string literal (including resolved bindings), allow `http` and `https` schemes. - if arguments.args.iter().all(|arg| !arg.is_starred_expr()) - && arguments - .keywords - .iter() - .all(|keyword| keyword.arg.is_some()) + if arguments.args().all(|arg| !arg.is_starred_expr()) + && arguments.keywords().all(|keyword| keyword.arg.is_some()) { if let Some(url_expr) = arguments.find_argument_value("url", 0) && expression_starts_with_http_prefix(url_expr, checker.semantic()) @@ -1202,11 +1200,8 @@ fn suspicious_function( "urlopen" | "urlretrieve", ] => { if let Some(arguments) = arguments { - if arguments.args.iter().all(|arg| !arg.is_starred_expr()) - && arguments - .keywords - .iter() - .all(|keyword| keyword.arg.is_some()) + if arguments.args().all(|arg| !arg.is_starred_expr()) + && arguments.keywords().all(|keyword| keyword.arg.is_some()) { match arguments.find_argument_value("url", 0) { // If the `url` argument is a `urllib.request.Request` object, allow `http` and `https` schemes. diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs index 45604e6fdd..e9561b5d2e 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_python_ast::{Expr, ExprCall}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -141,7 +142,7 @@ fn is_unsafe_call(call: &ExprCall, semantic: &SemanticModel, settings: &LinterSe // unlikely that someone will actually use a keyword argument here // TODO: Eventually we may want to allow dynamic values, as long as they // have a __html__ attribute, since that is part of the API - matches!(&*call.arguments.args, [first] if !first.is_string_literal_expr() && !first.is_bytes_literal_expr() && !is_whitelisted_call(first, semantic, settings)) + matches!(call.arguments.args().collect_array(), Some([first]) if !first.is_string_literal_expr() && !first.is_bytes_literal_expr() && !is_whitelisted_call(first, semantic, settings)) } fn is_whitelisted_call(expr: &Expr, semantic: &SemanticModel, settings: &LinterSettings) -> bool { diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs index 02a86d83ad..ba569d7c43 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs @@ -142,7 +142,7 @@ pub(super) fn allow_boolean_trap(call: &ast::ExprCall, checker: &Checker) -> boo // If the function appears to be a setter (e.g., `set_visible` or `setVisible`), then the // boolean trap is allowed. We want to avoid raising a violation for cases in which the argument // is positional-only and third-party, and this tends to be the case for setters. - if call.arguments.args.len() == 1 { + if call.arguments.args().count() == 1 { // Ex) `foo.set(True)` if func_name == "set" { return true; diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs index 91c8dc1a1f..c02244d549 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs @@ -60,8 +60,7 @@ pub(crate) fn boolean_positional_value_in_call(checker: &Checker, call: &ast::Ex } for arg in call .arguments - .args - .iter() + .args() .filter(|arg| arg.is_boolean_literal_expr()) { checker.report_diagnostic(BooleanPositionalValueInCall, arg.range()); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/helpers.rs b/crates/ruff_linter/src/rules/flake8_bugbear/helpers.rs index 090658de7d..a55acdd81d 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/helpers.rs @@ -1,10 +1,11 @@ +use itertools::Itertools; use ruff_notebook::CellOffsets; use ruff_python_semantic::SemanticModel; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextRange}; use crate::Locator; -use ruff_python_ast::{self as ast, Arguments, Expr}; +use ruff_python_ast::{self as ast, Expr}; /// Return `true` if the statement containing the current expression is the last /// top-level expression in the cell. This assumes that the source is a Jupyter @@ -33,9 +34,7 @@ pub(super) fn at_last_top_level_expression_in_cell( /// `itertools.cycle` or similar). pub(crate) fn is_infinite_iterable(arg: &Expr, semantic: &SemanticModel) -> bool { let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, keywords, .. }, - .. + func, arguments, .. }) = &arg else { return false; @@ -47,17 +46,20 @@ pub(crate) fn is_infinite_iterable(arg: &Expr, semantic: &SemanticModel) -> bool ["itertools", "cycle" | "count"] => true, ["itertools", "repeat"] => { // Ex) `itertools.repeat(1)` - if keywords.is_empty() && args.len() == 1 { + if matches!(arguments.items.as_slice(), [ast::Argument::Positional(_)]) { return true; } // Ex) `itertools.repeat(1, None)` - if args.len() == 2 && args[1].is_none_literal_expr() { + if matches!( + arguments.args().collect_array(), + Some([_, Expr::NoneLiteral(_)]) + ) { return true; } // Ex) `itertools.repeat(1, times=None)` - for keyword in keywords { + for keyword in arguments.keywords() { if keyword.arg.as_ref().is_some_and(|name| name == "times") && keyword.value.is_none_literal_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs index 35b069096c..d01db5acaa 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{self as ast, Arguments, Expr, Keyword, Stmt}; +use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::identifier::Identifier; @@ -116,12 +116,12 @@ impl Violation for EmptyMethodWithoutAbstractDecorator { } } -fn is_abc_class(bases: &[Expr], keywords: &[Keyword], semantic: &SemanticModel) -> bool { - keywords.iter().any(|keyword| { +fn is_abc_class(arguments: &Arguments, semantic: &SemanticModel) -> bool { + arguments.keywords().any(|keyword| { keyword.arg.as_ref().is_some_and(|arg| arg == "metaclass") && semantic.matches_qualified_name(&keyword.value, &["abc", "ABCMeta"]) - }) || bases - .iter() + }) || arguments + .args() .any(|base| semantic.matches_qualified_name(base, &["abc", "ABC"])) } @@ -151,14 +151,14 @@ pub(crate) fn abstract_base_class( arguments: Option<&Arguments>, body: &[Stmt], ) { - let Some(Arguments { args, keywords, .. }) = arguments else { + let Some(arguments) = arguments else { return; }; - if args.len() + keywords.len() != 1 { + if arguments.len() != 1 { return; } - if !is_abc_class(args, keywords, checker.semantic()) { + if !is_abc_class(arguments, checker.semantic()) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs index 98a7321084..531c6392fe 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs @@ -63,12 +63,11 @@ fn assertion_error(msg: Option<&Expr>) -> Stmt { node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), arguments: Arguments { - args: if let Some(msg) = msg { - [msg.clone()].into() - } else { - [].into() - }, - keywords: std::iter::empty().collect(), + items: msg + .cloned() + .into_iter() + .map(ast::Argument::Positional) + .collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs index c635f0480f..8d301b49e9 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs @@ -138,7 +138,7 @@ pub(crate) fn assert_raises_exception_call(checker: &Checker, call: &ast::ExprCa } = call; let semantic = checker.semantic(); - if arguments.args.len() < 2 && arguments.find_keyword("func").is_none() { + if arguments.args().nth(1).is_none() && arguments.find_argument("func", 1).is_none() { return; } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/delattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/delattr_with_constant.rs index b792ee7964..ebe86fe878 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/delattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/delattr_with_constant.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_python_ast::{self as ast, Expr, ExprContext, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; @@ -62,15 +63,22 @@ impl AlwaysFixableViolation for DelattrWithConstant { } /// B043 -pub(crate) fn delattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { +pub(crate) fn delattr_with_constant( + checker: &Checker, + expr: &Expr, + func: &Expr, + arguments: &ast::Arguments, +) { if !checker.semantic().match_builtin_expr(func, "delattr") { return; } - let [ - obj, - Expr::StringLiteral(ast::ExprStringLiteral { value: name, .. }), - ] = args + let Some( + [ + obj, + Expr::StringLiteral(ast::ExprStringLiteral { value: name, .. }), + ], + ) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs index 25e798a4a4..06b5c78e10 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs @@ -140,7 +140,7 @@ impl<'a> Visitor<'a> for SuspiciousVariablesVisitor<'a> { match func.as_ref() { Expr::Name(ast::ExprName { id, .. }) => { if matches!(id.as_str(), "filter" | "reduce" | "map") { - for arg in &*arguments.args { + for arg in arguments.args() { if arg.is_lambda_expr() { self.safe_functions.push(arg); } @@ -150,7 +150,7 @@ impl<'a> Visitor<'a> for SuspiciousVariablesVisitor<'a> { Expr::Attribute(ast::ExprAttribute { value, attr, .. }) if attr == "reduce" => { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { if id == "functools" { - for arg in &*arguments.args { + for arg in arguments.args() { if arg.is_lambda_expr() { self.safe_functions.push(arg); } @@ -161,7 +161,7 @@ impl<'a> Visitor<'a> for SuspiciousVariablesVisitor<'a> { _ => {} } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { if keyword.arg.as_ref().is_some_and(|arg| arg == "key") && keyword.value.is_lambda_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index 8b4d314fa3..b99d7f6117 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; @@ -69,8 +70,13 @@ impl AlwaysFixableViolation for GetattrWithConstant { } /// B009 -pub(crate) fn getattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - let [obj, arg] = args else { +pub(crate) fn getattr_with_constant( + checker: &Checker, + expr: &Expr, + func: &Expr, + arguments: &ast::Arguments, +) { + let Some([obj, arg]) = arguments.args().collect_array() else { return; }; if obj.is_starred_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs index 84b6e95119..d7d8504261 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs @@ -77,7 +77,7 @@ pub(crate) fn loop_iterator_mutation(checker: &Checker, stmt_for: &StmtFor) { func, arguments, .. }) if checker.semantic().match_builtin_expr(func, "enumerate") => { // Ex) `items` - let Some(iter) = arguments.args.first() else { + let Some(iter) = arguments.args().next() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/map_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/map_without_explicit_strict.rs index 216cda0c2f..6d9f35953b 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/map_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/map_without_explicit_strict.rs @@ -69,10 +69,10 @@ pub(crate) fn map_without_explicit_strict(checker: &Checker, call: &ast::ExprCal && call.arguments.find_keyword("strict").is_none() && ( // at least 2 iterables (+ 1 function), or a starred argument. - call.arguments.args.len() >= 3 - || call.arguments.args.iter().any(ast::Expr::is_starred_expr) + call.arguments.args().nth(2).is_some() + || call.arguments.args().any(ast::Expr::is_starred_expr) ) - && !any_infinite_iterables(call.arguments.args.iter().skip(1), semantic) + && !any_infinite_iterables(call.arguments.args().skip(1), semantic) { checker .report_diagnostic(MapWithoutExplicitStrict, call.range()) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs index 389e4965e6..2dd4d7d370 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs @@ -78,7 +78,7 @@ pub(crate) fn mutable_contextvar_default(checker: &Checker, call: &ast::ExprCall let Some(default) = call .arguments .find_keyword("default") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs index 22f768ca94..4a55d6481c 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs @@ -86,13 +86,11 @@ pub(crate) fn no_explicit_stacklevel( || is_skip_file_prefixes_param_set(&call.arguments) || call .arguments - .args - .iter() + .args() .any(ruff_python_ast::Expr::is_starred_expr) || call .arguments - .keywords - .iter() + .keywords() .any(|keyword| keyword.arg.is_none()) { return; @@ -109,7 +107,7 @@ pub(crate) fn no_explicit_stacklevel( fn is_skip_file_prefixes_param_set(arguments: &ast::Arguments) -> bool { arguments .find_keyword("skip_file_prefixes") - .is_some_and(|keyword| match &keyword.value { + .is_some_and(|keyword| match keyword.value.as_ref() { Expr::Tuple(tuple) => !tuple.elts.is_empty(), _ => true, }) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs index 63706d2943..f993afb197 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs @@ -75,7 +75,7 @@ pub(crate) fn re_sub_positional_args( _ => return, }; - if call.arguments.args.len() > method.num_args() { + if call.arguments.args().nth(method.num_args()).is_some() { checker.report_diagnostic(ReSubPositionalArgs { method }, call.range()); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index d6f286b0c8..f10f45593e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_python_ast::{self as ast, Expr, ExprContext, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; @@ -92,8 +93,13 @@ fn assignment(obj: &Expr, name: &str, value: &Expr, generator: Generator) -> Str } /// B010 -pub(crate) fn setattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - let [obj, name, value] = args else { +pub(crate) fn setattr_with_constant( + checker: &Checker, + expr: &Expr, + func: &Expr, + arguments: &ast::Arguments, +) { + let Some([obj, name, value]) = arguments.args().collect_array() else { return; }; if obj.is_starred_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs index 271a6954a6..86e0d348f3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{Expr, Keyword}; +use ruff_python_ast::{Argument, Arguments, Expr}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_text_size::Ranged; @@ -58,21 +58,13 @@ impl Violation for StarArgAfterKeyword { } /// B026 -pub(crate) fn star_arg_unpacking_after_keyword_arg( - checker: &Checker, - args: &[Expr], - keywords: &[Keyword], -) { - let Some(keyword) = keywords.first() else { - return; - }; - for arg in args { - let Expr::Starred(_) = arg else { - continue; - }; - if arg.start() <= keyword.start() { - continue; +pub(crate) fn star_arg_unpacking_after_keyword_arg(checker: &Checker, arguments: &Arguments) { + let mut items = arguments.items.iter(); + if items.any(|item| matches!(item, Argument::Keyword(_))) { + for item in items { + if let Argument::Positional(Expr::Starred(starred)) = item { + checker.report_diagnostic(StarArgAfterKeyword, starred.range()); + } } - checker.report_diagnostic(StarArgAfterKeyword, arg.range()); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs index d28e268428..86c165e476 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs @@ -78,7 +78,7 @@ pub(crate) fn strip_with_multi_characters( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], + arguments: &ast::Arguments, ) { let Expr::Attribute(ast::ExprAttribute { attr, .. }) = func else { return; @@ -87,7 +87,9 @@ pub(crate) fn strip_with_multi_characters( return; }; - let [Expr::StringLiteral(ast::ExprStringLiteral { value, .. })] = args else { + let Some([Expr::StringLiteral(ast::ExprStringLiteral { value, .. })]) = + arguments.args().collect_array() + else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index e8c4a502fa..e0c83fb0b9 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -91,13 +91,13 @@ pub(crate) fn unreliable_callable_check( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[ast::Keyword], + arguments: &ast::Arguments, ) { - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [obj, attr, ..] = args else { + let mut args = arguments.args(); + let (Some(obj), Some(attr)) = (args.next(), args.next()) else { return; }; let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = attr else { @@ -114,11 +114,11 @@ pub(crate) fn unreliable_callable_check( let valid_args = match builtins_function { "hasattr" => { // hasattr should have exactly 2 positional arguments and no keywords - args.len() == 2 + arguments.len() == 2 } "getattr" => { // getattr should have 2 or 3 positional arguments and no keywords - args.len() == 2 || args.len() == 3 + matches!(arguments.len(), 2 | 3) } _ => return, }; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs index 74577f956a..37668a7eeb 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs @@ -57,7 +57,7 @@ pub(crate) fn useless_contextlib_suppress( call: &ExprCall, qualified_name: &QualifiedName, ) { - if call.arguments.args.is_empty() + if call.arguments.args().next().is_none() && matches!(qualified_name.segments(), ["contextlib", "suppress"]) { checker.report_diagnostic(UselessContextlibSuppress, call.range()); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index 69990d729d..e868062ac1 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -61,9 +61,9 @@ pub(crate) fn zip_without_explicit_strict(checker: &Checker, call: &ast::ExprCal // any call to `zip()` with at least 2 iterables, or a starred argument. if semantic.match_builtin_expr(&call.func, "zip") && call.arguments.find_keyword("strict").is_none() - && (call.arguments.args.len() >= 2 - || call.arguments.args.iter().any(ast::Expr::is_starred_expr)) - && !any_infinite_iterables(call.arguments.args.iter(), semantic) + && (call.arguments.args().nth(1).is_some() + || call.arguments.args().any(ast::Expr::is_starred_expr)) + && !any_infinite_iterables(call.arguments.args(), semantic) { checker .report_diagnostic(ZipWithoutExplicitStrict, call.range()) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/helpers.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/helpers.rs index f22a8dd908..eca5d9ce9e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/helpers.rs @@ -1,17 +1,15 @@ -use ruff_python_ast::{Expr, Keyword}; +use ruff_python_ast::Argument; +use ruff_python_ast::Arguments; +use ruff_python_ast::Expr; pub(super) fn exactly_one_argument_with_matching_function<'a>( name: &str, func: &Expr, - args: &'a [Expr], - keywords: &[Keyword], + arguments: &'a Arguments, ) -> Option<&'a Expr> { - let [arg] = args else { + let [Argument::Positional(arg)] = arguments.items.as_slice() else { return None; }; - if !keywords.is_empty() { - return None; - } let func = func.as_name_expr()?; if func.id != name { return None; @@ -22,10 +20,10 @@ pub(super) fn exactly_one_argument_with_matching_function<'a>( pub(super) fn first_argument_with_matching_function<'a>( name: &str, func: &Expr, - args: &'a [Expr], + arguments: &'a Arguments, ) -> Option<&'a Expr> { if func.as_name_expr().is_some_and(|func| func.id == name) { - args.first() + arguments.args().next() } else { None } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index b2487ef669..b687ba5585 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -66,11 +66,11 @@ pub(crate) fn unnecessary_call_around_sorted( checker: &Checker, expr: &Expr, outer_func: &Expr, - args: &[Expr], + arguments: &ast::Arguments, ) { let Some(Expr::Call(ast::ExprCall { func: inner_func, .. - })) = args.first() + })) = arguments.args().next() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index 7bd83cb339..5ea2c9c778 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -64,7 +64,7 @@ pub(crate) fn unnecessary_collection_call( call: &ast::ExprCall, settings: &Settings, ) { - if !call.arguments.args.is_empty() { + if call.arguments.args().next().is_some() { return; } let Some(builtin) = checker.semantic().resolve_builtin_symbol(&call.func) else { @@ -72,18 +72,18 @@ pub(crate) fn unnecessary_collection_call( }; let collection = match builtin { "dict" - if call.arguments.keywords.is_empty() + if call.arguments.keywords().next().is_none() || (!settings.allow_dict_calls_with_keyword_arguments - && call.arguments.keywords.iter().all(|kw| kw.arg.is_some())) => + && call.arguments.keywords().all(|kw| kw.arg.is_some())) => { // `dict()` or `dict(a=1)` (as opposed to `dict(**a)`) Collection::Dict } - "list" if call.arguments.keywords.is_empty() => { + "list" if call.arguments.keywords().next().is_none() => { // `list() Collection::List } - "tuple" if call.arguments.keywords.is_empty() => { + "tuple" if call.arguments.keywords().next().is_none() => { // `tuple()` Collection::Tuple } @@ -94,7 +94,7 @@ pub(crate) fn unnecessary_collection_call( checker.report_diagnostic(UnnecessaryCollectionCall { kind: collection }, call.range()); // Convert `dict()` to `{}`. - if call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_none() { diagnostic.set_fix({ // Replace from the start of the call to the start of the argument. let call_start = Edit::replacement( diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs index 68169208cd..abf77ea18f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs @@ -1,6 +1,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::helpers::any_over_expr; -use ruff_python_ast::{self as ast, Expr, Keyword}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::{Ranged, TextSize}; use crate::FixAvailability; @@ -94,13 +94,12 @@ pub(crate) fn unnecessary_comprehension_in_call( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[Keyword], + arguments: &ast::Arguments, ) { - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let Some(arg) = args.first() else { + let Some(arg) = arguments.args().next() else { return; }; let (Expr::ListComp(ast::ExprListComp { @@ -154,7 +153,7 @@ pub(crate) fn unnecessary_comprehension_in_call( return; } }; - if args.len() == 1 { + if arguments.args().count() == 1 { // If there's only one argument, remove the list or set brackets. diagnostic.try_set_fix(|| { fixes::fix_unnecessary_comprehension_in_call(expr, checker.locator(), checker.stylist()) diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs index 15cff71ea0..211484f629 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs @@ -208,12 +208,10 @@ fn is_constant_like(expr: &Expr) -> bool { fn fix_unnecessary_dict_comprehension(value: &Expr, generator: &Comprehension) -> Expr { let iterable = generator.iter.clone(); let args = Arguments { - args: if value.is_none_literal_expr() { - [iterable].into() - } else { - [iterable, value.clone()].into() - }, - keywords: std::iter::empty().collect(), + items: std::iter::once(iterable) + .chain((!value.is_none_literal_expr()).then(|| value.clone())) + .map(ast::Argument::Positional) + .collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index d6fb343e1b..7419089323 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -1,6 +1,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::comparable::ComparableKeyword; -use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -73,17 +73,14 @@ pub(crate) fn unnecessary_double_cast_or_process( checker: &Checker, expr: &Expr, outer_func: &Expr, - args: &[Expr], - outer_kw: &[Keyword], + outer_arguments: &ast::Arguments, ) { - let Some(arg) = args.first() else { + let Some(arg) = outer_arguments.args().next() else { return; }; let Expr::Call(ast::ExprCall { func: inner_func, - arguments: Arguments { - keywords: inner_kw, .. - }, + arguments, .. }) = arg else { @@ -106,12 +103,12 @@ pub(crate) fn unnecessary_double_cast_or_process( // Avoid collapsing nested `sorted` calls with non-identical keyword arguments // (i.e., `key`, `reverse`). if inner_func_name == "sorted" && outer_func_name == "sorted" { - if inner_kw.len() != outer_kw.len() { + if arguments.keywords().count() != outer_arguments.keywords().count() { return; } - if !inner_kw.iter().all(|inner| { - outer_kw - .iter() + if !arguments.keywords().all(|inner| { + outer_arguments + .keywords() .any(|outer| ComparableKeyword::from(inner) == ComparableKeyword::from(outer)) }) { return; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index 45f88791e3..c48fd53932 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -1,5 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Expr, Keyword}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -52,11 +52,10 @@ pub(crate) fn unnecessary_generator_dict( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[Keyword], + arguments: &ast::Arguments, ) { let Some(argument) = - helpers::exactly_one_argument_with_matching_function("dict", func, args, keywords) + helpers::exactly_one_argument_with_matching_function("dict", func, arguments) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index edce594d89..c10ddcbedb 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -69,12 +69,9 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorList { /// C400 (`list(generator)`) pub(crate) fn unnecessary_generator_list(checker: &Checker, call: &ast::ExprCall) { - let Some(argument) = helpers::exactly_one_argument_with_matching_function( - "list", - &call.func, - &call.arguments.args, - &call.arguments.keywords, - ) else { + let Some(argument) = + helpers::exactly_one_argument_with_matching_function("list", &call.func, &call.arguments) + else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index 88a55574cc..3c52cd3dac 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -70,12 +70,9 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorSet { /// C401 (`set(generator)`) pub(crate) fn unnecessary_generator_set(checker: &Checker, call: &ast::ExprCall) { - let Some(argument) = helpers::exactly_one_argument_with_matching_function( - "set", - &call.func, - &call.arguments.args, - &call.arguments.keywords, - ) else { + let Some(argument) = + helpers::exactly_one_argument_with_matching_function("set", &call.func, &call.arguments) + else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 099f378f8b..6b8a4e3765 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{Arguments, Expr, ExprCall}; +use ruff_python_ast::{Expr, ExprCall}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_text_size::Ranged; @@ -55,22 +55,16 @@ pub(crate) fn unnecessary_list_call(checker: &Checker, expr: &Expr, call: &ExprC node_index: _, } = call; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - if arguments.args.len() > 1 { + if arguments.args().nth(1).is_some() { return; } - let Arguments { - range: _, - node_index: _, - args, - keywords: _, - } = arguments; - - let Some(argument) = helpers::first_argument_with_matching_function("list", func, args) else { + let Some(argument) = helpers::first_argument_with_matching_function("list", func, arguments) + else { return; }; if !argument.is_list_comp_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index 708d0b871b..4ea4a008bd 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -1,5 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Expr, Keyword}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -49,11 +49,10 @@ pub(crate) fn unnecessary_list_comprehension_dict( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[Keyword], + arguments: &ast::Arguments, ) { let Some(argument) = - helpers::exactly_one_argument_with_matching_function("dict", func, args, keywords) + helpers::exactly_one_argument_with_matching_function("dict", func, arguments) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index ec2b192398..a195933688 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -48,12 +48,9 @@ impl AlwaysFixableViolation for UnnecessaryListComprehensionSet { /// C403 (`set([...])`) pub(crate) fn unnecessary_list_comprehension_set(checker: &Checker, call: &ast::ExprCall) { - let Some(argument) = helpers::exactly_one_argument_with_matching_function( - "set", - &call.func, - &call.arguments.args, - &call.arguments.keywords, - ) else { + let Some(argument) = + helpers::exactly_one_argument_with_matching_function("set", &call.func, &call.arguments) + else { return; }; if !checker.semantic().has_builtin_binding("set") { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index adb894755b..7bc5825ef7 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -1,5 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Expr, Keyword}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -56,11 +56,10 @@ pub(crate) fn unnecessary_literal_dict( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[Keyword], + arguments: &ast::Arguments, ) { let Some(argument) = - helpers::exactly_one_argument_with_matching_function("dict", func, args, keywords) + helpers::exactly_one_argument_with_matching_function("dict", func, arguments) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 26d9f45f87..62583eb6b2 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -54,12 +54,9 @@ impl AlwaysFixableViolation for UnnecessaryLiteralSet { /// C405 (`set([1, 2])`) pub(crate) fn unnecessary_literal_set(checker: &Checker, call: &ast::ExprCall) { - let Some(argument) = helpers::exactly_one_argument_with_matching_function( - "set", - &call.func, - &call.arguments.args, - &call.arguments.keywords, - ) else { + let Some(argument) = + helpers::exactly_one_argument_with_matching_function("set", &call.func, &call.arguments) + else { return; }; let Some(kind) = UnnecessaryLiteral::try_from_expr(argument) else { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index 64e38a2dfa..528f1df193 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -57,14 +57,14 @@ impl Violation for UnnecessaryLiteralWithinDictCall { /// C418 pub(crate) fn unnecessary_literal_within_dict_call(checker: &Checker, call: &ast::ExprCall) { - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - if call.arguments.args.len() > 1 { + if call.arguments.args().nth(1).is_some() { return; } let Some(argument) = - helpers::first_argument_with_matching_function("dict", &call.func, &call.arguments.args) + helpers::first_argument_with_matching_function("dict", &call.func, &call.arguments) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index 6fbc864d56..1d94697b83 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -66,14 +66,14 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinListCall { /// C410 pub(crate) fn unnecessary_literal_within_list_call(checker: &Checker, call: &ast::ExprCall) { - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - if call.arguments.args.len() > 1 { + if call.arguments.args().nth(1).is_some() { return; } let Some(argument) = - helpers::first_argument_with_matching_function("list", &call.func, &call.arguments.args) + helpers::first_argument_with_matching_function("list", &call.func, &call.arguments) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index 16492a5643..74ddcc7a71 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -70,15 +70,12 @@ impl Violation for UnnecessaryLiteralWithinTupleCall { /// C409 pub(crate) fn unnecessary_literal_within_tuple_call(checker: &Checker, call: &ast::ExprCall) { - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - let Some(argument) = helpers::exactly_one_argument_with_matching_function( - "tuple", - &call.func, - &call.arguments.args, - &call.arguments.keywords, - ) else { + let Some(argument) = + helpers::exactly_one_argument_with_matching_function("tuple", &call.func, &call.arguments) + else { return; }; let argument_kind = match argument { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 4d86ac0573..9118ac858d 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -98,7 +98,7 @@ pub(crate) fn unnecessary_map(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let (func, arguments) = (&call.func, &call.arguments); - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } @@ -128,7 +128,7 @@ pub(crate) fn unnecessary_map(checker: &Checker, call: &ast::ExprCall) { } ObjectType::List | ObjectType::Set | ObjectType::Dict => { - let [Expr::Call(inner_call)] = arguments.args.as_ref() else { + let Some([Expr::Call(inner_call)]) = arguments.args().collect_array() else { return; }; @@ -202,18 +202,19 @@ fn is_list_set_or_dict(func: &Expr, semantic: &SemanticModel) -> bool { fn map_lambda_and_iterables<'a>( call: &'a ast::ExprCall, semantic: &'a SemanticModel, -) -> Option<(&'a ExprLambda, &'a [Expr])> { +) -> Option<(&'a ExprLambda, impl Iterator)> { if !semantic.match_builtin_expr(&call.func, "map") { return None; } let arguments = &call.arguments; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - let Some((Expr::Lambda(lambda), iterables)) = arguments.args.split_first() else { + let mut iterables = arguments.args(); + let Some(Expr::Lambda(lambda)) = iterables.next() else { return None; }; diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index db7ff2875f..3c5f079fa9 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -43,7 +43,7 @@ impl Violation for UnnecessarySubscriptReversal { /// C415 pub(crate) fn unnecessary_subscript_reversal(checker: &Checker, call: &ast::ExprCall) { - let Some(first_arg) = call.arguments.args.first() else { + let Some(first_arg) = call.arguments.args().next() else { return; }; let Expr::Subscript(ast::ExprSubscript { slice, .. }) = first_arg else { diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs index 3357b35ab0..34d7a90df4 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs @@ -109,7 +109,7 @@ pub(crate) fn call_datetime_strptime_without_zone( } // Does the `strptime` call contain a format string with a timezone specifier? - if let Some(expr) = call.arguments.args.get(1) { + if let Some(expr) = call.arguments.args().nth(1) { match expr { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) if value.to_str().contains("%z") => @@ -164,10 +164,9 @@ fn find_antipattern( } match arguments.find_keyword("tzinfo") { // Ex) `datetime.strptime(...).replace(tzinfo=None)` - Some(ast::Keyword { - value: Expr::NoneLiteral(_), - .. - }) => Some(DatetimeModuleAntipattern::NonePassedToTzArgument), + Some(keyword) if keyword.value.is_none_literal_expr() => { + Some(DatetimeModuleAntipattern::NonePassedToTzArgument) + } // Ex) `datetime.strptime(...).replace(tzinfo=...)` Some(_) => None, // Ex) `datetime.strptime(...).replace(...)` with no `tzinfo` argument diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs index bd6d3f7923..085f095beb 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs @@ -81,7 +81,7 @@ fn has_dunder_method(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> /// Returns `true` if the class is a non-abstract Django model. fn is_non_abstract_model(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> bool { - if class_def.bases().is_empty() || is_model_abstract(class_def) { + if class_def.bases().next().is_none() || is_model_abstract(class_def) { false } else { helpers::is_model(class_def, semantic) diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs index ad41efa25a..5d21a224d6 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs @@ -95,7 +95,7 @@ fn is_nullable_field<'a>(value: &'a Expr, semantic: &'a SemanticModel) -> Option let mut null_key = false; let mut blank_key = false; let mut unique_key = false; - for keyword in &*call.arguments.keywords { + for keyword in call.arguments.keywords() { let Some(argument) = &keyword.arg else { continue; }; diff --git a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs index 34ff72b8cd..1bfe8d8c37 100644 --- a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs @@ -1,6 +1,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::whitespace; -use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; +use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_codegen::Stylist; use ruff_python_semantic::SemanticModel; use ruff_source_file::LineRanges; @@ -187,9 +187,7 @@ impl Violation for StrFormatInException { /// EM101, EM102, EM103 pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) { let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) = exc else { return; @@ -199,7 +197,7 @@ pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) { return; } - if let Some(first) = args.first() { + if let Some(first) = arguments.args().next() { match first { // Check for string literals. Expr::StringLiteral(ast::ExprStringLiteral { value: string, .. }) diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs index 1cd7dcbd90..116b6b0d9a 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs @@ -1,3 +1,4 @@ +use ruff_python_ast::Arguments; use ruff_python_ast::Expr; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -65,9 +66,9 @@ impl Violation for FStringInGettextCall { } /// INT001 -pub(crate) fn f_string_in_gettext_func_call(checker: &Checker, func: &Expr, args: &[Expr]) { +pub(crate) fn f_string_in_gettext_func_call(checker: &Checker, func: &Expr, arguments: &Arguments) { // Check first argument (singular) - if let Some(first) = args.first() { + if let Some(first) = arguments.args().next() { if first.is_f_string_expr() { checker.report_diagnostic(FStringInGettextCall { is_plural: false }, first.range()); } @@ -75,7 +76,7 @@ pub(crate) fn f_string_in_gettext_func_call(checker: &Checker, func: &Expr, args // Check second argument (plural) for ngettext calls if is_ngettext_call(checker, func) - && let Some(second) = args.get(1) + && let Some(second) = arguments.args().nth(1) && second.is_f_string_expr() { checker.report_diagnostic(FStringInGettextCall { is_plural: true }, second.range()); diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs index d2abf03beb..cb32f2b6c1 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs @@ -1,3 +1,4 @@ +use ruff_python_ast::Arguments; use ruff_python_ast::Expr; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -66,9 +67,9 @@ impl Violation for FormatInGettextCall { } /// INT002 -pub(crate) fn format_in_gettext_func_call(checker: &Checker, func: &Expr, args: &[Expr]) { +pub(crate) fn format_in_gettext_func_call(checker: &Checker, func: &Expr, arguments: &Arguments) { // Check first argument (singular) - if let Some(first) = args.first() { + if let Some(first) = arguments.args().next() { if is_format_call(first) { checker.report_diagnostic(FormatInGettextCall { is_plural: false }, first.range()); } @@ -76,7 +77,7 @@ pub(crate) fn format_in_gettext_func_call(checker: &Checker, func: &Expr, args: // Check second argument (plural) for ngettext calls if is_ngettext_call(checker, func) - && let Some(second) = args.get(1) + && let Some(second) = arguments.args().nth(1) && is_format_call(second) { checker.report_diagnostic(FormatInGettextCall { is_plural: true }, second.range()); diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs index 2b5c15cff0..1d7f2c20ea 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs @@ -64,9 +64,13 @@ impl Violation for PrintfInGettextCall { } /// INT003 -pub(crate) fn printf_in_gettext_func_call(checker: &Checker, func: &Expr, args: &[Expr]) { +pub(crate) fn printf_in_gettext_func_call( + checker: &Checker, + func: &Expr, + arguments: &ast::Arguments, +) { // Check first argument (singular) - if let Some(first) = args.first() { + if let Some(first) = arguments.args().next() { if is_printf_format(first) { checker.report_diagnostic(PrintfInGettextCall { is_plural: false }, first.range()); } @@ -74,7 +78,7 @@ pub(crate) fn printf_in_gettext_func_call(checker: &Checker, func: &Expr, args: // Check second argument (plural) for ngettext calls if is_ngettext_call(checker, func) - && let Some(second) = args.get(1) + && let Some(second) = arguments.args().nth(1) && is_printf_format(second) { checker.report_diagnostic(PrintfInGettextCall { is_plural: true }, second.range()); diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs index fedff40470..521d3b9b7b 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs @@ -84,7 +84,7 @@ pub(crate) fn exception_without_exc_info(checker: &Checker, call: &ExprCall) { fn exc_info_arg_is_falsey(call: &ExprCall, checker: &Checker) -> bool { call.arguments .find_keyword("exc_info") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) .is_some_and(|value| { let truthiness = Truthiness::from_expr(value, |id| checker.semantic().has_builtin_binding(id)); diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs index 5b3cc811a2..fb12f897ec 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs @@ -32,7 +32,7 @@ fn logging_f_string( // If there are existing positional arguments after the message, bail out. // This could indicate a mistake or complex usage we shouldn't try to fix. - if arguments.args.len() > msg_pos + 1 { + if arguments.args().nth(msg_pos + 1).is_some() { return; } @@ -181,7 +181,7 @@ fn check_msg(checker: &Checker, msg: &Expr, arguments: &Arguments, msg_pos: usiz /// Check contents of the `extra` argument to logging calls. fn check_log_record_attr_clash(checker: &Checker, extra: &Keyword) { - match &extra.value { + match extra.value.as_ref() { Expr::Dict(dict) => { for invalid_key in dict.iter_keys().filter_map(|key| { let string_key = key?.as_string_literal_expr()?; @@ -198,11 +198,9 @@ fn check_log_record_attr_clash(checker: &Checker, extra: &Keyword) { } } Expr::Call(ast::ExprCall { - func, - arguments: Arguments { keywords, .. }, - .. + func, arguments, .. }) if checker.semantic().match_builtin_expr(func, "dict") => { - for keyword in keywords { + for keyword in arguments.keywords() { if let Some(attr) = &keyword.arg { if is_reserved_attr(attr) { checker.report_diagnostic( diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index ddaeff8074..bc8255d7c9 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::collections::BTreeMap; use std::iter; @@ -84,13 +85,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { for (index, call) in values.iter().enumerate() { let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = &call @@ -98,11 +93,11 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { continue; }; - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { continue; } - let [arg] = &**args else { + let Some([arg]) = arguments.args().collect_array() else { continue; }; @@ -145,13 +140,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { .map(|expr| { let Expr::Call(ast::ExprCall { func: _, - arguments: - Arguments { - args, - keywords: _, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = expr @@ -161,7 +150,9 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { format!("Indices should only contain `{attr_name}` calls") ) }; - args.first() + arguments + .args() + .next() .unwrap_or_else(|| panic!("`{attr_name}` should have one argument")) }) .collect(); @@ -199,8 +190,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { let node3 = Expr::Call(ast::ExprCall { func: Box::new(node2), arguments: Arguments { - args: [node].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(node)].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs index 57c5997ff7..a9780627f9 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_python_semantic::SemanticModel; use rustc_hash::FxHashSet; @@ -65,7 +66,6 @@ pub(crate) fn non_unique_enums(checker: &Checker, parent: &Stmt, body: &[Stmt]) if !parent .bases() - .iter() .any(|expr| semantic.matches_qualified_name(expr, &["enum", "Enum"])) { return; @@ -120,11 +120,14 @@ fn member_has_unknown_value(semantic: &SemanticModel, expr: &Expr) -> bool { return false; } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return false; } - matches!(arguments.args.as_ref(), [_, Expr::EllipsisLiteral(_)]) + matches!( + arguments.args().collect_array(), + Some([_, Expr::EllipsisLiteral(_)]) + ) } _ => false, diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs index c7386f3346..0f01560db1 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs @@ -90,13 +90,13 @@ impl Violation for UnnecessaryDictKwargs { /// PIE804 pub(crate) fn unnecessary_dict_kwargs(checker: &Checker, call: &ast::ExprCall) { let mut duplicate_keywords = None; - for keyword in &*call.arguments.keywords { + for keyword in call.arguments.keywords() { // keyword is a spread operator (indicated by None). if keyword.arg.is_some() { continue; } - let Expr::Dict(dict) = &keyword.value else { + let Expr::Dict(dict) = keyword.value.as_ref() else { continue; }; @@ -177,15 +177,15 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &Checker, call: &ast::ExprCall) { /// `func(x=1)`, or indirectly, as in `func(**{"x": 1})`). fn duplicates(call: &ast::ExprCall) -> FxHashSet<&str> { let mut seen = - FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher); + FxHashSet::with_capacity_and_hasher(call.arguments.keywords().count(), FxBuildHasher); let mut duplicates = - FxHashSet::with_capacity_and_hasher(call.arguments.keywords.len(), FxBuildHasher); - for keyword in &*call.arguments.keywords { + FxHashSet::with_capacity_and_hasher(call.arguments.keywords().count(), FxBuildHasher); + for keyword in call.arguments.keywords() { if let Some(name) = &keyword.arg { if !seen.insert(name.as_str()) { duplicates.insert(name.as_str()); } - } else if let Expr::Dict(dict) = &keyword.value { + } else if let Expr::Dict(dict) = keyword.value.as_ref() { for key in dict.iter_keys() { if let Some(name) = key.and_then(as_kwarg) { if !seen.insert(name) { diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index 3eb2822903..0843dc7c46 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -45,12 +46,12 @@ impl AlwaysFixableViolation for UnnecessaryRangeStart { /// PIE808 pub(crate) fn unnecessary_range_start(checker: &Checker, call: &ast::ExprCall) { // `range` doesn't accept keyword arguments. - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } // Verify that the call has exactly two arguments (no `step`). - let [start, _] = &*call.arguments.args else { + let Some([start, _]) = call.arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs index 35073565e1..0b8f46758b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs @@ -112,13 +112,12 @@ pub(crate) fn generic_not_last_base_class(checker: &Checker, class_def: &ast::St return; } - let Some(last_base) = bases.args.last() else { + let Some(last_base) = bases.args().next_back() else { return; }; let mut generic_base_iter = bases - .args - .iter() + .args() .filter(|base| semantic.match_typing_expr(map_subscript(base), "Generic")); let Some(generic_base) = generic_base_iter.next() else { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs index ded87729b5..0b4c0bef2c 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs @@ -267,7 +267,7 @@ pub(crate) fn unused_private_protocol(checker: &Checker, scope: &Scope) { continue; }; - if !class_def.bases().iter().any(|base| { + if !class_def.bases().any(|base| { checker .semantic() .match_typing_expr(map_subscript(base), "Protocol") @@ -390,7 +390,7 @@ fn extract_typeddict_name<'a>(stmt: &'a Stmt, semantic: &SemanticModel) -> Optio // y: T // ``` Stmt::ClassDef(class_def @ ast::StmtClassDef { name, .. }) => { - if class_def.bases().iter().any(is_typeddict) { + if class_def.bases().any(is_typeddict) { Some(name) } else { None diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/helpers.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/helpers.rs index 44f0e0a5de..74e8d460d3 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/helpers.rs @@ -111,7 +111,7 @@ pub(crate) fn is_likely_pytest_test(func: &StmtFunctionDef, checker: &Checker) - } pub(super) fn keyword_is_literal(keyword: &Keyword, literal: &str) -> bool { - if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = &keyword.value { + if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = keyword.value.as_ref() { value == literal } else { false diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs index 52261b2409..6f2b7595d8 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs @@ -13,7 +13,7 @@ use ruff_python_ast::helpers::Truthiness; use ruff_python_ast::token::parenthesized_range; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{ - self as ast, AnyNodeRef, Arguments, BoolOp, ExceptHandler, Expr, Keyword, Stmt, UnaryOp, + self as ast, AnyNodeRef, Arguments, BoolOp, ExceptHandler, Expr, Stmt, UnaryOp, }; use ruff_python_ast::{visitor, whitespace}; use ruff_python_codegen::Stylist; @@ -298,8 +298,7 @@ pub(crate) fn unittest_assertion( checker: &Checker, expr: &Expr, func: &Expr, - args: &[Expr], - keywords: &[Keyword], + arguments: &Arguments, ) { let Expr::Attribute(ast::ExprAttribute { attr, .. }) = func else { return; @@ -322,7 +321,7 @@ pub(crate) fn unittest_assertion( && checker.semantic().current_expression_parent().is_none() && !checker.comment_ranges().intersects(expr.range()) { - if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) { + if let Ok(stmt) = unittest_assert.generate_assert(arguments) { diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().stmt(&stmt), parenthesized_range( @@ -524,11 +523,11 @@ fn to_pytest_raises_args<'a>( ) -> Option> { let args = match attr { "assertRaises" | "failUnlessRaises" => { - match (&*arguments.args, &*arguments.keywords) { + match arguments.items.as_slice() { // Ex) `assertRaises(Exception)` - ([arg], []) => Cow::Borrowed(checker.locator().slice(arg)), + [ast::Argument::Positional(arg)] => Cow::Borrowed(checker.locator().slice(arg)), // Ex) `assertRaises(expected_exception=Exception)` - ([], [kwarg]) + [ast::Argument::Keyword(kwarg)] if kwarg .arg .as_ref() @@ -540,19 +539,28 @@ fn to_pytest_raises_args<'a>( } } "assertRaisesRegex" | "assertRaisesRegexp" => { - match (&*arguments.args, &*arguments.keywords) { + match arguments.items.as_slice() { // Ex) `assertRaisesRegex(Exception, regex)` - ([arg1, arg2], []) => Cow::Owned(format!( + [ + ast::Argument::Positional(arg1), + ast::Argument::Positional(arg2), + ] => Cow::Owned(format!( "{}, match={}", checker.locator().slice(arg1), checker.locator().slice(arg2) )), // Ex) `assertRaisesRegex(Exception, expected_regex=regex)` - ([arg], [kwarg]) - if kwarg - .arg - .as_ref() - .is_some_and(|arg| arg.as_str() == "expected_regex") => + [ + ast::Argument::Positional(arg), + ast::Argument::Keyword(kwarg), + ] + | [ + ast::Argument::Keyword(kwarg), + ast::Argument::Positional(arg), + ] if kwarg + .arg + .as_ref() + .is_some_and(|arg| arg.as_str() == "expected_regex") => { Cow::Owned(format!( "{}, match={}", @@ -561,15 +569,17 @@ fn to_pytest_raises_args<'a>( )) } // Ex) `assertRaisesRegex(expected_exception=Exception, expected_regex=regex)` - ([], [kwarg1, kwarg2]) - if kwarg1 + [ + ast::Argument::Keyword(kwarg1), + ast::Argument::Keyword(kwarg2), + ] if kwarg1 + .arg + .as_ref() + .is_some_and(|id| id.as_str() == "expected_exception") + && kwarg2 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_exception") - && kwarg2 - .arg - .as_ref() - .is_some_and(|id| id.as_str() == "expected_regex") => + .is_some_and(|id| id.as_str() == "expected_regex") => { Cow::Owned(format!( "{}, match={}", @@ -578,15 +588,17 @@ fn to_pytest_raises_args<'a>( )) } // Ex) `assertRaisesRegex(expected_regex=regex, expected_exception=Exception)` - ([], [kwarg1, kwarg2]) - if kwarg1 + [ + ast::Argument::Keyword(kwarg1), + ast::Argument::Keyword(kwarg2), + ] if kwarg1 + .arg + .as_ref() + .is_some_and(|id| id.as_str() == "expected_regex") + && kwarg2 .arg .as_ref() - .is_some_and(|id| id.as_str() == "expected_regex") - && kwarg2 - .arg - .as_ref() - .is_some_and(|id| id.as_str() == "expected_exception") => + .is_some_and(|id| id.as_str() == "expected_exception") => { Cow::Owned(format!( "{}, match={}", diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs index 937aa2891f..7069163a87 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs @@ -749,8 +749,8 @@ fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decor }) => { if checker.is_rule_enabled(Rule::PytestFixtureIncorrectParenthesesStyle) { if !checker.settings().flake8_pytest_style.fixture_parentheses - && arguments.args.is_empty() - && arguments.keywords.is_empty() + && arguments.args().next().is_none() + && arguments.keywords().next().is_none() { let fix = Fix::applicable_edit( Edit::range_deletion(arguments.range()), @@ -771,7 +771,7 @@ fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decor } if checker.is_rule_enabled(Rule::PytestFixturePositionalArgs) { - if !arguments.args.is_empty() { + if arguments.args().next().is_some() { checker.report_diagnostic( PytestFixturePositionalArgs { function: func_name.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs index 598186a88a..08e1eb5888 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Applicability; -use ruff_python_ast::{self as ast, Arguments, Decorator, Expr}; +use ruff_python_ast::{self as ast, Decorator, Expr}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_text_size::Ranged; @@ -163,8 +163,8 @@ fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str node_index: _, }) => { if !checker.settings().flake8_pytest_style.mark_parentheses - && arguments.args.is_empty() - && arguments.keywords.is_empty() + && arguments.args().next().is_none() + && arguments.keywords().next().is_none() { let fix = Fix::applicable_edit( Edit::range_deletion(arguments.range()), @@ -212,11 +212,8 @@ fn check_useless_usefixtures(checker: &Checker, decorator: &Decorator, marker: & // @pytest.mark.usefixtures Expr::Attribute(..) => {} // @pytest.mark.usefixtures(...) - Expr::Call(ast::ExprCall { - arguments: Arguments { args, keywords, .. }, - .. - }) => { - if !args.is_empty() || !keywords.is_empty() { + Expr::Call(ast::ExprCall { arguments, .. }) => { + if !arguments.is_empty() { return; } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs index da75eaa014..0b3828451c 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs @@ -1,7 +1,7 @@ use anyhow::{Result, anyhow, bail}; use ruff_python_ast::name::Name; use ruff_python_ast::{ - self as ast, Arguments, CmpOp, Expr, ExprContext, Identifier, Keyword, Stmt, UnaryOp, + self as ast, Arguments, CmpOp, Expr, ExprContext, Identifier, Stmt, UnaryOp, }; use ruff_text_size::TextRange; use rustc_hash::{FxBuildHasher, FxHashMap}; @@ -227,20 +227,18 @@ impl UnittestAssert { } /// Create a map from argument name to value. - fn args_map<'a>( - &'a self, - args: &'a [Expr], - keywords: &'a [Keyword], - ) -> Result> { + fn args_map<'a>(&'a self, arguments: &'a Arguments) -> Result> { // If we have variable-length arguments, abort. - if args.iter().any(Expr::is_starred_expr) || keywords.iter().any(|kw| kw.arg.is_none()) { + if arguments.args().any(Expr::is_starred_expr) + || arguments.keywords().any(|kw| kw.arg.is_none()) + { bail!("Variable-length arguments are not supported"); } let arg_spec = self.arg_spec(); // If any of the keyword arguments are not in the argument spec, abort. - if keywords.iter().any(|kw| { + if arguments.keywords().any(|kw| { kw.arg .as_ref() .is_some_and(|kwarg_name| !arg_spec.contains(&kwarg_name.as_str())) @@ -250,16 +248,16 @@ impl UnittestAssert { // Generate a map from argument name to value. let mut args_map: FxHashMap<&str, &Expr> = - FxHashMap::with_capacity_and_hasher(args.len() + keywords.len(), FxBuildHasher); + FxHashMap::with_capacity_and_hasher(arguments.len(), FxBuildHasher); // Process positional arguments. - for (arg_name, value) in arg_spec.iter().zip(args) { + for (arg_name, value) in arg_spec.iter().zip(arguments.args()) { args_map.insert(arg_name, value); } // Process keyword arguments. - for arg_name in arg_spec.iter().skip(args.len()) { - if let Some(value) = keywords.iter().find_map(|keyword| { + for arg_name in arg_spec.iter().skip(arguments.args().count()) { + if let Some(value) = arguments.keywords().find_map(|keyword| { if keyword .arg .as_ref() @@ -277,8 +275,8 @@ impl UnittestAssert { Ok(args_map) } - pub(crate) fn generate_assert(self, args: &[Expr], keywords: &[Keyword]) -> Result { - let args = self.args_map(args, keywords)?; + pub(crate) fn generate_assert(self, arguments: &Arguments) -> Result { + let args = self.args_map(arguments)?; match self { UnittestAssert::True | UnittestAssert::False @@ -391,8 +389,9 @@ impl UnittestAssert { let node1 = ast::ExprCall { func: Box::new(node.into()), arguments: Arguments { - args: [(**obj).clone(), (**cls).clone()].into(), - keywords: std::iter::empty().collect(), + items: [(**obj).clone(), (**cls).clone()] + .map(ast::Argument::Positional) + .into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -440,8 +439,9 @@ impl UnittestAssert { let node2 = ast::ExprCall { func: Box::new(node1.into()), arguments: Arguments { - args: [(**regex).clone(), (**text).clone()].into(), - keywords: std::iter::empty().collect(), + items: [(**regex).clone(), (**text).clone()] + .map(ast::Argument::Positional) + .into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index 3db7b8dd1a..58dc9d276e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::iter; use itertools::Itertools; -use ruff_python_ast::{self as ast, Arguments, BoolOp, CmpOp, Expr, ExprContext, UnaryOp}; +use ruff_python_ast::{self as ast, BoolOp, CmpOp, Expr, ExprContext, UnaryOp}; use ruff_text_size::{Ranged, TextRange}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -317,28 +317,23 @@ fn isinstance_target<'a>(call: &'a Expr, semantic: &'a SemanticModel) -> Option< // Verify that this is an `isinstance` call. let ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, } = call.as_call_expr()?; - if args.len() != 2 { + let [ + ast::Argument::Positional(target), + ast::Argument::Positional(_), + ] = arguments.items.as_slice() + else { return None; - } - if !keywords.is_empty() { - return None; - } + }; if !semantic.match_builtin_expr(func, "isinstance") { return None; } // Collect the target (e.g., `obj` in `isinstance(obj, int)`). - Some(&args[0]) + Some(target) } /// SIM101 @@ -382,12 +377,10 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { if indices.len() > 1 { // Grab the target used in each duplicate `isinstance` call (e.g., `obj` in // `isinstance(obj, int)`). - let target = if let Expr::Call(ast::ExprCall { - arguments: Arguments { args, .. }, - .. - }) = &values[indices[0]] - { - args.first() + let target = if let Expr::Call(ast::ExprCall { arguments, .. }) = &values[indices[0]] { + arguments + .args() + .next() .expect("`isinstance` should have two arguments") } else { unreachable!("Indices should only contain `isinstance` calls") @@ -409,14 +402,13 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { let flattened: Vec<&Expr> = indices .iter() .flat_map(|index| { - let Expr::Call(ast::ExprCall { - arguments: Arguments { args, .. }, - .. - }) = &values[*index] - else { + let Expr::Call(ast::ExprCall { arguments, .. }) = &values[*index] else { unreachable!("Indices should only contain `isinstance` calls") }; - let value = args.get(1).expect("`isinstance` should have two arguments"); + let value = arguments + .args() + .nth(1) + .expect("`isinstance` should have two arguments"); if let Expr::Tuple(tuple) = value { &tuple.elts } else { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index 6c21424d63..a94fae0e9d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Applicability; -use ruff_python_ast::{self as ast, Arguments, Expr, str_prefix::StringLiteralPrefix}; +use ruff_python_ast::{self as ast, Expr, str_prefix::StringLiteralPrefix}; use ruff_text_size::{Ranged, TextRange}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -151,14 +151,12 @@ pub(crate) fn use_capital_environment_variables(checker: &Checker, expr: &Expr) // Ex) `os.environ.get('foo')`, `os.getenv('foo')` let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) = expr else { return; }; - let Some(arg) = args.first() else { + let Some(arg) = arguments.args().next() else { return; }; let Expr::StringLiteral(ast::ExprStringLiteral { value: env_var, .. }) = arg else { @@ -256,14 +254,14 @@ fn check_os_environ_subscript(checker: &Checker, expr: &Expr) { pub(crate) fn dict_get_with_none_default(checker: &Checker, expr: &Expr) { let Expr::Call(ast::ExprCall { func, - arguments: Arguments { args, keywords, .. }, + arguments, range_start: _, node_index: _, }) = expr else { return; }; - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func.as_ref() else { @@ -272,10 +270,10 @@ pub(crate) fn dict_get_with_none_default(checker: &Checker, expr: &Expr) { if attr != "get" { return; } - let Some(key) = args.first() else { + let Some(key) = arguments.args().next() else { return; }; - let Some(default) = args.get(1) else { + let Some(default) = arguments.args().nth(1) else { return; }; if !default.is_none_literal_expr() { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index b7146fe083..aa978a8a2c 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -193,8 +193,7 @@ pub(crate) fn if_expr_with_true_false( .into(), ), arguments: Arguments { - args: [test.clone()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(test.clone())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index 659f96b665..47c5176d39 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -300,8 +300,7 @@ pub(crate) fn double_negation(checker: &Checker, expr: &Expr, op: UnaryOp, opera let node1 = ast::ExprCall { func: Box::new(node.into()), arguments: Arguments { - args: [*operand.clone()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(*operand.clone())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs index 1f72dd2bc1..4ca8a7b55f 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs @@ -198,8 +198,7 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast let node3 = ast::ExprCall { func: Box::new(node2.into()), arguments: Arguments { - args: [node1, node].into(), - keywords: std::iter::empty().collect(), + items: [node1, node].map(ast::Argument::Positional).into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -300,8 +299,9 @@ pub(crate) fn if_exp_instead_of_dict_get( let fixed_node = ast::ExprCall { func: Box::new(dict_get_node.into()), arguments: Arguments { - args: [dict_key_node, default_value_node].into(), - keywords: std::iter::empty().collect(), + items: [dict_key_node, default_value_node] + .map(ast::Argument::Positional) + .into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs index e4644a7882..2c6252fbea 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -1,7 +1,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::AnyNodeRef; use ruff_python_ast::token::parenthesized_range; -use ruff_python_ast::{self as ast, Arguments, CmpOp, Comprehension, Expr}; +use ruff_python_ast::{self as ast, CmpOp, Comprehension, Expr}; use ruff_python_semantic::analyze::typing; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextRange}; @@ -60,14 +60,14 @@ impl AlwaysFixableViolation for InDictKeys { fn key_in_dict(checker: &Checker, left: &Expr, right: &Expr, operator: CmpOp, parent: AnyNodeRef) { let Expr::Call(ast::ExprCall { func, - arguments: Arguments { args, keywords, .. }, + arguments, range_start: _, node_index: _, }) = &right else { return; }; - if !(args.is_empty() && keywords.is_empty()) { + if !(arguments.is_empty()) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs index 1019c0b39d..be4c645585 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs @@ -274,8 +274,7 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { let call_node = ast::ExprCall { func: Box::new(func_node.into()), arguments: Arguments { - args: [if_test.clone()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(if_test.clone())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 00823723a2..122a67ba59 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -401,8 +401,7 @@ fn return_stmt(id: Name, test: &Expr, target: &Expr, iter: &Expr, generator: Gen let node2 = ast::ExprCall { func: Box::new(node1.into()), arguments: Arguments { - args: [node.into()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(node.into())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs index 905454dc40..a2697ce379 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs @@ -1,4 +1,5 @@ use ast::{ExprAttribute, ExprName, Identifier}; +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Arguments, Expr}; @@ -68,20 +69,20 @@ impl AlwaysFixableViolation for ZipDictKeysAndValues { /// SIM911 pub(crate) fn zip_dict_keys_and_values(checker: &Checker, expr: &ast::ExprCall) { let ast::ExprCall { - func, - arguments: Arguments { args, keywords, .. }, - .. + func, arguments, .. } = expr; - match &keywords[..] { - [] => {} - [ - ast::Keyword { + let mut keywords = arguments.keywords(); + match (keywords.next(), keywords.next()) { + (None, _) => {} + ( + Some(ast::Keyword { arg: Some(name), .. - }, - ] if name.as_str() == "strict" => {} + }), + None, + ) if name.as_str() == "strict" => {} _ => return, } - let [arg1, arg2] = &args[..] else { + let Some([arg1, arg2]) = arguments.args().collect_array() else { return; }; let Some((var1, attr1, args1)) = get_var_attr_args(arg1) else { diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs index 64f4ac8303..040a98d469 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs @@ -84,11 +84,11 @@ pub(crate) fn no_slots_in_namedtuple_subclass( if checker.source_type.is_stub() { return; } - let Some(Arguments { args: bases, .. }) = class.arguments.as_deref() else { + let Some(arguments) = class.arguments.as_deref() else { return; }; - if let Some(namedtuple_kind) = namedtuple_base(bases, checker.semantic()) { + if let Some(namedtuple_kind) = namedtuple_base(arguments, checker.semantic()) { if !has_slots(&class.body) { checker.report_diagnostic( NoSlotsInNamedtupleSubclass(namedtuple_kind), @@ -100,9 +100,9 @@ pub(crate) fn no_slots_in_namedtuple_subclass( /// If the class's bases consist solely of named tuples, return the kind of named tuple /// (either `collections.namedtuple()`, or `typing.NamedTuple()`). Otherwise, return `None`. -fn namedtuple_base(bases: &[Expr], semantic: &SemanticModel) -> Option { +fn namedtuple_base(arguments: &Arguments, semantic: &SemanticModel) -> Option { let mut kind = None; - for base in bases { + for base in arguments.args() { if let Expr::Call(ast::ExprCall { func, .. }) = base { // Ex) `collections.namedtuple()` let qualified_name = semantic.resolve_qualified_name(func)?; diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs index 8f35f2a181..ebb111ea46 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs @@ -1,6 +1,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::identifier::Identifier; -use ruff_python_ast::{Arguments, Expr, Stmt, StmtClassDef}; +use ruff_python_ast::{Arguments, Stmt, StmtClassDef}; use ruff_python_semantic::{SemanticModel, analyze::class::is_enumeration}; use crate::Violation; @@ -56,13 +56,13 @@ pub(crate) fn no_slots_in_str_subclass(checker: &Checker, stmt: &Stmt, class: &S if checker.source_type.is_stub() { return; } - let Some(Arguments { args: bases, .. }) = class.arguments.as_deref() else { + let Some(arguments) = class.arguments.as_deref() else { return; }; let semantic = checker.semantic(); - if !is_str_subclass(bases, semantic) { + if !is_str_subclass(arguments, semantic) { return; } @@ -79,8 +79,8 @@ pub(crate) fn no_slots_in_str_subclass(checker: &Checker, stmt: &Stmt, class: &S } /// Return `true` if the class is a subclass of `str`. -fn is_str_subclass(bases: &[Expr], semantic: &SemanticModel) -> bool { - bases - .iter() +fn is_str_subclass(arguments: &Arguments, semantic: &SemanticModel) -> bool { + arguments + .args() .any(|base| semantic.match_builtin_expr(base, "str")) } diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs index 88d2c3165c..f8e589817a 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{Arguments, Stmt, StmtClassDef}; +use ruff_python_ast::{Stmt, StmtClassDef}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::helpers::map_subscript; @@ -57,13 +57,13 @@ pub(crate) fn no_slots_in_tuple_subclass(checker: &Checker, stmt: &Stmt, class: if checker.source_type.is_stub() { return; } - let Some(Arguments { args: bases, .. }) = class.arguments.as_deref() else { + let Some(arguments) = class.arguments.as_deref() else { return; }; let semantic = checker.semantic(); - if bases.iter().any(|base| { + if arguments.args().any(|base| { let base = map_subscript(base); semantic.match_builtin_expr(base, "tuple") || semantic.match_typing_expr(base, "Tuple") }) { diff --git a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs index 8ee11ea843..c0e4f8319b 100644 --- a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs +++ b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_python_ast as ast; use ruff_python_ast::{Parameter, Parameters, Stmt, StmtExpr, StmtFunctionDef, StmtRaise}; @@ -376,7 +377,7 @@ pub(crate) fn is_not_implemented_stub_with_variable( return false; } - let [argument] = &*arguments.args else { + let Some([argument]) = arguments.args().collect_array() else { return false; }; diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs index 44bb14b9c8..0a11f07a10 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs @@ -199,11 +199,11 @@ pub(crate) fn has_unknown_keywords_or_starred_expr( arguments: &Arguments, allowed: &[&str], ) -> bool { - if arguments.args.iter().any(Expr::is_starred_expr) { + if arguments.args().any(Expr::is_starred_expr) { return true; } - arguments.keywords.iter().any(|kw| match &kw.arg { + arguments.keywords().any(|kw| match &kw.arg { Some(arg) => !allowed.contains(&arg.as_str()), None => true, }) diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_stat.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_stat.rs index 011c6e789b..cf3f51d4b3 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_stat.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_stat.rs @@ -204,7 +204,7 @@ fn is_boolean_literal_or_default(argument: &Arguments, name: &str) -> Option Some(*value), _ => None, } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index 3d80caa53e..19b18a46ed 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::ops::Range; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -75,11 +76,11 @@ pub(crate) fn path_constructor_current_directory( return; } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [Expr::StringLiteral(arg)] = &*arguments.args else { + let Some([Expr::StringLiteral(arg)]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index 2f567676ca..dade051dd9 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -26,7 +26,7 @@ pub(crate) fn replaceable_by_pathlib( checker.report_diagnostic_if_enabled( OsPathJoin { module: module.to_string(), - joiner: if call.arguments.args.iter().any(Expr::is_starred_expr) { + joiner: if call.arguments.args().any(Expr::is_starred_expr) { Joiner::Joinpath } else { Joiner::Slash diff --git a/crates/ruff_linter/src/rules/flynt/helpers.rs b/crates/ruff_linter/src/rules/flynt/helpers.rs index d0ea3ea97e..5e22c3d6e4 100644 --- a/crates/ruff_linter/src/rules/flynt/helpers.rs +++ b/crates/ruff_linter/src/rules/flynt/helpers.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{self as ast, Arguments, ConversionFlag, Expr}; +use ruff_python_ast::{self as ast, ConversionFlag, Expr}; use ruff_text_size::TextRange; /// Wrap an expression in a [`ast::FStringElement::Expression`] with no special formatting. @@ -28,16 +28,10 @@ fn is_simple_call(expr: &Expr) -> bool { match expr { Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, - }) => args.is_empty() && keywords.is_empty() && is_simple_callee(func), + }) => arguments.is_empty() && is_simple_callee(func), _ => false, } } diff --git a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs index 14d1dadeb3..531a804246 100644 --- a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs @@ -2,7 +2,7 @@ use ast::FStringFlags; use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Arguments, Expr, StringFlags, str::Quote}; +use ruff_python_ast::{self as ast, Expr, StringFlags, str::Quote}; use ruff_text_size::{Ranged, TextRange}; use crate::checkers::ast::Checker; @@ -161,20 +161,13 @@ fn build_fstring(joiner: &str, joinees: &[Expr], flags: FStringFlags) -> Option< /// FLY002 pub(crate) fn static_join_to_fstring(checker: &Checker, expr: &Expr, joiner: &str) { - let Expr::Call(ast::ExprCall { - arguments: Arguments { args, keywords, .. }, - .. - }) = expr - else { + let Expr::Call(ast::ExprCall { arguments, .. }) = expr else { return; }; // If there are kwargs or more than one argument, this is some non-standard // string join call. - if !keywords.is_empty() { - return; - } - let [arg] = &**args else { + let [ast::Argument::Positional(arg)] = arguments.items.as_slice() else { return; }; diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs index 12625ae6d2..24fd2d21c8 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs @@ -73,7 +73,7 @@ pub(crate) fn inplace_argument(checker: &Checker, call: &ast::ExprCall) { } let mut seen_star = false; - for keyword in call.arguments.keywords.iter().rev() { + for keyword in call.arguments.keywords().rev() { let Some(arg) = &keyword.arg else { seen_star = true; continue; diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs index 509d35e4a7..a467db3cf2 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs @@ -62,7 +62,7 @@ pub(crate) fn use_of_read_table( && let Some(Expr::StringLiteral(ast::ExprStringLiteral { value, .. })) = call .arguments .find_keyword("sep") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) && value == "," { checker.report_diagnostic(PandasUseOfDotReadTable, call.func.range()); diff --git a/crates/ruff_linter/src/rules/pep8_naming/helpers.rs b/crates/ruff_linter/src/rules/pep8_naming/helpers.rs index b6a8b095f6..3fd4643528 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/helpers.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/helpers.rs @@ -122,7 +122,7 @@ pub(super) fn is_django_model_import(name: &str, stmt: &Stmt, semantic: &Semanti if let Some(unqualified_name) = UnqualifiedName::from_expr(func.as_ref()) { if matches!(unqualified_name.segments(), [.., "get_model"]) { if let Some(argument) = arguments - .find_argument_value("model_name", arguments.args.len().saturating_sub(1)) + .find_argument_value("model_name", arguments.args().count().saturating_sub(1)) { if let Some(string_literal) = argument.as_string_literal_expr() { if string_literal.value.to_str() == name { diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs index 31af0dcb45..ab13850cd3 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs @@ -62,7 +62,7 @@ pub(crate) fn error_suffix_on_exception_name( } if !arguments.is_some_and(|arguments| { - arguments.args.iter().any(|base| { + arguments.args().any(|base| { if let Expr::Name(ast::ExprName { id, .. }) = &base { id == "Exception" || id.ends_with("Error") } else { diff --git a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs index 27e2625091..155276d673 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs @@ -2,7 +2,7 @@ use std::fmt; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast as ast; -use ruff_python_ast::{Arguments, Expr}; +use ruff_python_ast::Expr; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -90,14 +90,12 @@ fn check_dict_items_usage(checker: &Checker, target: &Expr, iter: &Expr) { return; }; let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) = iter else { return; }; - if !args.is_empty() { + if arguments.args().next().is_some() { return; } let Expr::Attribute(ast::ExprAttribute { attr, .. }) = func.as_ref() else { diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs index 211c994d7c..4d7074837e 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{self as ast, Arguments, Expr}; +use ruff_python_ast::{self as ast, Expr}; use crate::codes::Category; use crate::{Edit, Fix, FixAvailability, Violation}; @@ -141,13 +141,7 @@ pub(crate) fn manual_list_comprehension(checker: &Checker, for_stmt: &ast::StmtF let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = value.as_ref() @@ -156,11 +150,7 @@ pub(crate) fn manual_list_comprehension(checker: &Checker, for_stmt: &ast::StmtF }; let call_range = value.range(); - if !keywords.is_empty() { - return; - } - - let [arg] = &**args else { + let [ast::Argument::Positional(arg)] = arguments.items.as_slice() else { return; }; diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs index e34b29ccfb..9f230abbb5 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs @@ -1,6 +1,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::helpers::any_over_expr; -use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; +use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::analyze::typing::is_list; use ruff_text_size::Ranged; @@ -68,13 +68,7 @@ pub(crate) fn manual_list_copy(checker: &Checker, for_stmt: &ast::StmtFor) { let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = value.as_ref() @@ -83,11 +77,7 @@ pub(crate) fn manual_list_copy(checker: &Checker, for_stmt: &ast::StmtFor) { }; let call_range = value.range(); - if !keywords.is_empty() { - return; - } - - let [arg] = &**args else { + let [ast::Argument::Positional(arg)] = arguments.items.as_slice() else { return; }; diff --git a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs index 8ee945c570..9922c80306 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -1,7 +1,8 @@ +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::statement_visitor::{StatementVisitor, walk_stmt}; -use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; +use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::analyze::typing::find_assigned_value; use ruff_text_size::{Ranged, TextRange}; @@ -70,13 +71,7 @@ impl AlwaysFixableViolation for UnnecessaryListCast { pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt]) { let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords: _, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = iter @@ -84,7 +79,7 @@ pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt return; }; - let [arg] = &**args else { + let Some([arg]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index aa031f4381..a22d342a86 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -561,14 +561,14 @@ impl Violation for StringDotFormatMixingAutomatic { } } -fn has_star_star_kwargs(keywords: &[Keyword]) -> bool { - keywords - .iter() +fn has_star_star_kwargs(arguments: &ast::Arguments) -> bool { + arguments + .keywords() .any(|keyword| matches!(keyword, Keyword { arg: None, .. })) } -fn has_star_args(args: &[Expr]) -> bool { - args.iter().any(Expr::is_starred_expr) +fn has_star_args(arguments: &ast::Arguments) -> bool { + arguments.args().any(Expr::is_starred_expr) } /// F502 @@ -806,15 +806,15 @@ pub(crate) fn string_dot_format_extra_named_arguments( checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, - keywords: &[Keyword], ) { // If there are any **kwargs, abort. - if has_star_star_kwargs(keywords) { + if has_star_star_kwargs(&call.arguments) { return; } - let keyword_names = keywords - .iter() + let keyword_names = call + .arguments + .keywords() .filter_map(|Keyword { arg, value, .. }| Some((arg.as_ref()?, value))); let mut side_effects = false; @@ -866,18 +866,17 @@ pub(crate) fn string_dot_format_extra_positional_arguments( checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, - args: &[Expr], ) { // We can only fix if the positional arguments we're removing don't require re-indexing // the format string itself. For example, we can't fix `"{1}{2}".format(0, 1, 2)"`, since // this requires changing the format string to `"{0}{1}"`. But we can fix // `"{0}{1}".format(0, 1, 2)`, since this only requires modifying the call arguments. - fn is_contiguous_from_end(indexes: &[usize], target: &[T]) -> bool { + fn is_contiguous_from_end(indexes: &[usize], target_len: usize) -> bool { if indexes.is_empty() { return true; } - let mut expected_index = target.len() - 1; + let mut expected_index = target_len - 1; for &index in indexes.iter().rev() { if index != expected_index { return false; @@ -894,8 +893,9 @@ pub(crate) fn string_dot_format_extra_positional_arguments( } let mut side_effects = false; - let missing: Vec = args - .iter() + let missing: Vec = call + .arguments + .args() .enumerate() .filter(|(i, arg)| { !(arg.is_starred_expr() || summary.autos.contains(i) || summary.indices.contains(i)) @@ -920,7 +920,7 @@ pub(crate) fn string_dot_format_extra_positional_arguments( call.range(), ); - if is_contiguous_from_end(&missing, args) { + if is_contiguous_from_end(&missing, call.arguments.args().count()) { diagnostic.try_set_fix(|| { let edit = remove_unused_positional_arguments_from_format_call( &missing, @@ -946,26 +946,26 @@ pub(crate) fn string_dot_format_missing_argument( checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, - args: &[Expr], - keywords: &[Keyword], ) { - if has_star_args(args) || has_star_star_kwargs(keywords) { + if has_star_args(&call.arguments) || has_star_star_kwargs(&call.arguments) { return; } - let keywords: FxHashSet<_> = keywords - .iter() + let keywords: FxHashSet<_> = call + .arguments + .keywords() .filter_map(|k| { let Keyword { arg, .. } = &k; arg.as_ref().map(ruff_python_ast::Identifier::id) }) .collect(); + let positional_count = call.arguments.args().count(); let missing: Vec = summary .autos .iter() .chain(&summary.indices) - .filter(|&&i| i >= args.len()) + .filter(|&&i| i >= positional_count) .map(ToString::to_string) .chain( summary diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs index 343d1bdbac..2240f21142 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::fmt; use ruff_python_ast::{self as ast, Expr}; @@ -179,11 +180,11 @@ pub(crate) fn bad_str_strip_call(checker: &Checker, call: &ast::ExprCall) { return; }; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [arg] = arguments.args.as_ref() else { + let Some([arg]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index 46b7450017..54fb9ae8e0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{Expr, ExprCompare}; use ruff_text_size::Ranged; @@ -68,15 +69,17 @@ pub(crate) fn comparison_with_itself(checker: &Checker, compare: &ExprCompare) { // Ex) `id(foo) == id(foo)` (Expr::Call(left_call), Expr::Call(right_call)) => { // Both calls must take a single argument, of the same name. - if !left_call.arguments.keywords.is_empty() - || !right_call.arguments.keywords.is_empty() + if left_call.arguments.keywords().next().is_some() + || right_call.arguments.keywords().next().is_some() { continue; } - let [Expr::Name(left_arg)] = &*left_call.arguments.args else { + let Some([Expr::Name(left_arg)]) = left_call.arguments.args().collect_array() + else { continue; }; - let [Expr::Name(right_right)] = &*right_call.arguments.args else { + let Some([Expr::Name(right_right)]) = right_call.arguments.args().collect_array() + else { continue; }; if left_arg.id != right_right.id { diff --git a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs index 0d216983a2..7803302ab6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs @@ -81,9 +81,10 @@ pub(crate) fn duplicate_bases(checker: &Checker, name: &str, arguments: Option<& let Some(arguments) = arguments else { return; }; - let bases = &arguments.args; + let bases = arguments.args(); - let mut seen: FxHashSet<&str> = FxHashSet::with_capacity_and_hasher(bases.len(), FxBuildHasher); + let mut seen: FxHashSet<&str> = + FxHashSet::with_capacity_and_hasher(arguments.len(), FxBuildHasher); for base in bases { if let Expr::Name(ast::ExprName { id, .. }) = base { if !seen.insert(id) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs index e03353e954..0911633b07 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr, ExprCall}; @@ -96,8 +97,10 @@ pub(crate) fn len_test(checker: &Checker, call: &ExprCall) { } // Single argument and no keyword arguments - let [argument] = &*arguments.args else { return }; - if !arguments.keywords.is_empty() { + let Some([argument]) = arguments.args().collect_array() else { + return; + }; + if arguments.keywords().next().is_some() { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/logging.rs b/crates/ruff_linter/src/rules/pylint/rules/logging.rs index cde9c80471..b03da9b97d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/logging.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/logging.rs @@ -98,15 +98,14 @@ impl Violation for LoggingTooManyArgs { /// PLE1206 pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { // If there are any starred arguments, abort. - if call.arguments.args.iter().any(Expr::is_starred_expr) { + if call.arguments.args().any(Expr::is_starred_expr) { return; } // If there are any starred keyword arguments, abort. if call .arguments - .keywords - .iter() + .keywords() .any(|keyword| keyword.arg.is_none()) { return; @@ -160,8 +159,8 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { return; } - let num_message_args = call.arguments.args.len() - 1; - let num_keywords = call.arguments.keywords.len(); + let num_message_args = call.arguments.args().count() - 1; + let num_keywords = call.arguments.keywords().count(); if checker.is_rule_enabled(Rule::LoggingTooManyArgs) { if summary.num_positional < num_message_args { diff --git a/crates/ruff_linter/src/rules/pylint/rules/missing_maxsplit_arg.rs b/crates/ruff_linter/src/rules/pylint/rules/missing_maxsplit_arg.rs index 3c5293ff45..8c00787ee0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/missing_maxsplit_arg.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/missing_maxsplit_arg.rs @@ -172,10 +172,10 @@ pub(crate) fn missing_maxsplit_arg(checker: &Checker, value: &Expr, slice: &Expr } // Check maxsplit kwarg not set via unpacked dict literal - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { let Keyword { value, .. } = keyword; - if let Expr::Dict(ExprDict { items, .. }) = value { + if let Expr::Dict(ExprDict { items, .. }) = value.as_ref() { for item in items { let DictItem { key, .. } = item; if let Some(Expr::StringLiteral(ExprStringLiteral { value, .. })) = key { @@ -217,11 +217,8 @@ pub(crate) fn missing_maxsplit_arg(checker: &Checker, value: &Expr, slice: &Expr maxsplit_argument_edit, split_type_edit, // Mark the fix as unsafe, if there are `*args` or `**kwargs` - if arguments.args.iter().any(Expr::is_starred_expr) - || arguments - .keywords - .iter() - .any(|keyword| keyword.arg.is_none()) + if arguments.args().any(Expr::is_starred_expr) + || arguments.keywords().any(|keyword| keyword.arg.is_none()) { Applicability::Unsafe } else { diff --git a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs index e126093e1c..88861dec04 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs @@ -104,19 +104,13 @@ impl std::fmt::Display for Nan { /// Returns `true` if the expression is a call to `float("NaN")`. fn is_nan_float(expr: &Expr, semantic: &SemanticModel) -> bool { let Expr::Call(ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. }) = expr else { return false; }; - if !keywords.is_empty() { - return false; - } - - let [expr] = &**args else { + let [ast::Argument::Positional(expr)] = arguments.items.as_slice() else { return false; }; if as_nan_float_string_literal(expr).is_none() { diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index 2ef25da39a..2fbbdfa84e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -1,4 +1,4 @@ -use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; +use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_text_size::{Ranged, TextRange}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -101,10 +101,10 @@ impl MinMax { /// Converts a function call [`Expr`] into a [`MinMax`] if it is a call to `min` or `max`. fn try_from_call( func: &Expr, - keywords: &[Keyword], + arguments: &Arguments, semantic: &SemanticModel, ) -> Option { - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } match semantic.resolve_builtin_symbol(func)? { @@ -126,24 +126,27 @@ impl std::fmt::Display for MinMax { /// Collect a new set of arguments to by either accepting existing args as-is or /// collecting child arguments, if it's a call to the same function. -fn collect_nested_args(min_max: MinMax, args: &[Expr], semantic: &SemanticModel) -> Vec { - fn inner(min_max: MinMax, args: &[Expr], semantic: &SemanticModel, new_args: &mut Vec) { - for arg in args { +fn collect_nested_args( + min_max: MinMax, + arguments: &Arguments, + semantic: &SemanticModel, +) -> Vec { + fn inner( + min_max: MinMax, + arguments: &Arguments, + semantic: &SemanticModel, + new_args: &mut Vec, + ) { + for arg in arguments.args() { if let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = arg { - if MinMax::try_from_call(func, keywords, semantic) == Some(min_max) { - if let [arg] = &**args { + if MinMax::try_from_call(func, arguments, semantic) == Some(min_max) { + if let [ast::Argument::Positional(arg)] = arguments.items.as_slice() { if arg.as_starred_expr().is_none() { let new_arg = Expr::Starred(ast::ExprStarred { value: Box::new(arg.clone()), @@ -155,7 +158,7 @@ fn collect_nested_args(min_max: MinMax, args: &[Expr], semantic: &SemanticModel) continue; } } - inner(min_max, args, semantic, new_args); + inner(min_max, arguments, semantic, new_args); continue; } } @@ -163,48 +166,42 @@ fn collect_nested_args(min_max: MinMax, args: &[Expr], semantic: &SemanticModel) } } - let mut new_args = Vec::with_capacity(args.len()); - inner(min_max, args, semantic, &mut new_args); + let mut new_args = Vec::with_capacity(arguments.len()); + inner(min_max, arguments, semantic, &mut new_args); new_args } /// PLW3301 -pub(crate) fn nested_min_max( - checker: &Checker, - expr: &Expr, - func: &Expr, - args: &[Expr], - keywords: &[Keyword], -) { - let Some(min_max) = MinMax::try_from_call(func, keywords, checker.semantic()) else { +pub(crate) fn nested_min_max(checker: &Checker, expr: &Expr, func: &Expr, arguments: &Arguments) { + let Some(min_max) = MinMax::try_from_call(func, arguments, checker.semantic()) else { return; }; // It's only safe to flatten nested calls if the outer call has more than one argument. // When the outer call has a single argument, flattening would change the semantics by // changing the shape of the call from treating the inner result as an iterable (or a scalar) // to passing multiple arguments directly, which can lead to behavioral changes. - if args.len() < 2 { + if arguments.len() < 2 { return; } - if args.iter().any(|arg| { + if arguments.args().any(|arg| { let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { keywords, .. }, - .. + func, arguments, .. }) = arg else { return false; }; - MinMax::try_from_call(func.as_ref(), keywords.as_ref(), checker.semantic()) == Some(min_max) + MinMax::try_from_call(func, arguments, checker.semantic()) == Some(min_max) }) { let mut diagnostic = checker.report_diagnostic(NestedMinMax { func: min_max }, expr.range()); let flattened_expr = Expr::Call(ast::ExprCall { func: Box::new(func.clone()), arguments: Arguments { - args: collect_nested_args(min_max, args, checker.semantic()).into(), - keywords: keywords.iter().cloned().collect(), + items: collect_nested_args(min_max, arguments, checker.semantic()) + .into_iter() + .map(ast::Argument::Positional) + .collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs index e6cf9d1596..1ff2490944 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::collections::HashMap; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -121,23 +122,15 @@ fn get_undecorated_methods(checker: &Checker, class_stmt: &Stmt, method_type: &M { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { if id == method_name && checker.semantic().has_builtin_binding(method_name) { - if arguments.args.len() != 1 { + let Some([Expr::Name(ast::ExprName { id, .. })]) = + arguments.args().collect_array() + else { continue; - } - - if targets.len() != 1 { - continue; - } - - let target_name = match targets.first() { - Some(Expr::Name(ast::ExprName { id, .. })) => id.to_string(), - _ => continue, }; - - if let Expr::Name(ast::ExprName { id, .. }) = &arguments.args[0] { - if target_name == *id { - explicit_decorator_calls.insert(id.clone(), stmt); - } + if let [Expr::Name(target)] = targets.as_slice() + && target.id == *id + { + explicit_decorator_calls.insert(id.clone(), stmt); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index 314e7a2846..c4b03b9fc5 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -69,7 +69,6 @@ pub(crate) fn non_slot_assignment(checker: &Checker, class_def: &ast::StmtClassD // the parent class defines the relevant `__slots__`. if !class_def .bases() - .iter() .all(|base| semantic.match_builtin_expr(base, "object")) { return; diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs index 53c096c8ee..37675c49d2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs @@ -1,7 +1,8 @@ +use itertools::Itertools; use std::{fmt, iter}; use regex::Regex; -use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt, WithItem}; +use ruff_python_ast::{self as ast, Expr, ExprContext, Stmt, WithItem}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::comparable::ComparableExpr; @@ -263,9 +264,7 @@ fn assignment_is_cast_expr(value: &Expr, target: &Expr, semantic: &SemanticModel } let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) = value else { return false; @@ -273,10 +272,8 @@ fn assignment_is_cast_expr(value: &Expr, target: &Expr, semantic: &SemanticModel let Expr::Name(ast::ExprName { id: target_id, .. }) = target else { return false; }; - if args.len() != 2 { - return false; - } - let Expr::Name(ast::ExprName { id: arg_id, .. }) = &args[1] else { + let Some([_, Expr::Name(ast::ExprName { id: arg_id, .. })]) = arguments.args().collect_array() + else { return false; }; if arg_id != target_id { diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs index 68e8b883ef..14127946c9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs @@ -56,7 +56,7 @@ impl Violation for RedefinedSlotsInSubclass { // PLW0244 pub(crate) fn redefined_slots_in_subclass(checker: &Checker, class_def: &ast::StmtClassDef) { // Early return if this is not a subclass - if class_def.bases().is_empty() { + if class_def.bases().next().is_none() { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs index eaafb60891..583439ad4f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use rustc_hash::{FxBuildHasher, FxHashSet}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -43,23 +44,23 @@ pub(crate) fn repeated_keyword_argument(checker: &Checker, call: &ExprCall) { // Avoid allocating if there's only one non-unpacked keyword argument, or the unpacked value is // not a dict literal. - if let [keyword] = &*arguments.keywords { + if let Some([keyword]) = arguments.keywords().collect_array() { if keyword.arg.is_some() || !keyword.value.is_dict_expr() { return; } } - let mut seen = FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher); + let mut seen = FxHashSet::with_capacity_and_hasher(arguments.keywords().count(), FxBuildHasher); - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { if let Some(id) = &keyword.arg { seen.insert(id.as_str()); } } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { if keyword.arg.is_none() - && let Expr::Dict(dict) = &keyword.value + && let Expr::Dict(dict) = keyword.value.as_ref() { for key in dict.iter_keys().flatten() { if let Expr::StringLiteral(ExprStringLiteral { value, .. }) = key { diff --git a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs index f206684fad..8d52d77972 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; @@ -73,11 +74,11 @@ pub(crate) fn shallow_copy_environ(checker: &Checker, call: &ast::ExprCall) { return; } - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - let [arg] = call.arguments.args.as_ref() else { + let Some([arg]) = call.arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index 1a8d809b33..a3871efb8e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -86,11 +86,7 @@ pub(crate) fn sys_exit_alias(checker: &Checker, call: &ExprCall) { call.func.range(), ); - let has_star_kwargs = call - .arguments - .keywords - .iter() - .any(|kwarg| kwarg.arg.is_none()); + let has_star_kwargs = call.arguments.keywords().any(|kwarg| kwarg.arg.is_none()); // only one optional argument allowed, and we can't convert **kwargs if call.arguments.len() > 1 || has_star_kwargs { return; diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs index e1b8d11af7..f0a0ef0185 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs @@ -90,14 +90,14 @@ pub(crate) fn type_bivariance(checker: &Checker, value: &Expr) { let Some(covariant) = arguments .find_keyword("covariant") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) else { return; }; let Some(contravariant) = arguments .find_keyword("contravariant") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) else { return; }; diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs index bd0bfc984c..a539a55d8d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs @@ -87,11 +87,11 @@ pub(crate) fn type_name_incorrect_variance(checker: &Checker, value: &Expr) { let covariant = arguments .find_keyword("covariant") - .map(|keyword| &keyword.value); + .map(|keyword| keyword.value.as_ref()); let contravariant = arguments .find_keyword("contravariant") - .map(|keyword| &keyword.value); + .map(|keyword| keyword.value.as_ref()); if !mismatch(param_name, covariant, contravariant) { return; diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs index df48beb9be..f3c2668879 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs @@ -133,7 +133,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { } // If the call has keywords, abort. - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } @@ -143,8 +143,9 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { let mut title: Option = None; if let Some(dunder) = DunderReplacement::from_method(attr) { - match (&*call.arguments.args, dunder) { - ([], DunderReplacement::Builtin(replacement, message)) => { + let mut args = call.arguments.args(); + match (args.next(), args.next(), dunder) { + (None, _, DunderReplacement::Builtin(replacement, message)) => { if !checker.semantic().has_builtin_binding(replacement) { return; } @@ -158,7 +159,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { )); title = Some(message.to_string()); } - ([arg], DunderReplacement::Operator(replacement, message, precedence)) => { + (Some(arg), None, DunderReplacement::Operator(replacement, message, precedence)) => { let value_slice = checker.locator().slice(value.as_ref()); let arg_slice = checker.locator().slice(arg); @@ -178,7 +179,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { title = Some(message.to_string()); } - ([arg], DunderReplacement::ROperator(replacement, message, precedence)) => { + (Some(arg), None, DunderReplacement::ROperator(replacement, message, precedence)) => { let value_slice = checker.locator().slice(value.as_ref()); let arg_slice = checker.locator().slice(arg); @@ -197,7 +198,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { } title = Some(message.to_string()); } - (_, DunderReplacement::MessageOnly(message)) => { + (_, _, DunderReplacement::MessageOnly(message)) => { title = Some(message.to_string()); } _ => {} diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs index d44dd706fe..0ddaede8a9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs @@ -186,7 +186,7 @@ fn forwards_arguments(parameters: &ast::Parameters, arguments: &ast::Arguments) Expr::Starred(arg) => (&mut starred, arg.value.as_ref()), _ => return false, }, - ArgOrKeyword::Keyword(arg) => (&mut keyword, &arg.value), + ArgOrKeyword::Keyword(arg) => (&mut keyword, arg.value.as_ref()), }; let Some(name) = value.as_name_expr() else { return false; diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs index cc84fc3515..2ea177b129 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs @@ -145,7 +145,7 @@ fn enumerate_items<'a>( } // Get the first argument of the enumerate call. - let Some(Expr::Name(sequence)) = arguments.args.first() else { + let Some(Expr::Name(sequence)) = arguments.args().next() else { return None; }; diff --git a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs index 2c205cfe6e..53e9fa994d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs @@ -206,14 +206,13 @@ fn is_binary_mode(expr: &Expr) -> Option { /// Returns `true` if the given call lacks an explicit `encoding`. fn is_violation(call: &ast::ExprCall, qualified_name: &Callee) -> bool { // If we have something like `*args`, which might contain the encoding argument, abort. - if call.arguments.args.iter().any(Expr::is_starred_expr) { + if call.arguments.args().any(Expr::is_starred_expr) { return false; } // If we have something like `**kwargs`, which might contain the encoding argument, abort. if call .arguments - .keywords - .iter() + .keywords() .any(|keyword| keyword.arg.is_none()) { return false; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 9b0c4678b6..c5b0b13ccd 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -4,7 +4,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::name::Name; use ruff_python_ast::{ - self as ast, Arguments, DecoratorList, Expr, ExprContext, Identifier, Keyword, Stmt, Suite, + self as ast, Arguments, DecoratorList, Expr, ExprContext, Identifier, Stmt, Suite, }; use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; @@ -81,20 +81,23 @@ pub(crate) fn convert_named_tuple_functional_to_class( targets: &[Expr], value: &Expr, ) { - let Some((typename, args, keywords, base_class)) = + let Some((typename, arguments, base_class)) = match_named_tuple_assign(targets, value, checker.semantic()) else { return; }; - let fields = match (args, keywords) { + let fields = match arguments.items.as_slice() { // Ex) `NamedTuple("MyType")` - ([_typename], []) => Suite::from([Stmt::Pass(ast::StmtPass { + [ast::Argument::Positional(_)] => Suite::from([Stmt::Pass(ast::StmtPass { range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, })]), // Ex) `NamedTuple("MyType", [("a", int), ("b", str)])` - ([_typename, fields], []) => { + [ + ast::Argument::Positional(_), + ast::Argument::Positional(fields), + ] => { if let Some(fields) = create_fields_from_fields_arg(fields) { fields } else { @@ -103,8 +106,8 @@ pub(crate) fn convert_named_tuple_functional_to_class( } } // Ex) `NamedTuple("MyType", a=int, b=str)` - ([_typename], keywords) => { - if let Some(fields) = create_fields_from_keywords(keywords) { + _ if arguments.args().count() == 1 => { + if let Some(fields) = create_fields_from_keywords(arguments) { fields } else { debug!("Skipping `NamedTuple` \"{typename}\": unable to parse keywords"); @@ -137,18 +140,18 @@ pub(crate) fn convert_named_tuple_functional_to_class( } } -/// Return the typename, args, keywords, and base class. +/// Return the typename, arguments, and base class. fn match_named_tuple_assign<'a>( targets: &'a [Expr], value: &'a Expr, semantic: &SemanticModel, -) -> Option<(&'a str, &'a [Expr], &'a [Keyword], &'a Expr)> { +) -> Option<(&'a str, &'a Arguments, &'a Expr)> { let [Expr::Name(ast::ExprName { id: typename, .. })] = targets else { return None; }; let Expr::Call(ast::ExprCall { func, - arguments: Arguments { args, keywords, .. }, + arguments, range_start: _, node_index: _, }) = value @@ -158,7 +161,7 @@ fn match_named_tuple_assign<'a>( if !semantic.match_typing_expr(func, "NamedTuple") { return None; } - Some((typename, args, keywords, func)) + Some((typename, arguments, func)) } /// Generate a [`Stmt::AnnAssign`] representing the provided field definition. @@ -219,9 +222,9 @@ fn create_fields_from_fields_arg(fields: &Expr) -> Option { } /// Create a list of field assignments from the `NamedTuple` keyword arguments. -fn create_fields_from_keywords(keywords: &[Keyword]) -> Option { - keywords - .iter() +fn create_fields_from_keywords(arguments: &Arguments) -> Option { + arguments + .keywords() .map(|keyword| { keyword .arg @@ -237,8 +240,7 @@ fn create_class_def_stmt(typename: &str, body: Suite, base_class: &Expr) -> Stmt ast::StmtClassDef { name: Identifier::new(typename.to_string(), TextRange::default()), arguments: Some(Box::new(Arguments { - args: [base_class.clone()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(base_class.clone())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 838b3fcb95..72bc63111d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -1,7 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{ - self as ast, Arguments, Expr, ExprContext, Identifier, Keyword, Stmt, Suite, -}; +use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Identifier, Stmt, Suite}; use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::identifiers::is_identifier; @@ -171,14 +169,21 @@ fn create_field_assignment_stmt(field: &str, annotation: &Expr) -> Stmt { fn create_class_def_stmt( class_name: &str, body: Suite, - keywords: &[Keyword], + class_keywords: Option<&Arguments>, base_class: &Expr, ) -> Stmt { ast::StmtClassDef { name: Identifier::new(class_name.to_string(), TextRange::default()), arguments: Some(Box::new(Arguments { - args: [base_class.clone()].into(), - keywords: keywords.into(), + items: std::iter::once(ast::Argument::Positional(base_class.clone())) + .chain( + class_keywords + .into_iter() + .flat_map(Arguments::keywords) + .cloned() + .map(ast::Argument::Keyword), + ) + .collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), @@ -220,26 +225,18 @@ fn fields_from_dict_literal(items: &[ast::DictItem]) -> Option { } } -fn fields_from_dict_call(func: &Expr, keywords: &[Keyword]) -> Option { +fn fields_from_dict_call(func: &Expr, arguments: &Arguments) -> Option { let ast::ExprName { id, .. } = func.as_name_expr()?; if id != "dict" { return None; } - - if keywords.is_empty() { - let node = Stmt::Pass(ast::StmtPass { - range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::NONE, - }); - Some(Suite::from([node])) - } else { - fields_from_keywords(keywords) - } + fields_from_keywords(arguments) } // Deprecated in Python 3.11, removed in Python 3.13. -fn fields_from_keywords(keywords: &[Keyword]) -> Option { - if keywords.is_empty() { +fn fields_from_keywords(arguments: &Arguments) -> Option { + let mut keywords = arguments.keywords().peekable(); + if keywords.peek().is_none() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, @@ -248,7 +245,6 @@ fn fields_from_keywords(keywords: &[Keyword]) -> Option { } keywords - .iter() .map(|keyword| { keyword .arg @@ -259,36 +255,21 @@ fn fields_from_keywords(keywords: &[Keyword]) -> Option { } /// Match the fields and class keywords from a `TypedDict` call. -fn match_fields_and_keywords(arguments: &Arguments) -> Option<(Suite, &[Keyword])> { - match (&*arguments.args, &*arguments.keywords) { - // Ex) `TypedDict("MyType", {"a": int, "b": str})` - ([_typename, fields], keywords) => match fields { - Expr::Dict(ast::ExprDict { - items, - range: _, - node_index: _, - }) => Some((fields_from_dict_literal(items)?, keywords)), - Expr::Call(ast::ExprCall { - func, - arguments: Arguments { - keywords: fields, .. - }, - range_start: _, - node_index: _, - }) => Some((fields_from_dict_call(func, fields)?, keywords)), - _ => None, - }, - // Ex) `TypedDict("MyType")` - ([_typename], []) => { - let node = Stmt::Pass(ast::StmtPass { - range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::NONE, - }); - Some((Suite::from([node]), &[])) +fn match_fields_and_keywords(arguments: &Arguments) -> Option<(Suite, Option<&Arguments>)> { + let mut args = arguments.args(); + let _typename = args.next()?; + match (args.next(), args.next()) { + // Ex) `TypedDict("MyType", {"a": int}, total=False)` + (Some(fields), None) => { + let suite = match fields { + Expr::Dict(dict) => fields_from_dict_literal(&dict.items)?, + Expr::Call(call) => fields_from_dict_call(&call.func, &call.arguments)?, + _ => return None, + }; + Some((suite, Some(arguments))) } - // Ex) `TypedDict("MyType", a=int, b=str)` - ([_typename], fields) => Some((fields_from_keywords(fields)?, &[])), - // Ex) `TypedDict()` + // Ex) `TypedDict("MyType", a=int)` + (None, _) => Some((fields_from_keywords(arguments)?, None)), _ => None, } } @@ -298,7 +279,7 @@ fn convert_to_class( stmt: &Stmt, class_name: &str, body: Suite, - keywords: &[Keyword], + class_keywords: Option<&Arguments>, base_class: &Expr, generator: Generator, comment_ranges: &CommentRanges, @@ -306,7 +287,10 @@ fn convert_to_class( Fix::applicable_edit( Edit::range_replacement( generator.stmt(&create_class_def_stmt( - class_name, body, keywords, base_class, + class_name, + body, + class_keywords, + base_class, )), stmt.range(), ), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index e76dea002e..5201eb0205 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -74,7 +74,7 @@ impl<'a> FormatSummaryValues<'a> { let mut extracted_args: Vec<&Expr> = Vec::new(); let mut extracted_kwargs: FxHashMap<&str, &Expr> = FxHashMap::default(); - for arg in &*call.arguments.args { + for arg in call.arguments.args() { if matches!(arg, Expr::Starred(..)) || contains_quotes(locator.slice(arg)) || locator.contains_line_break(arg.range()) @@ -83,7 +83,7 @@ impl<'a> FormatSummaryValues<'a> { } extracted_args.push(arg); } - for keyword in &*call.arguments.keywords { + for keyword in call.arguments.keywords() { let Keyword { arg, value, @@ -91,7 +91,9 @@ impl<'a> FormatSummaryValues<'a> { node_index: _, } = keyword; let key = arg.as_ref()?; - if contains_quotes(locator.slice(value)) || locator.contains_line_break(value.range()) { + if contains_quotes(locator.slice(value.as_ref())) + || locator.contains_line_break(value.range()) + { return None; } extracted_kwargs.insert(key, value); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs index e57ef1cb65..89df7d1131 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs @@ -91,20 +91,19 @@ pub(crate) fn format_literals(checker: &Checker, call: &ast::ExprCall, summary: Arguments::Preserve } else { // Ex) `"{1} {0}".format(foo=1, bar=2)` - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } // Ex) `"{1} {0}".format(foo)` - if call.arguments.args.len() < summary.indices.len() { + if call.arguments.args().count() < summary.indices.len() { return; } // Ex) `"{1} {0}".format(*foo)` if call .arguments - .args - .iter() + .args() .take(summary.indices.len()) .any(Expr::is_starred_expr) { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index 9d78aa7098..774075756c 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Applicability; -use ruff_python_ast::{self as ast, Arguments, Decorator, Expr, Keyword}; +use ruff_python_ast::{self as ast, Decorator, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -65,13 +65,7 @@ pub(crate) fn lru_cache_with_maxsize_none(checker: &Checker, decorator_list: &[D for decorator in decorator_list { let Expr::Call(ast::ExprCall { func, - arguments: - Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, }) = &decorator.expression @@ -80,8 +74,7 @@ pub(crate) fn lru_cache_with_maxsize_none(checker: &Checker, decorator_list: &[D }; // Look for, e.g., `import functools; @functools.lru_cache(maxsize=None)`. - if args.is_empty() - && keywords.len() == 1 + if let [ast::Argument::Keyword(keyword)] = arguments.items.as_slice() && checker .semantic() .matches_qualified_name(func, &["functools", "lru_cache"]) @@ -91,7 +84,7 @@ pub(crate) fn lru_cache_with_maxsize_none(checker: &Checker, decorator_list: &[D value, range: _, node_index: _, - } = &keywords[0]; + } = keyword; if arg.as_ref().is_some_and(|arg| arg == "maxsize") && value.is_none_literal_expr() { let mut diagnostic = checker.report_diagnostic( LRUCacheWithMaxsizeNone, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index d9820d6efa..f8a49734d8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -68,8 +68,8 @@ pub(crate) fn lru_cache_without_parameters(checker: &Checker, decorator_list: &[ }; // Look for, e.g., `import functools; @functools.lru_cache()`. - if arguments.args.is_empty() - && arguments.keywords.is_empty() + if arguments.args().next().is_none() + && arguments.keywords().next().is_none() && checker .semantic() .matches_qualified_name(func, &["functools", "lru_cache"]) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index 58f74144f7..eb39a278b2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -190,13 +190,7 @@ pub(crate) fn native_literals( ) { let ast::ExprCall { func, - arguments: - ast::Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, } = call; @@ -207,10 +201,12 @@ pub(crate) fn native_literals( return; }; - let call_arg = match (args.as_ref(), keywords.as_ref()) { - ([], []) => None, - ([arg], []) => Some(arg), - ([], [keyword]) if is_redundant_keyword(builtin, keyword) => Some(&keyword.value), + let call_arg = match arguments.items.as_slice() { + [] => None, + [ast::Argument::Positional(arg)] => Some(arg), + [ast::Argument::Keyword(keyword)] if is_redundant_keyword(builtin, keyword) => { + Some(keyword.value.as_ref()) + } _ => return, }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs index 3edb9a055e..3fd7a1d446 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs @@ -329,8 +329,8 @@ pub(crate) fn expr_name_to_type_var<'a>( }; if arguments - .args - .first() + .args() + .next() .is_some_and(Expr::is_string_literal_expr) { // `default` was added in PEP 696 and Python 3.13. We now support converting @@ -348,12 +348,12 @@ pub(crate) fn expr_name_to_type_var<'a>( // ``` let default = arguments .find_keyword("default") - .map(|default| &default.value); + .map(|default| default.value.as_ref()); let restriction = if let Some(bound) = arguments.find_keyword("bound") { Some(TypeVarRestriction::Bound(&bound.value)) - } else if arguments.args.len() > 1 { + } else if arguments.args().nth(1).is_some() { Some(TypeVarRestriction::Constraint( - arguments.args.iter().skip(1).collect(), + arguments.args().skip(1).collect(), )) } else { None @@ -432,7 +432,7 @@ pub(crate) fn find_generic<'a>( class_bases: &'a Arguments, semantic: &SemanticModel, ) -> Option<(usize, &'a ExprSubscript)> { - class_bases.args.iter().enumerate().find_map(|(idx, expr)| { + class_bases.args().enumerate().find_map(|(idx, expr)| { expr.as_subscript_expr().and_then(|sub_expr| { semantic .match_typing_expr(&sub_expr.value, "Generic") diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs index f3075795be..4eebfbb3ae 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs @@ -201,7 +201,7 @@ pub(crate) fn non_pep695_generic_class(checker: &Checker, class_def: &StmtClassD // // because `find_generic` also finds the *first* Generic argument, this has the additional // benefit of bailing out with a diagnostic if multiple Generic arguments are present - if generic_idx != arguments.args.len() - 1 { + if generic_idx != arguments.args().count() - 1 { return; } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs index 50bf2e394d..d02959744a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs @@ -146,7 +146,7 @@ pub(crate) fn non_pep695_type_alias_type(checker: &Checker, stmt: &StmtAssign) { return; }; - let [Expr::StringLiteral(name), value] = arguments.args.as_ref() else { + let Some([Expr::StringLiteral(name), value]) = arguments.args().collect_array() else { return; }; @@ -154,15 +154,21 @@ pub(crate) fn non_pep695_type_alias_type(checker: &Checker, stmt: &StmtAssign) { return; } - let type_params = match arguments.keywords.as_ref() { - [] => &[], - [ - Keyword { + let mut keywords = arguments.keywords(); + let type_params = match (keywords.next(), keywords.next()) { + (None, _) => &[], + ( + Some(Keyword { arg: Some(name), - value: Expr::Tuple(type_params), + value, .. - }, - ] if name.as_str() == "type_params" => type_params.elts.as_slice(), + }), + None, + ) if name.as_str() == "type_params" + && let Expr::Tuple(type_params) = value.as_ref() => + { + type_params.elts.as_slice() + } _ => return, }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs index b43445b8a8..db0460e851 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs @@ -111,7 +111,7 @@ pub(crate) fn replace_str_enum(checker: &Checker, class_def: &ast::StmtClassDef) // Determine whether the class inherits from both `str` and `enum.Enum`. let mut inherits_str = false; let mut inherits_enum = false; - for base in &*arguments.args { + for base in arguments.args() { if let Some(qualified_name) = checker.semantic().resolve_qualified_name(base) { match qualified_name.segments() { ["" | "builtins", "str"] => inherits_str = true, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index c4af1dc596..eb2b9b066d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::visitor::{Visitor, walk_expr, walk_stmt}; @@ -93,7 +94,7 @@ pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall // For a `super` invocation to be unnecessary, the first argument needs to match // the enclosing class, and the second argument needs to match the first // argument to the enclosing function. - let [first_arg, second_arg] = &*call.arguments.args else { + let Some([first_arg, second_arg]) = call.arguments.args().collect_array() else { return; }; @@ -235,7 +236,7 @@ pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall { arguments.find_keyword("slots").is_some_and(|keyword| { matches!( - keyword.value, + keyword.value.as_ref(), Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: true, .. }) ) }) @@ -249,7 +250,7 @@ pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall let mut diagnostic = checker.report_diagnostic(SuperCallWithParameters, call.arguments.range()); // Only provide a fix if there are no keyword arguments, since super() doesn't accept keyword arguments - if call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_none() { let applicability = if checker.comment_ranges().intersects(call.arguments.range()) { Applicability::Unsafe } else { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs index 3f679f9a14..1ea7e92ed7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -1,4 +1,6 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::Arguments; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -55,8 +57,13 @@ impl Violation for TypeOfPrimitive { } /// UP003 -pub(crate) fn type_of_primitive(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - let [arg] = args else { +pub(crate) fn type_of_primitive( + checker: &Checker, + expr: &Expr, + func: &Expr, + arguments: &Arguments, +) { + let Some([arg]) = arguments.args().collect_array() else { return; }; let Some(primitive) = Primitive::from_expr(arg) else { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs index 2284645e85..13e6e90641 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs @@ -51,7 +51,7 @@ pub(crate) fn unnecessary_class_parentheses(checker: &Checker, class_def: &ast:: return; }; - if !arguments.args.is_empty() || !arguments.keywords.is_empty() { + if arguments.args().next().is_some() || arguments.keywords().next().is_some() { return; } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index d468b53f58..a9f3485d48 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -104,15 +104,15 @@ enum EncodingArg<'a> { /// Return the encoding argument to an `encode` call, if it can be determined to be a /// UTF-8-equivalent encoding. fn match_encoding_arg(arguments: &Arguments) -> Option> { - match (&*arguments.args, &*arguments.keywords) { + match arguments.items.as_slice() { // Ex `"".encode()` - ([], []) => return Some(EncodingArg::Empty), + [] => return Some(EncodingArg::Empty), // Ex `"".encode(encoding)` - ([arg], []) if is_utf8_encoding_arg(arg) => { + [ast::Argument::Positional(arg)] if is_utf8_encoding_arg(arg) => { return Some(EncodingArg::Positional(arg)); } // Ex `"".encode(kwarg=kwarg)` - ([], [keyword]) + [ast::Argument::Keyword(keyword)] if keyword.arg.as_ref().is_some_and(|arg| arg == "encoding") && is_utf8_encoding_arg(&keyword.value) => { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index e9e85aa40b..b5ad055ba7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -1,3 +1,4 @@ +use ruff_python_ast::Arguments; use std::fmt; use ruff_macros::{ViolationMetadata, derive_message_formats}; @@ -90,8 +91,13 @@ impl AlwaysFixableViolation for NonPEP604Isinstance { } /// UP038 -pub(crate) fn use_pep604_isinstance(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - let Some(types) = args.get(1) else { +pub(crate) fn use_pep604_isinstance( + checker: &Checker, + expr: &Expr, + func: &Expr, + arguments: &Arguments, +) { + let Some(types) = arguments.args().nth(1) else { return; }; let Expr::Tuple(tuple) = types else { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_class_metaclass_type.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_class_metaclass_type.rs index 1f1ca95582..e18d6f7176 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_class_metaclass_type.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_class_metaclass_type.rs @@ -55,7 +55,7 @@ pub(crate) fn useless_class_metaclass_type(checker: &Checker, class_def: &StmtCl return; }; - for keyword in &arguments.keywords { + for keyword in arguments.keywords() { if let (Some("metaclass"), expr) = (keyword.arg.as_deref(), &keyword.value) { if checker.semantic().match_builtin_expr(expr, "type") { let mut diagnostic = checker.report_diagnostic( diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs index 638afaa4cd..15ada585ce 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -56,7 +56,7 @@ pub(crate) fn useless_object_inheritance(checker: &Checker, class_def: &ast::Stm return; }; - for base in &*arguments.args { + for base in arguments.args() { if !checker.semantic().match_builtin_expr(base, "object") { continue; } diff --git a/crates/ruff_linter/src/rules/refurb/helpers.rs b/crates/ruff_linter/src/rules/refurb/helpers.rs index 7d9ed5459a..45285bb322 100644 --- a/crates/ruff_linter/src/rules/refurb/helpers.rs +++ b/crates/ruff_linter/src/rules/refurb/helpers.rs @@ -32,8 +32,7 @@ pub(super) fn generate_method_call(name: Name, method: &str, generator: Generato let call = ast::ExprCall { func: Box::new(attr.into()), arguments: ast::Arguments { - args: [].into(), - keywords: std::iter::empty().collect(), + items: [].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -260,16 +259,14 @@ fn find_file_open<'a>( ) -> Option> { // We want to match `open(...) as var`. let ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. } = item.context_expr.as_call_expr()?; // Ignore calls with `*args` and `**kwargs`. In the exact case of `open(*filename, mode="w")`, // it could be a match; but in all other cases, the call _could_ contain unsupported keyword // arguments, like `buffering`. - if args.iter().any(Expr::is_starred_expr) - || keywords.iter().any(|keyword| keyword.arg.is_none()) + if arguments.args().any(Expr::is_starred_expr) + || arguments.keywords().any(|keyword| keyword.arg.is_none()) { return None; } @@ -279,7 +276,7 @@ fn find_file_open<'a>( } // Match positional arguments, get filename and mode. - let (filename, pos_mode) = match_open_args(args)?; + let (filename, pos_mode) = match_open_args(arguments)?; // `open` accepts a file descriptor, but `Path` does not, so a `pathlib` replacement // would fail at runtime. `PTH123` skips these for the same reason. @@ -288,7 +285,7 @@ fn find_file_open<'a>( } // Match keyword arguments, get keyword arguments to forward and possibly mode. - let (keywords, kw_mode) = match_open_keywords(keywords, read_mode, python_version)?; + let (keywords, kw_mode) = match_open_keywords(arguments, read_mode, python_version)?; let mode = kw_mode.unwrap_or(pos_mode); @@ -311,12 +308,10 @@ fn find_path_open<'a>( python_version: PythonVersion, ) -> Option> { let ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. } = item.context_expr.as_call_expr()?; - if args.iter().any(Expr::is_starred_expr) - || keywords.iter().any(|keyword| keyword.arg.is_none()) + if arguments.args().any(Expr::is_starred_expr) + || arguments.keywords().any(|keyword| keyword.arg.is_none()) { return None; } @@ -326,13 +321,13 @@ fn find_path_open<'a>( } let attr = func.as_attribute_expr()?; - let mode = if args.is_empty() { + let mode = if arguments.args().next().is_none() { OpenMode::ReadText } else { - match_open_mode(args.first()?)? + match_open_mode(arguments.args().next()?)? }; - let (keywords, kw_mode) = match_open_keywords(keywords, read_mode, python_version)?; + let (keywords, kw_mode) = match_open_keywords(arguments, read_mode, python_version)?; let mode = kw_mode.unwrap_or(mode); resolve_file_open( @@ -349,10 +344,13 @@ fn find_path_open<'a>( } /// Match positional arguments. Return expression for the file name and open mode. -fn match_open_args(args: &[Expr]) -> Option<(&Expr, OpenMode)> { - match args { - [filename] => Some((filename, OpenMode::ReadText)), - [filename, mode_literal] => match_open_mode(mode_literal).map(|mode| (filename, mode)), +fn match_open_args(arguments: &ast::Arguments) -> Option<(&Expr, OpenMode)> { + let mut args = arguments.args(); + match (args.next(), args.next(), args.next()) { + (Some(filename), None, _) => Some((filename, OpenMode::ReadText)), + (Some(filename), Some(mode_literal), None) => { + match_open_mode(mode_literal).map(|mode| (filename, mode)) + } // The third positional argument is `buffering` and the pathlib methods don't support it. _ => None, } @@ -360,14 +358,14 @@ fn match_open_args(args: &[Expr]) -> Option<(&Expr, OpenMode)> { /// Match keyword arguments. Return keyword arguments to forward and mode. fn match_open_keywords( - keywords: &[ast::Keyword], + arguments: &ast::Arguments, read_mode: bool, target_version: PythonVersion, ) -> Option<(Vec<&ast::Keyword>, Option)> { let mut result: Vec<&ast::Keyword> = vec![]; let mut mode: Option = None; - for keyword in keywords { + for keyword in arguments.keywords() { match keyword.arg.as_ref()?.as_str() { "encoding" | "errors" => result.push(keyword), "newline" => { diff --git a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs index 150b439f6e..2d42a80053 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::PythonVersion; use ruff_python_ast::{self as ast, Expr, ExprAttribute, ExprCall}; @@ -80,10 +81,10 @@ pub(crate) fn bit_count(checker: &Checker, call: &ExprCall) { return; } - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - let [arg] = &*call.arguments.args else { + let Some([arg]) = call.arguments.args().collect_array() else { return; }; @@ -106,10 +107,10 @@ pub(crate) fn bit_count(checker: &Checker, call: &ExprCall) { return; }; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [arg] = &*arguments.args else { + let Some([arg]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index 246fe7800c..f75cf894bb 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; @@ -147,7 +148,7 @@ fn match_remove(if_stmt: &ast::StmtIf) -> Option<(&Expr, &ast::ExprName)> { let ast::ExprCall { func: attr, - arguments: ast::Arguments { args, keywords, .. }, + arguments, .. } = expr.as_call_expr()?; @@ -161,11 +162,9 @@ fn match_remove(if_stmt: &ast::StmtIf) -> Option<(&Expr, &ast::ExprName)> { return None; }; - let [arg] = &**args else { - return None; - }; + let [arg] = arguments.args().collect_array()?; - if func_name != "remove" || !keywords.is_empty() { + if func_name != "remove" || arguments.keywords().next().is_some() { return None; } @@ -188,8 +187,7 @@ fn make_suggestion(set: &ast::ExprName, element: &Expr, generator: Generator) -> let call = ast::ExprCall { func: Box::new(attr.into()), arguments: ast::Arguments { - args: [element.clone()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(element.clone())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs index a3bf3761f4..97f0e1320f 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{Expr, Stmt, StmtFor}; use ruff_python_semantic::analyze::typing; @@ -76,7 +77,7 @@ pub(crate) fn for_loop_set_mutations(checker: &Checker, for_stmt: &StmtFor) { let Expr::Attribute(expr_attr) = expr_call.func.as_ref() else { return; }; - if !expr_call.arguments.keywords.is_empty() { + if expr_call.arguments.keywords().next().is_some() { return; } @@ -99,7 +100,7 @@ pub(crate) fn for_loop_set_mutations(checker: &Checker, for_stmt: &StmtFor) { { return; } - let [arg] = expr_call.arguments.args.as_ref() else { + let Some([arg]) = expr_call.arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs b/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs index 24324b822d..088f62fb5b 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{Expr, ExprList, ExprName, ExprTuple, Stmt, StmtFor}; use ruff_python_semantic::analyze::typing; @@ -160,10 +161,10 @@ fn for_loop_writes( return; } - if !call_expr.arguments.keywords.is_empty() { + if call_expr.arguments.keywords().next().is_some() { return; } - let [write_arg] = call_expr.arguments.args.as_ref() else { + let Some([write_arg]) = call_expr.arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs b/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs index 88c844698c..6a996fcf3d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::token::parenthesized_range; use ruff_python_ast::{ @@ -90,11 +91,11 @@ pub(crate) fn fromisoformat_replace_z(checker: &Checker, call: &ExprCall) { let (func, arguments) = (&*call.func, &call.arguments); - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [argument] = &*arguments.args else { + let Some([argument]) = arguments.args().collect_array() else { return; }; @@ -153,7 +154,7 @@ impl<'a> ReplaceTimeZone<'a> { fn from_call(call: &'a ExprCall) -> Option { let arguments = &call.arguments; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } @@ -163,7 +164,7 @@ impl<'a> ReplaceTimeZone<'a> { return None; } - let [z, Expr::StringLiteral(zero_offset)] = &*arguments.args else { + let Some([z, Expr::StringLiteral(zero_offset)]) = arguments.args().collect_array() else { return None; }; @@ -219,13 +220,11 @@ fn strip_z_date(call: &ExprCall) -> Option<(&Expr, &Expr)> { return None; } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - let [z] = &*arguments.args else { - return None; - }; + let [z] = arguments.args().collect_array()?; if !is_upper_case_z_string(z) { return None; diff --git a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs index 1c0c284753..30450d6445 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr, ExprCall, Number, PythonVersion, UnaryOp}; use ruff_source_file::find_newline; @@ -103,11 +104,11 @@ pub(crate) fn fstring_number_format(checker: &Checker, subscript: &ast::ExprSubs return; }; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [arg] = &*arguments.args else { + let Some([arg]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs index 19cd3e25d3..410860e99f 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs @@ -69,11 +69,12 @@ pub(crate) fn no_implicit_cwd(checker: &Checker, call: &ExprCall) { // Match on arguments, but ignore keyword arguments. `Path()` accepts keyword arguments, but // ignores them. See: https://github.com/python/cpython/issues/98094. - match &*arguments.args { + let mut args = arguments.args(); + match (args.next(), args.next()) { // Ex) `Path().resolve()` - [] => {} + (None, _) => {} // Ex) `Path(".").resolve()` - [arg] => { + (Some(arg), None) => { let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = arg else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs index 5a56954827..03fac79846 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs @@ -1,4 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::Argument; use ruff_python_ast::{Expr, ExprCall, Identifier}; use ruff_text_size::Ranged; @@ -74,14 +75,14 @@ pub(crate) fn int_on_sliced_str(checker: &Checker, call: &ExprCall) { } // There must be exactly two arguments (e.g., `int(num[2:], 16)`). - let (expression, base) = match ( - call.arguments.args.as_ref(), - call.arguments.keywords.as_ref(), - ) { - ([expression], [base]) if base.arg.as_ref().map(Identifier::as_str) == Some("base") => { - (expression, &base.value) + let (expression, base) = match call.arguments.items.as_slice() { + [Argument::Positional(expression), Argument::Keyword(base)] + | [Argument::Keyword(base), Argument::Positional(expression)] + if base.arg.as_ref().map(Identifier::as_str) == Some("base") => + { + (expression, base.value.as_ref()) } - ([expression, base], []) => (expression, base), + [Argument::Positional(expression), Argument::Positional(base)] => (expression, base), _ => { return; } diff --git a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs index c011f6a386..3f6cd68cc6 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr, Operator}; use ruff_python_semantic::SemanticModel; @@ -55,11 +56,11 @@ pub(crate) fn isinstance_type_none(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let (func, arguments) = (&call.func, &call.arguments); - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [expr, types] = arguments.args.as_ref() else { + let Some([expr, types]) = arguments.args().collect_array() else { return; }; @@ -95,11 +96,14 @@ fn is_none(expr: &Expr, semantic: &SemanticModel) -> bool { return false; } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return false; } - matches!(arguments.args.as_ref(), [Expr::NoneLiteral(_)]) + matches!( + arguments.args().collect_array(), + Some([Expr::NoneLiteral(_)]) + ) } // Ex) `(type(None),)` diff --git a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs index 09c2130eb1..df2d6121ab 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{ Expr, ExprCall, ExprName, ExprSlice, ExprSubscript, ExprUnaryOp, Int, StmtAssign, UnaryOp, @@ -116,7 +117,7 @@ fn peel_lists(expr: &Expr) -> &Expr { return expr; }; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return expr; } @@ -124,7 +125,7 @@ fn peel_lists(expr: &Expr) -> &Expr { return expr; } - let [arg] = arguments.args.as_ref() else { + let Some([arg]) = arguments.args().collect_array() else { return expr; }; @@ -142,13 +143,11 @@ fn extract_name_from_reversed<'a>( func, arguments, .. } = expr.as_call_expr()?; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - let [arg] = arguments.args.as_ref() else { - return None; - }; + let [arg] = arguments.args().collect_array()?; if !semantic.match_builtin_expr(func, "reversed") { return None; diff --git a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs index 2b8442c744..d57ec3de3a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs @@ -74,7 +74,11 @@ pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) { }; // Identify the `metaclass` keyword. - let Some((position, keyword)) = class_def.keywords().iter().find_position(|&keyword| { + let mut keywords = arguments.keywords().peekable(); + let Some(&first_keyword) = keywords.peek() else { + return; + }; + let Some((position, keyword)) = keywords.find_position(|&keyword| { keyword .arg .as_ref() @@ -91,7 +95,7 @@ pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) { return; } - let applicability = if !class_def.bases().is_empty() { + let applicability = if class_def.bases().next().is_some() { // The class has base arguments (not just a `metaclass` keyword). // Applying the fix may change semantics, so it is considered unsafe. Applicability::Unsafe @@ -137,7 +141,7 @@ pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) { Fix::applicable_edits( delete_metaclass_keyword, [ - Edit::insertion(format!("{binding}, "), class_def.keywords()[0].start()), + Edit::insertion(format!("{binding}, "), first_keyword.start()), import_edit, ], applicability, diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index 68ccca8831..c15fcb25cf 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -82,9 +82,10 @@ pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { return; } - match &*call.arguments.args { + let mut positional = call.arguments.args(); + match (positional.next(), positional.next()) { // Ex) `print("")` or `print("", sep="\t")` - [arg] if is_empty_string(arg) => { + (Some(arg), None) if is_empty_string(arg) => { let reason = if call.arguments.find_keyword("sep").is_some() { Reason::Both } else { @@ -105,12 +106,12 @@ pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { ); } - [arg] if arg.is_starred_expr() => { + (Some(arg), None) if arg.is_starred_expr() => { // If there's a starred argument, we can't remove the empty string. } // Ex) `print(sep="\t")` or `print(obj, sep="\t")` - [] | [_] => { + (_, None) => { // If there's a `sep` argument, remove it, regardless of what it is. if call.arguments.find_keyword("sep").is_some() { let mut diagnostic = checker.report_diagnostic( @@ -137,8 +138,7 @@ pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { // Ignore `**kwargs`. let has_kwargs = call .arguments - .keywords - .iter() + .keywords() .any(|keyword| keyword.arg.is_none()); if has_kwargs { return; @@ -156,8 +156,7 @@ pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { // Count the number of empty and non-empty arguments. let empty_arguments = call .arguments - .args - .iter() + .args() .filter(|arg| is_empty_string(arg)) .count(); if empty_arguments == 0 { @@ -166,8 +165,8 @@ pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { // If removing the arguments would leave us with one or fewer, then we can remove the // separator too. - let separator = if call.arguments.args.len() - empty_arguments > 1 - || call.arguments.args.iter().any(Expr::is_starred_expr) + let separator = if call.arguments.args().count() - empty_arguments > 1 + || call.arguments.args().any(Expr::is_starred_expr) { Separator::Retain } else { @@ -237,39 +236,18 @@ impl EmptyStringFix { applicability = Applicability::Unsafe; } - // Remove all empty string positional arguments. - call.arguments.args = call - .arguments - .args - .iter() - .filter(|arg| !is_empty_string(arg)) - .cloned() - .collect(); - - // Remove the `sep` keyword argument if it exists. - if separator == Separator::Remove { - call.arguments.keywords = call - .arguments - .keywords - .iter() - .filter(|keyword| { - let Some(arg) = keyword.arg.as_ref() else { - return true; - }; - - if arg.as_str() != "sep" { - return true; - } - - if !is_known_valid_separator(&keyword.value) { - applicability = Applicability::Unsafe; - } - - false - }) - .cloned() - .collect(); - } + call.arguments.items.retain(|item| match item { + ast::Argument::Positional(arg) => !is_empty_string(arg), + ast::Argument::Keyword(keyword) + if separator == Separator::Remove && keyword.arg.as_deref() == Some("sep") => + { + if !is_known_valid_separator(&keyword.value) { + applicability = Applicability::Unsafe; + } + false + } + ast::Argument::Keyword(_) => true, + }); let contents = generator.expr(&call.into()); diff --git a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs index 4b80046487..dae746d001 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs @@ -160,8 +160,8 @@ fn match_read_call(expr: &Expr) -> Option<&Expr> { if method_name != "read" || !attr.value.is_name_expr() - || !call.arguments.args.is_empty() - || !call.arguments.keywords.is_empty() + || call.arguments.args().next().is_some() + || call.arguments.keywords().next().is_some() { return None; } @@ -179,8 +179,13 @@ fn make_suggestion(open: &FileOpen<'_>, generator: Generator) -> String { let call = ast::ExprCall { func: Box::new(name.into()), arguments: ast::Arguments { - args: [].into(), - keywords: open.keywords.iter().copied().cloned().collect(), + items: open + .keywords + .iter() + .copied() + .cloned() + .map(ast::Argument::Keyword) + .collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs index b9a2a0649b..96c20e35ee 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::name::QualifiedName; @@ -82,11 +83,11 @@ pub(crate) fn redundant_log_base( call: &ast::ExprCall, qualified_name: &QualifiedName, ) { - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - let [arg, base] = &*call.arguments.args else { + let Some([arg, base]) = call.arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index 55d24484b8..7ddb27de0f 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -100,7 +100,7 @@ pub(crate) fn reimplemented_starmap(checker: &Checker, target: &StarmapCandidate match value { // Ex) `f(*x) for x in iter` ComprehensionTarget::Name(name) => { - let [arg] = args else { + let [ast::Argument::Positional(arg)] = args.items.as_slice() else { return; }; @@ -122,7 +122,7 @@ pub(crate) fn reimplemented_starmap(checker: &Checker, target: &StarmapCandidate // Ex) `f(x, y, z) for x, y, z in iter` ComprehensionTarget::Tuple(tuple) => { if tuple.len() != args.len() - || std::iter::zip(tuple, args) + || std::iter::zip(tuple, args.args()) .any(|(x, y)| ComparableExpr::from(x) != ComparableExpr::from(y)) { return; @@ -320,8 +320,9 @@ fn construct_starmap_call(starmap_binding: Name, iter: &Expr, func: &Expr) -> as ast::ExprCall { func: Box::new(starmap.into()), arguments: ast::Arguments { - args: [func.clone(), iter.clone()].into(), - keywords: std::iter::empty().collect(), + items: [func.clone(), iter.clone()] + .map(ast::Argument::Positional) + .into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -341,8 +342,7 @@ fn wrap_with_call_to(call: ast::ExprCall, func_name: Name) -> ast::ExprCall { ast::ExprCall { func: Box::new(name.into()), arguments: ast::Arguments { - args: [call.into()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(call.into())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -374,16 +374,14 @@ fn match_comprehension_target( } /// Match that the given expression is `func(x, y, z, ...)`. -fn match_call(element: &Expr) -> Option<(&[Expr], &Expr)> { +fn match_call(element: &Expr) -> Option<(&ast::Arguments, &Expr)> { let ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. } = element.as_call_expr()?; - if !keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - Some((args, func)) + Some((arguments, func)) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index f28da1ba59..a6b1a6c653 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use rustc_hash::FxHashMap; use ast::traversal; @@ -275,9 +276,7 @@ fn match_append<'a>(semantic: &'a SemanticModel, stmt: &'a Stmt) -> Option(semantic: &'a SemanticModel, stmt: &'a Stmt) -> Option String { let call = ast::ExprCall { func: Box::new(attr.into()), arguments: ast::Arguments { - args: [tuple.into()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(tuple.into())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs index 5c23bdae1d..9c1a388df9 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_diagnostics::Applicability; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, PythonVersion}; @@ -295,11 +296,9 @@ fn affix_removal_data<'a>( .id .as_str(); - let func_args = &test.as_call_expr()?.arguments.args; + let func_args = test.as_call_expr()?.arguments.args(); - let [affix] = func_args.as_ref() else { - return None; - }; + let [affix] = func_args.collect_array()?; if compr_value != compr_test_expr || compr_test_expr != compr_else_or_target { return None; } diff --git a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs index cb04fa1de9..ba3cd229c1 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::Number; use ruff_python_ast::token::parenthesized_range; @@ -138,7 +139,7 @@ pub(crate) fn sorted_min_max(checker: &Checker, subscript: &ast::ExprSubscript) } // Check if the call to `sorted()` has a single argument. - let [list_expr] = arguments.args.as_ref() else { + let Some([list_expr]) = arguments.args().collect_array() else { return; }; @@ -146,7 +147,7 @@ pub(crate) fn sorted_min_max(checker: &Checker, subscript: &ast::ExprSubscript) let mut key_keyword_expr = None; // Check if the call to `sorted()` has the `reverse` and `key` keywords. - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { // If the call contains `**kwargs`, return. let Some(arg) = keyword.arg.as_ref() else { return; diff --git a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs index 6cbdc3247b..8921da61b5 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs @@ -1,5 +1,6 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{Arguments, StmtClassDef, helpers::map_subscript}; +use ruff_python_ast::{StmtClassDef, helpers::map_subscript}; use ruff_text_size::Ranged; use crate::codes::Category; @@ -91,12 +92,12 @@ pub(crate) fn subclass_builtin(checker: &Checker, class: &StmtClassDef) { return; } - let Some(Arguments { args: bases, .. }) = class.arguments.as_deref() else { + let Some(arguments) = class.arguments.as_deref() else { return; }; // Expect only one base class else return - let [base] = &**bases else { + let Some([base]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index 0f59b8b3c9..1953027309 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -105,7 +105,7 @@ pub(crate) fn unnecessary_enumerate(checker: &Checker, stmt_for: &ast::StmtFor) }; // Get the first argument, which is the sequence to iterate over. - let Some(Expr::Name(sequence)) = arguments.args.first() else { + let Some(Expr::Name(sequence)) = arguments.args().next() else { return; }; @@ -248,8 +248,7 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { .into(), ), arguments: Arguments { - args: [var.into()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(var.into())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, @@ -268,8 +267,7 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { .into(), ), arguments: Arguments { - args: [len.into()].into(), - keywords: std::iter::empty().collect(), + items: [ast::Argument::Positional(len.into())].into(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs index 570e20de66..373ab91a28 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_python_semantic::analyze::type_inference::{NumberLike, PythonType, ResolvedPythonType}; @@ -299,12 +300,10 @@ fn handle_non_finite_float_special_case( } // Must have exactly one argument, which is a string literal. - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - let [float_arg] = arguments.args.as_ref() else { - return None; - }; + let [float_arg] = arguments.args().collect_array()?; let normalized = as_non_finite_float_string_literal(float_arg)?; let replacement_text = format!( r#"{constructor_name}("{}")"#, diff --git a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs index 0efd3c5366..348e43a338 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs @@ -178,10 +178,10 @@ pub(crate) fn verbose_decimal_constructor( } // Must have exactly one argument, which is a string literal. - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [float] = arguments.args.as_ref() else { + let Some([float]) = arguments.args().collect_array() else { return; }; let Some(float_str) = as_non_finite_float_string_literal(float) else { diff --git a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs index 707ee269a7..2609cd5854 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs @@ -174,14 +174,14 @@ fn match_write_call(expr: &Expr) -> Option<(&Expr, &Expr)> { if method_name != "write" || !attr.value.is_name_expr() - || call.arguments.args.len() != 1 - || !call.arguments.keywords.is_empty() + || call.arguments.args().count() != 1 + || call.arguments.keywords().next().is_some() { return None; } // `write` only takes in a single positional argument. - Some((&*attr.value, call.arguments.args.first()?)) + Some((&*attr.value, call.arguments.args().next()?)) } fn make_suggestion(open: &FileOpen<'_>, arg: &Expr, locator: &Locator) -> String { diff --git a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__print-empty-string_FURB105.py.snap b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__print-empty-string_FURB105.py.snap index 3b5583ab03..408a991b6d 100644 --- a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__print-empty-string_FURB105.py.snap +++ b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__print-empty-string_FURB105.py.snap @@ -259,15 +259,15 @@ FURB105 [*] Unnecessary empty string passed to `print` 17 | print("", *args) 18 | print("", *args, sep="") | ^^^^^^^^^^^^^^^^^^^^^^^^ -19 | print("", **kwargs) -20 | print(sep="\t") +19 | print("", end="!", *args, sep="") +20 | print("", **kwargs) | help: Remove empty string | 17 | print("", *args) - print("", *args, sep="") 18 + print(*args, sep="") -19 | print("", **kwargs) +19 | print("", end="!", *args, sep="") | FURB105 [*] Unnecessary empty string passed to `print` @@ -275,160 +275,178 @@ FURB105 [*] Unnecessary empty string passed to `print` | 17 | print("", *args) 18 | print("", *args, sep="") -19 | print("", **kwargs) - | ^^^^^^^^^^^^^^^^^^^ -20 | print(sep="\t") -21 | print(sep=print(1)) +19 | print("", end="!", *args, sep="") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +20 | print("", **kwargs) +21 | print(sep="\t") | help: Remove empty string | 18 | print("", *args, sep="") - - print("", **kwargs) -19 + print(**kwargs) -20 | print(sep="\t") + - print("", end="!", *args, sep="") +19 + print(end="!", *args, sep="") +20 | print("", **kwargs) | -FURB105 [*] Unnecessary separator passed to `print` +FURB105 [*] Unnecessary empty string passed to `print` --> FURB105.py:20:1 | 18 | print("", *args, sep="") -19 | print("", **kwargs) -20 | print(sep="\t") - | ^^^^^^^^^^^^^^^ -21 | print(sep=print(1)) -22 | print(f"") +19 | print("", end="!", *args, sep="") +20 | print("", **kwargs) + | ^^^^^^^^^^^^^^^^^^^ +21 | print(sep="\t") +22 | print(sep=print(1)) | -help: Remove separator +help: Remove empty string | -19 | print("", **kwargs) - - print(sep="\t") -20 + print() -21 | print(sep=print(1)) +19 | print("", end="!", *args, sep="") + - print("", **kwargs) +20 + print(**kwargs) +21 | print(sep="\t") | FURB105 [*] Unnecessary separator passed to `print` --> FURB105.py:21:1 | -19 | print("", **kwargs) -20 | print(sep="\t") -21 | print(sep=print(1)) - | ^^^^^^^^^^^^^^^^^^^ -22 | print(f"") -23 | print(f"", sep=",") +19 | print("", end="!", *args, sep="") +20 | print("", **kwargs) +21 | print(sep="\t") + | ^^^^^^^^^^^^^^^ +22 | print(sep=print(1)) +23 | print(f"") | help: Remove separator | -20 | print(sep="\t") - - print(sep=print(1)) +20 | print("", **kwargs) + - print(sep="\t") 21 + print() -22 | print(f"") +22 | print(sep=print(1)) + | + +FURB105 [*] Unnecessary separator passed to `print` + --> FURB105.py:22:1 + | +20 | print("", **kwargs) +21 | print(sep="\t") +22 | print(sep=print(1)) + | ^^^^^^^^^^^^^^^^^^^ +23 | print(f"") +24 | print(f"", sep=",") + | +help: Remove separator + | +21 | print(sep="\t") + - print(sep=print(1)) +22 + print() +23 | print(f"") | note: This is an unsafe fix and may change runtime behavior FURB105 [*] Unnecessary empty string passed to `print` - --> FURB105.py:22:1 + --> FURB105.py:23:1 | -20 | print(sep="\t") -21 | print(sep=print(1)) -22 | print(f"") +21 | print(sep="\t") +22 | print(sep=print(1)) +23 | print(f"") | ^^^^^^^^^^ -23 | print(f"", sep=",") -24 | print(f"", end="bar") +24 | print(f"", sep=",") +25 | print(f"", end="bar") | help: Remove empty string | -21 | print(sep=print(1)) +22 | print(sep=print(1)) - print(f"") -22 + print() -23 | print(f"", sep=",") +23 + print() +24 | print(f"", sep=",") | FURB105 [*] Unnecessary empty string and separator passed to `print` - --> FURB105.py:23:1 + --> FURB105.py:24:1 | -21 | print(sep=print(1)) -22 | print(f"") -23 | print(f"", sep=",") +22 | print(sep=print(1)) +23 | print(f"") +24 | print(f"", sep=",") | ^^^^^^^^^^^^^^^^^^^ -24 | print(f"", end="bar") -25 | print(1, sep=None) +25 | print(f"", end="bar") +26 | print(1, sep=None) | help: Remove empty string and separator | -22 | print(f"") +23 | print(f"") - print(f"", sep=",") -23 + print() -24 | print(f"", end="bar") +24 + print() +25 | print(f"", end="bar") | FURB105 [*] Unnecessary empty string passed to `print` - --> FURB105.py:24:1 + --> FURB105.py:25:1 | -22 | print(f"") -23 | print(f"", sep=",") -24 | print(f"", end="bar") +23 | print(f"") +24 | print(f"", sep=",") +25 | print(f"", end="bar") | ^^^^^^^^^^^^^^^^^^^^^ -25 | print(1, sep=None) +26 | print(1, sep=None) | help: Remove empty string | -23 | print(f"", sep=",") +24 | print(f"", sep=",") - print(f"", end="bar") -24 + print(end="bar") -25 | print(1, sep=None) +25 + print(end="bar") +26 | print(1, sep=None) | FURB105 [*] Unnecessary separator passed to `print` - --> FURB105.py:25:1 + --> FURB105.py:26:1 | -23 | print(f"", sep=",") -24 | print(f"", end="bar") -25 | print(1, sep=None) +24 | print(f"", sep=",") +25 | print(f"", end="bar") +26 | print(1, sep=None) | ^^^^^^^^^^^^^^^^^^ -26 | -27 | def p(sep): +27 | +28 | def p(sep): | help: Remove separator | -24 | print(f"", end="bar") +25 | print(f"", end="bar") - print(1, sep=None) -25 + print(1) -26 | +26 + print(1) +27 | | FURB105 [*] Unnecessary separator passed to `print` - --> FURB105.py:28:5 + --> FURB105.py:29:5 | -27 | def p(sep): -28 | print(1, sep=sep) +28 | def p(sep): +29 | print(1, sep=sep) | ^^^^^^^^^^^^^^^^^ -29 | -30 | # OK. +30 | +31 | # OK. | help: Remove separator | -27 | def p(sep): +28 | def p(sep): - print(1, sep=sep) -28 + print(1) -29 | +29 + print(1) +30 | | note: This is an unsafe fix and may change runtime behavior FURB105 [*] Unnecessary empty string passed to `print` - --> FURB105.py:46:1 + --> FURB105.py:47:1 | -46 | / print( -47 | | # text -48 | | "" -49 | | ) +47 | / print( +48 | | # text +49 | | "" +50 | | ) | |_^ help: Remove empty string | -45 | +46 | - print( - # text - "" - ) -46 + print() +47 + print() | note: This is an unsafe fix and may change runtime behavior diff --git a/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs b/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs index 8da952e106..8c4e9236d3 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs @@ -127,7 +127,7 @@ pub(crate) fn access_annotations_from_class_dict_with_get(checker: &Checker, cal // - One or two positional arguments. // - First positional argument must be the string literal "__annotations__". // - The value of the second positional argument (if present) does not affect the match. - if !call.arguments.keywords.is_empty() || call.arguments.len() > 2 { + if call.arguments.keywords().next().is_some() || call.arguments.len() > 2 { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs index bab669f7b6..df84b961e9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs @@ -275,10 +275,10 @@ mod print_arguments { .and_then( // If the `sep` argument is `None`, treat this as default behavior. |keyword| { - if let Expr::NoneLiteral(_) = keyword.value { + if let Expr::NoneLiteral(_) = keyword.value.as_ref() { None } else { - Some(&keyword.value) + Some(keyword.value.as_ref()) } }, ) @@ -294,8 +294,7 @@ mod print_arguments { }); let args = arguments - .args - .iter() + .args() .map(expr_to_fstring_elements) .collect::>(); diff --git a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs index 8546e7b34b..4f1d82fb3e 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs @@ -59,7 +59,7 @@ pub(crate) fn decimal_from_float_literal_syntax( call: &ast::ExprCall, qualified_name: &QualifiedName, ) { - let Some(arg) = call.arguments.args.first() else { + let Some(arg) = call.arguments.args().next() else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs index 2b7a01cc35..ef7a7c2ed0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs @@ -92,7 +92,7 @@ pub(crate) fn default_factory_kwarg( } // If the user provided a positional argument for `default_factory`, return. - if !call.arguments.args.is_empty() { + if call.arguments.args().next().is_some() { return; } @@ -144,7 +144,7 @@ fn convert_to_positional( if call.arguments.len() == 1 { // Ex) `defaultdict(default_factory=list)` Ok(Fix::unsafe_edit(Edit::range_replacement( - locator.slice(&default_factory.value).to_string(), + locator.slice(&*default_factory.value).to_string(), default_factory.range(), ))) } else { @@ -161,7 +161,7 @@ fn convert_to_positional( // Second, insert the value as the first positional argument. let insertion_edit = Edit::insertion( - format!("{}, ", locator.slice(&default_factory.value)), + format!("{}, ", locator.slice(&*default_factory.value)), call.arguments .iter_source_order() .next() diff --git a/crates/ruff_linter/src/rules/ruff/rules/duplicate_entry_in_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/duplicate_entry_in_dunder_all.rs index af95d25aa3..3f37237075 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/duplicate_entry_in_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/duplicate_entry_in_dunder_all.rs @@ -89,12 +89,10 @@ pub(crate) fn duplicate_entry_in_dunder_all_aug_assign( pub(crate) fn duplicate_entry_in_dunder_all_extend_call( checker: &Checker, ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. }: &ast::ExprCall, ) { - let ([value_passed], []) = (&**args, &**keywords) else { + let [ast::Argument::Positional(value_passed)] = arguments.items.as_slice() else { return; }; let ast::Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = &**func else { diff --git a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index b3240c7ab5..dc11078cbc 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::fmt::Display; use anyhow::Result; @@ -100,12 +101,12 @@ pub(crate) fn explicit_f_string_type_conversion(checker: &Checker, f_string: &as } Conversion::Str | Conversion::Repr | Conversion::Ascii => { // Can't be a conversion otherwise. - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { continue; } // Can't be a conversion otherwise. - let [arg] = call.arguments.args.as_ref() else { + let Some([arg]) = call.arguments.args().collect_array() else { continue; }; arg diff --git a/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs b/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs index a2055d50b4..3980de3bc1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs @@ -107,12 +107,12 @@ pub(crate) fn falsy_dict_get_fallback(checker: &Checker, expr: &Expr) { let mut diagnostic = checker.report_diagnostic(FalsyDictGetFallback, fallback_arg.range()); // All arguments to `dict.get` are positional-only. - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } // And there are only two of them, at most. - if call.arguments.args.len() > 2 { + if call.arguments.args().nth(2).is_some() { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/float_equality_comparison.rs b/crates/ruff_linter/src/rules/ruff/rules/float_equality_comparison.rs index 8d388cabfa..dfbf49f8ef 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/float_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/float_equality_comparison.rs @@ -180,9 +180,7 @@ fn should_skip_comparison(expr: &Expr, semantic: &SemanticModel) -> bool { .iter() .any(|s| semantic.match_builtin_expr(func, s)) { - return arguments.args.len() == 1 - && arguments.keywords.is_empty() - && is_infinity_string_literal(&arguments.args[0]).is_some(); + return matches!(arguments.items.as_slice(), [ast::Argument::Positional(arg)] if is_infinity_string_literal(arg).is_some()); } false diff --git a/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs b/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs index 9aad74cebb..c2b742c7e9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs @@ -1,4 +1,3 @@ -use itertools::{Either, Itertools}; use ruff_diagnostics::{Edit, Fix}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::name::QualifiedName; @@ -208,7 +207,7 @@ fn try_fix_legacy_call( PytestContextType::from_expr_name(&inner_call.func, semantic) == Some(PytestContextType::Raises) })?; - let match_arg = call.arguments.args.first(); + let match_arg = call.arguments.args().next(); generate_with_statement(context_type, inner_raises_call, match_arg, None, None) } else { None @@ -254,14 +253,13 @@ fn generate_with_statement( .arguments .find_argument_value(func_arg_name, func_arg_position)?; - let (func_args, func_keywords): (Vec<_>, Vec<_>) = legacy_call + let func_args = legacy_call .arguments - .iter_source_order() + .items + .iter() .skip(if expected.is_some() { 2 } else { 1 }) - .partition_map(|arg_or_keyword| match arg_or_keyword { - ast::ArgOrKeyword::Arg(expr) => Either::Left(expr.clone()), - ast::ArgOrKeyword::Keyword(keyword) => Either::Right(keyword.clone()), - }); + .cloned() + .collect(); let context_call = ast::ExprCall { node_index: AtomicNodeIndex::NONE, @@ -270,18 +268,19 @@ fn generate_with_statement( arguments: ast::Arguments { node_index: AtomicNodeIndex::NONE, range: TextRange::default(), - args: expected.cloned().as_slice().into(), - keywords: match_arg - .map(|expr| ast::Keyword { - node_index: AtomicNodeIndex::NONE, - // Take range from the original expression so that the keyword - // argument is generated after positional arguments - range: expr.range(), - arg: Some(ast::Identifier::new("match", TextRange::default())), - value: expr.clone(), - }) - .as_slice() - .into(), + items: expected + .cloned() + .into_iter() + .map(ast::Argument::Positional) + .chain(match_arg.map(|expr| { + ast::Argument::Keyword(ast::Keyword { + node_index: AtomicNodeIndex::NONE, + range: expr.range(), + arg: Some(ast::Identifier::new("match", TextRange::default())), + value: Box::new(expr.clone()), + }) + })) + .collect(), }, }; @@ -292,8 +291,7 @@ fn generate_with_statement( arguments: ast::Arguments { node_index: AtomicNodeIndex::NONE, range: TextRange::default(), - args: func_args.into(), - keywords: func_keywords.into(), + items: func_args, }, }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/logging_eager_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/logging_eager_conversion.rs index c7fee1d9f8..a918f0e679 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/logging_eager_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/logging_eager_conversion.rs @@ -140,8 +140,7 @@ pub(crate) fn logging_eager_conversion(checker: &Checker, call: &ast::ExprCall) }) .zip( call.arguments - .args - .iter() + .args() .skip(msg_pos + 1) .take_while(|arg| !arg.is_starred_expr()), ) diff --git a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs index 132d6f309c..7e38550d99 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs @@ -65,22 +65,16 @@ fn map_call_with_two_arguments<'a>( ) -> Option<(&'a ast::Expr, &'a ast::Expr)> { let ast::ExprCall { func, - arguments: - ast::Arguments { - args, - keywords, - range: _, - node_index: _, - }, + arguments, range_start: _, node_index: _, } = call; - if !keywords.is_empty() { - return None; - } - - let [first, second] = &**args else { + let [ + ast::Argument::Positional(first), + ast::Argument::Positional(second), + ] = arguments.items.as_slice() + else { return None; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs index 47cd6ccb6d..671d982f6b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs @@ -223,13 +223,13 @@ fn should_be_fstring( .current_expressions() .filter_map(ast::Expr::as_call_expr) { - let ast::Arguments { keywords, args, .. } = &expr.arguments; - for keyword in keywords { + let arguments = &expr.arguments; + for keyword in arguments.keywords() { if let Some(ident) = keyword.arg.as_ref() { arg_names.insert(&ident.id); } } - for arg in args { + for arg in arguments.args() { if let ast::Expr::Name(ast::ExprName { id, .. }) = arg { arg_names.insert(id); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs index 04552bfa77..a3d8bffc53 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs @@ -1,5 +1,6 @@ use crate::codes::Category; use crate::fix::edits::fresh_binding_name; +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{SemanticModel, analyze::typing::is_mutable_expr}; @@ -82,7 +83,7 @@ pub(crate) fn mutable_fromkeys_value(checker: &Checker, call: &ast::ExprCall) { } // Check that the value parameter is a mutable object. - let [keys, value] = &*call.arguments.args else { + let Some([keys, value]) = call.arguments.args().collect_array() else { return; }; if !is_mutable_expr(value, semantic) { diff --git a/crates/ruff_linter/src/rules/ruff/rules/non_octal_permissions.rs b/crates/ruff_linter/src/rules/ruff/rules/non_octal_permissions.rs index e6ac5dce3d..8a20e621b9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/non_octal_permissions.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/non_octal_permissions.rs @@ -192,7 +192,7 @@ fn find_func_parent_mode_arg<'a>(call: &'a ExprCall, semantic: &SemanticModel) - } call.arguments .find_keyword("parent_mode") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) } fn find_method_parent_mode_arg<'a>( @@ -205,7 +205,7 @@ fn find_method_parent_mode_arg<'a>( (["pathlib", "Path" | "PosixPath" | "WindowsPath"], "mkdir") => call .arguments .find_keyword("parent_mode") - .map(|keyword| &keyword.value), + .map(|keyword| keyword.value.as_ref()), _ => None, } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs b/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs index 9dc4872fb3..de2979bfb8 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs @@ -97,7 +97,7 @@ pub(crate) fn pytest_raises_ambiguous_pattern( return; }; - let ast::Expr::StringLiteral(string) = value else { + let ast::Expr::StringLiteral(string) = value.as_ref() else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index fa5e8809b4..1a136366cf 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -118,7 +118,7 @@ pub(crate) fn quadratic_list_summation(checker: &Checker, call: &ast::ExprCall) node_index: _, } = call; - let Some(iterable) = arguments.args.first() else { + let Some(iterable) = arguments.args().next() else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs index 12ab5752be..0957cd08ef 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs @@ -138,12 +138,10 @@ pub(crate) fn sort_dunder_all_aug_assign(checker: &Checker, node: &ast::StmtAugA pub(crate) fn sort_dunder_all_extend_call( checker: &Checker, ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. }: &ast::ExprCall, ) { - let ([value_passed], []) = (&**args, &**keywords) else { + let [ast::Argument::Positional(value_passed)] = arguments.items.as_slice() else { return; }; let ast::Expr::Attribute(ast::ExprAttribute { diff --git a/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs b/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs index 3873190505..63b8e57009 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::PythonVersion; use ruff_python_ast::name::QualifiedName; @@ -63,38 +64,37 @@ impl Violation for StarmapZip { pub(crate) fn starmap_zip(checker: &Checker, call: &ExprCall, qualified_name: &QualifiedName) { let semantic = checker.semantic(); - if !call.arguments.keywords.is_empty() { + if call.arguments.keywords().next().is_some() { return; } - let [_map_func, Expr::Call(iterable_call)] = &*call.arguments.args else { + let Some([_map_func, Expr::Call(iterable_call)]) = call.arguments.args().collect_array() else { return; }; - let keywords = &iterable_call.arguments.keywords; + let mut keywords = iterable_call.arguments.keywords(); match checker.target_version().cmp(&PythonVersion::PY314) { // Keyword arguments not supported for `map` before Python 3.14 std::cmp::Ordering::Less => { - if !keywords.is_empty() { + if keywords.next().is_some() { return; } } // Only supported keyword argument is `strict` starting in 3.14 std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => { - if keywords.len() > 1 { - return; - } - if keywords.len() == 1 && iterable_call.arguments.find_keyword("strict").is_none() { + if let Some(keyword) = keywords.next() + && (keyword.arg.as_deref() != Some("strict") || keywords.next().is_some()) + { return; } } } - let positionals = &iterable_call.arguments.args; + let mut positionals = iterable_call.arguments.args().peekable(); // `zip(*a)` where `a` is empty is valid, but `map(_, *a)` isn't. - if !positionals.is_empty() && positionals.iter().all(Expr::is_starred_expr) { + if positionals.peek().is_some() && positionals.all(Expr::is_starred_expr) { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs index bc29718a9f..6fcb312c7a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{Arguments, Expr, ExprCall}; use ruff_python_edits::unwrapped_call_argument; @@ -158,13 +159,11 @@ fn single_argument_to_int_call<'a>( return None; } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return None; } - let [argument] = &*arguments.args else { - return None; - }; + let [argument] = arguments.args().collect_array()?; Some(argument) } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index ac3605d09b..7bc29b9c8b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -1,7 +1,8 @@ +use itertools::Itertools; use std::borrow::Cow; use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Arguments, Comprehension, Expr, Int}; +use ruff_python_ast::{self as ast, Comprehension, Expr, Int}; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::builtins::is_iterator; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -87,10 +88,10 @@ pub(crate) fn unnecessary_iterable_allocation_for_first_element(checker: &Checke Expr::Call(ast::ExprCall { func, arguments, .. }) => { - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return; } - let [arg] = arguments.args.as_ref() else { + let Some([arg]) = arguments.args().collect_array() else { return; }; if !is_zero(arg) { @@ -161,13 +162,9 @@ struct IterationTarget { fn match_iteration_target(expr: &Expr, semantic: &SemanticModel) -> Option { let result = match expr { Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) => { - let [arg] = &**args else { - return None; - }; + let [arg] = arguments.args().collect_array()?; let builtin_function_name = semantic.resolve_builtin_symbol(func)?; if !matches!(builtin_function_name, "tuple" | "list") { diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs index 857903d5de..54be4cccac 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs @@ -124,7 +124,7 @@ pub(crate) fn unnecessary_literal_within_deque_call( // Return without a fix in the presence of a starred argument because we can't accurately // generate the fix. If all of the arguments are unpacked (e.g. `deque(*([], 10))`), we will // have already returned after the first `find_argument_value` call. - if deque.arguments.args.iter().any(Expr::is_starred_expr) { + if deque.arguments.args().any(Expr::is_starred_expr) { return; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs index 5306814225..e589613100 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs @@ -1,5 +1,6 @@ use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::Argument; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{ Arguments, CmpOp, Expr, ExprAttribute, ExprBytesLiteral, ExprCall, ExprCompare, ExprContext, @@ -355,8 +356,7 @@ impl<'a> ReFunc<'a> { Expr::Call(ExprCall { func: Box::new(method), arguments: Arguments { - args: args.into(), - keywords: std::iter::empty().collect(), + items: args.into_iter().map(Argument::Positional).collect(), range: TextRange::default(), node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression_compile.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression_compile.rs index 023e49e9c2..201a055108 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression_compile.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression_compile.rs @@ -1,4 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::Argument; use ruff_python_ast::{Arguments, Expr, ExprAttribute, ExprCall}; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -88,15 +89,12 @@ pub(crate) fn unnecessary_regular_expression_compile(checker: &Checker, call: &E /// `split` are a positional prefix of the top-level functions', so any explicit argument shape /// reduces; unpacked (`*`/`**`) arguments have an unknown shape and never reduce. fn reducible_re_method(attr: &str, arguments: &Arguments) -> Option<&'static str> { - if arguments.args.iter().any(Expr::is_starred_expr) - || arguments - .keywords - .iter() - .any(|keyword| keyword.arg.is_none()) + if arguments.args().any(Expr::is_starred_expr) + || arguments.keywords().any(|keyword| keyword.arg.is_none()) { return None; } - let only_string_argument = arguments.args.len() == 1 && arguments.keywords.is_empty(); + let only_string_argument = matches!(arguments.items.as_slice(), [Argument::Positional(_)]); Some(match attr { "search" if only_string_argument => "search", "match" if only_string_argument => "match", diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs index 583c3ad0f6..95807647dd 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs @@ -155,11 +155,11 @@ pub(super) fn rounded_and_ndigits<'a>( } // *args - if arguments.args.iter().any(Expr::is_starred_expr) { + if arguments.args().any(Expr::is_starred_expr) { return None; } // **kwargs - if arguments.keywords.iter().any(|kw| kw.arg.is_none()) { + if arguments.keywords().any(|kw| kw.arg.is_none()) { return None; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs index 200bbfeb24..b0a8a7bf29 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs @@ -148,7 +148,7 @@ pub(crate) fn unraw_re_pattern(checker: &Checker, call: &ExprCall) { return; }; - match call.arguments.args.as_ref().first() { + match call.arguments.args().next() { Some(Expr::StringLiteral(ExprStringLiteral { value, .. })) => { value .iter() diff --git a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs index b126de3750..dc5f28a8b2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs @@ -1,5 +1,6 @@ +use itertools::Itertools; use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Arguments, Expr, Int}; +use ruff_python_ast::{self as ast, Expr, Int}; use ruff_text_size::Ranged; use crate::codes::Category; @@ -115,13 +116,11 @@ fn match_slice_info(expr: &Expr) -> Option { /// RUF007 pub(crate) fn zip_instead_of_pairwise(checker: &Checker, call: &ast::ExprCall) { let ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. } = call; // Require exactly two positional arguments. - let [first, second] = args.as_ref() else { + let Some([first, second]) = arguments.args().collect_array() else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__legacy-form-pytest-raises_RUF061_raises.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__legacy-form-pytest-raises_RUF061_raises.py.snap index 64e072723c..05042aef53 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__legacy-form-pytest-raises_RUF061_raises.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__legacy-form-pytest-raises_RUF061_raises.py.snap @@ -66,34 +66,50 @@ help: Use `pytest.raises()` as a context-manager note: This is an unsafe fix and may change runtime behavior RUF061 [*] Use context-manager form of `pytest.raises()` - --> RUF061_raises.py:35:15 - | -34 | def test_error_multi_statement(): -35 | excinfo = pytest.raises(ValueError, int, "hello") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -36 | assert excinfo.match("^invalid literal") + --> RUF061_raises.py:35:5 | +34 | def test_error_mixed_argument_order(args): +35 | pytest.raises(ZeroDivisionError, func, b=0, *args) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `pytest.raises()` as a context-manager | -34 | def test_error_multi_statement(): - - excinfo = pytest.raises(ValueError, int, "hello") -35 + with pytest.raises(ValueError) as excinfo: -36 + int("hello") -37 | assert excinfo.match("^invalid literal") +34 | def test_error_mixed_argument_order(args): + - pytest.raises(ZeroDivisionError, func, b=0, *args) +35 + with pytest.raises(ZeroDivisionError): +36 + func(b=0, *args) +37 | | note: This is an unsafe fix and may change runtime behavior RUF061 [*] Use context-manager form of `pytest.raises()` - --> RUF061_raises.py:40:5 + --> RUF061_raises.py:39:15 | -39 | def test_error_lambda(): -40 | pytest.raises(ZeroDivisionError, lambda: 1 / 0) +38 | def test_error_multi_statement(): +39 | excinfo = pytest.raises(ValueError, int, "hello") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +40 | assert excinfo.match("^invalid literal") + | +help: Use `pytest.raises()` as a context-manager + | +38 | def test_error_multi_statement(): + - excinfo = pytest.raises(ValueError, int, "hello") +39 + with pytest.raises(ValueError) as excinfo: +40 + int("hello") +41 | assert excinfo.match("^invalid literal") + | +note: This is an unsafe fix and may change runtime behavior + +RUF061 [*] Use context-manager form of `pytest.raises()` + --> RUF061_raises.py:44:5 + | +43 | def test_error_lambda(): +44 | pytest.raises(ZeroDivisionError, lambda: 1 / 0) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `pytest.raises()` as a context-manager | -39 | def test_error_lambda(): +43 | def test_error_lambda(): - pytest.raises(ZeroDivisionError, lambda: 1 / 0) -40 + with pytest.raises(ZeroDivisionError): -41 + (lambda: 1 / 0)() +44 + with pytest.raises(ZeroDivisionError): +45 + (lambda: 1 / 0)() | note: This is an unsafe fix and may change runtime behavior diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs index 766ba4c275..c405843736 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs @@ -1,5 +1,5 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::{self as ast, Arguments, Expr}; +use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; use crate::Violation; @@ -58,15 +58,13 @@ impl Violation for RaiseExceptionWithMessage { /// TRY003 pub(crate) fn raise_vanilla_args(checker: &Checker, expr: &Expr) { let Expr::Call(ast::ExprCall { - func, - arguments: Arguments { args, .. }, - .. + func, arguments, .. }) = expr else { return; }; - let Some(arg) = args.first() else { + let Some(arg) = arguments.args().next() else { return; }; diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs index c51036eb5f..e796528fd7 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs @@ -67,8 +67,7 @@ pub(crate) fn verbose_log_message(checker: &Checker, handlers: &[ExceptHandler]) // Collect all referenced names in the `logging.exception` call. let names: Vec<&ast::ExprName> = { expr.arguments - .args - .iter() + .args() .flat_map(|arg| { let mut visitor = NameVisitor::default(); visitor.visit_expr(arg); diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index 0704036465..d641d5b0d8 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -443,24 +443,58 @@ type ComparableComprehensionSlice<'a> = ComparableSlice<'a, ast::Comprehension, ComparableComprehension<'a>>; type ComparableExprSlice<'a> = ComparableSlice<'a, Expr, ComparableExpr<'a>>; -#[derive(Debug, Default, PartialEq, Eq, Hash)] -struct ComparableArguments<'a> { - args: ComparableExprSlice<'a>, - keywords: ComparableSlice<'a, ast::Keyword, ComparableKeyword<'a>>, +#[derive(Default)] +struct ComparableArguments<'a>(&'a [ast::Argument]); + +#[derive(Debug, PartialEq, Eq, Hash)] +enum ComparableArgument<'a> { + Positional(ComparableExpr<'a>), + Keyword(ComparableKeyword<'a>), +} + +impl<'a> ComparableArguments<'a> { + fn iter(&self) -> impl Iterator> { + // Calls evaluate all positional arguments before their keywords, including a starred + // argument written after a named argument. + let positional = self.0.iter().filter_map(ast::Argument::as_positional); + let keywords = self.0.iter().filter_map(ast::Argument::as_keyword); + positional + .map(|expr| ComparableArgument::Positional(expr.into())) + .chain(keywords.map(|keyword| ComparableArgument::Keyword(keyword.into()))) + } +} + +impl fmt::Debug for ComparableArguments<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_list().entries(self.iter()).finish() + } +} + +impl PartialEq for ComparableArguments<'_> { + fn eq(&self, other: &Self) -> bool { + self.0.len() == other.0.len() && self.iter().eq(other.iter()) + } +} + +impl Eq for ComparableArguments<'_> {} + +impl Hash for ComparableArguments<'_> { + fn hash(&self, state: &mut H) { + self.0.len().hash(state); + for argument in self.iter() { + argument.hash(state); + } + } } impl<'a> From<&'a ast::Arguments> for ComparableArguments<'a> { fn from(arguments: &'a ast::Arguments) -> Self { let ast::Arguments { - args, - keywords, + items, range: _, node_index: _, } = arguments; - Self { - args: ComparableSlice::new(args), - keywords: ComparableSlice::new(keywords), - } + Self(items) } } @@ -580,7 +614,7 @@ impl<'a> From<&'a ast::Keyword> for ComparableKeyword<'a> { } = keyword; Self { arg: arg.as_ref().map(ast::Identifier::as_str), - value: value.into(), + value: value.as_ref().into(), } } } diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 23da0a11b1..523fa3c06a 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -12,7 +12,7 @@ use crate::statement_visitor::StatementVisitor; use crate::token::{Tokens, parenthesized_range}; use crate::visitor::Visitor; use crate::{ - self as ast, Arguments, AtomicNodeIndex, CmpOp, DictItem, ExceptHandler, Expr, ExprNoneLiteral, + self as ast, AtomicNodeIndex, CmpOp, DictItem, ExceptHandler, Expr, ExprNoneLiteral, InterpolatedStringElement, MatchCase, Operator, Pattern, Stmt, TypeParam, }; use crate::{AnyNodeRef, ExprContext}; @@ -401,13 +401,9 @@ where // Note that this is the evaluation order but not necessarily the declaration order // (e.g. for `f(*args, a=2, *args2, **kwargs)` it's not) any_over_expr(call_func, &mut *func) + || arguments.args().any(|expr| any_over_expr(expr, &mut *func)) || arguments - .args - .iter() - .any(|expr| any_over_expr(expr, &mut *func)) - || arguments - .keywords - .iter() + .keywords() .any(|keyword| any_over_expr(&keyword.value, &mut *func)) } Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { @@ -565,20 +561,16 @@ where }) => { // Note that e.g. `class A(*args, a=2, *args2, **kwargs): pass` is a valid class // definition - arguments - .as_deref() - .is_some_and(|Arguments { args, keywords, .. }| { - args.iter().any(|expr| any_over_expr(expr, &mut *func)) - || keywords - .iter() - .any(|keyword| any_over_expr(&keyword.value, &mut *func)) - }) - || type_params.as_ref().is_some_and(|type_params| { - type_params - .iter() - .any(|type_param| any_over_type_param(type_param, &mut *func)) - }) - || body.iter().any(|stmt| any_over_stmt(stmt, &mut *func)) + arguments.as_deref().is_some_and(|arguments| { + arguments.args().any(|expr| any_over_expr(expr, &mut *func)) + || arguments + .keywords() + .any(|keyword| any_over_expr(&keyword.value, &mut *func)) + }) || type_params.as_ref().is_some_and(|type_params| { + type_params + .iter() + .any(|type_param| any_over_type_param(type_param, &mut *func)) + }) || body.iter().any(|stmt| any_over_stmt(stmt, &mut *func)) || decorator_list .iter() .any(|decorator| any_over_expr(&decorator.expression, &mut *func)) @@ -1481,8 +1473,8 @@ impl Truthiness { if arguments.is_empty() { // Ex) `list()` Self::Falsey - } else if let [argument] = &*arguments.args - && arguments.keywords.is_empty() + } else if let [ast::Argument::Positional(argument)] = + arguments.items.as_slice() { // Ex) `list([1, 2, 3])` match argument { diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index c0b185349a..751243c70f 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -31,19 +31,15 @@ use crate::{ impl StmtClassDef { /// Return an iterator over the bases of the class. - pub fn bases(&self) -> &[Expr] { - match &self.arguments { - Some(arguments) => &arguments.args, - None => &[], - } + pub fn bases(&self) -> impl DoubleEndedIterator + FusedIterator + Clone { + self.arguments.iter().flat_map(|arguments| arguments.args()) } - /// Return an iterator over the metaclass keywords of the class. - pub fn keywords(&self) -> &[Keyword] { - match &self.arguments { - Some(arguments) => &arguments.keywords, - None => &[], - } + /// Return the keyword arguments in the class header. + pub fn keywords(&self) -> impl DoubleEndedIterator + FusedIterator + Clone { + self.arguments + .iter() + .flat_map(|arguments| arguments.keywords()) } } @@ -3067,7 +3063,9 @@ pub struct Keyword { pub range: TextRange, pub node_index: AtomicNodeIndex, pub arg: Option, - pub value: Expr, + // Every argument takes up the same space in `Arguments::items`. Boxing the value + // keeps positional arguments from reserving space for both an expression and a keyword name. + pub value: Box, } /// See also [alias](https://docs.python.org/3/library/ast.html#ast.alias) @@ -3636,14 +3634,43 @@ impl ParameterWithDefault { /// In the context of a class definition, the Python-style AST refers to the arguments as `bases`, /// as they represent the "explicitly specified base classes", while the keyword arguments are /// typically used for `metaclass`, with any additional arguments being passed to the `metaclass`. - #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "get-size", derive(get_size2::GetSize))] pub struct Arguments { pub range: TextRange, pub node_index: AtomicNodeIndex, - pub args: ThinVec, - pub keywords: ThinVec, + pub items: ThinVec, +} + +/// A positional or keyword argument, stored in the order it appears in the source. +#[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))] +pub enum Argument { + Positional(Expr), + Keyword(Keyword), +} + +impl Argument { + pub fn as_positional(&self) -> Option<&Expr> { + match self { + Self::Positional(expr) => Some(expr), + Self::Keyword(_) => None, + } + } + + pub fn as_keyword(&self) -> Option<&Keyword> { + match self { + Self::Keyword(keyword) => Some(keyword), + Self::Positional(_) => None, + } + } + + pub fn as_ref(&self) -> ArgOrKeyword<'_> { + match self { + Self::Positional(expr) => ArgOrKeyword::Arg(expr), + Self::Keyword(keyword) => ArgOrKeyword::Keyword(keyword), + } + } } /// An entry in the argument list of a function call. @@ -3705,9 +3732,27 @@ impl Ranged for ArgOrKeyword<'_> { } impl Arguments { + /// Return the argument if the call contains exactly one positional argument and no keywords. + pub fn as_single_positional(&self) -> Option<&Expr> { + let [Argument::Positional(arg)] = self.items.as_slice() else { + return None; + }; + Some(arg) + } + + /// Positional arguments, including iterable unpacking. + pub fn args(&self) -> impl DoubleEndedIterator + FusedIterator + Clone { + self.items.iter().filter_map(Argument::as_positional) + } + + /// Keyword arguments, including mapping unpacking. + pub fn keywords(&self) -> impl DoubleEndedIterator + FusedIterator + Clone { + self.items.iter().filter_map(Argument::as_keyword) + } + /// Return the number of positional and keyword arguments. pub fn len(&self) -> usize { - self.args.len() + self.keywords.len() + self.items.len() } /// Return `true` if there are no positional or keyword arguments. @@ -3717,7 +3762,7 @@ impl Arguments { /// Return the [`Keyword`] with the given name, or `None` if no such [`Keyword`] exists. pub fn find_keyword(&self, keyword_name: &str) -> Option<&Keyword> { - self.keywords.iter().find(|keyword| { + self.keywords().find(|keyword| { let Keyword { arg, .. } = keyword; arg.as_ref().is_some_and(|arg| arg == keyword_name) }) @@ -3725,8 +3770,7 @@ impl Arguments { /// Return the positional argument at the given index, or `None` if no such argument exists. pub fn find_positional(&self, position: usize) -> Option<&Expr> { - self.args - .iter() + self.args() .take_while(|expr| !expr.is_starred_expr()) .nth(position) } @@ -3759,35 +3803,13 @@ impl Arguments { /// ``` /// where `*args` and `args2` are `args` while `a=1` and `kwargs` are `keywords`. /// - /// If you would just chain `args` and `keywords` the call would get reordered which we don't - /// want. This function instead "merge sorts" them into the correct order. - /// - /// Note that the order of evaluation is always first `args`, then `keywords`: - /// ```python - /// def f(*args, **kwargs): - /// pass - /// - /// def g(x): - /// print(x) - /// return x - /// - /// - /// f(*g([1]), a=g(2), *g([3]), **g({"4": 5})) - /// ``` - /// Output: - /// ```text - /// [1] - /// [3] - /// 2 - /// {'4': 5} - /// ``` - pub fn iter_source_order(&self) -> ArgumentsSourceOrder<'_> { - ArgumentsSourceOrder { - args: &self.args, - keywords: &self.keywords, - next_arg: 0, - next_keyword: 0, - } + /// Python evaluates positional arguments before keyword arguments, even when a starred + /// argument appears after a keyword. Evaluation-order visitors use the two groups separately. + pub fn iter_source_order( + &self, + ) -> impl DoubleEndedIterator> + ExactSizeIterator + FusedIterator + Clone + { + self.items.iter().map(Argument::as_ref) } pub fn inner_range(&self) -> TextRange { @@ -3803,38 +3825,6 @@ impl Arguments { } } -/// The iterator returned by [`Arguments::iter_source_order`]. -#[derive(Clone)] -pub struct ArgumentsSourceOrder<'a> { - args: &'a [Expr], - keywords: &'a [Keyword], - next_arg: usize, - next_keyword: usize, -} - -impl<'a> Iterator for ArgumentsSourceOrder<'a> { - type Item = ArgOrKeyword<'a>; - - fn next(&mut self) -> Option { - let arg = self.args.get(self.next_arg); - let keyword = self.keywords.get(self.next_keyword); - - if let Some(arg) = arg - && keyword.is_none_or(|keyword| arg.start() <= keyword.start()) - { - self.next_arg += 1; - Some(ArgOrKeyword::Arg(arg)) - } else if let Some(keyword) = keyword { - self.next_keyword += 1; - Some(ArgOrKeyword::Keyword(keyword)) - } else { - None - } - } -} - -impl FusedIterator for ArgumentsSourceOrder<'_> {} - /// An AST node used to represent a sequence of type parameters. /// /// For example, given: @@ -4147,7 +4137,9 @@ mod tests { assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 64); assert_eq!(std::mem::size_of::(), 40); - assert_eq!(std::mem::size_of::(), 32); + assert_eq!(std::mem::size_of::(), 24); + assert_eq!(std::mem::size_of::(), 64); + assert_eq!(std::mem::size_of::(), 56); assert_eq!(std::mem::size_of::(), 56); assert_eq!(std::mem::size_of::(), 56); assert_eq!(std::mem::size_of::(), 24); @@ -4155,7 +4147,7 @@ mod tests { assert_eq!(std::mem::size_of::(), 40); assert_eq!(std::mem::size_of::(), 16); assert_eq!(std::mem::size_of::(), 48); - assert_eq!(std::mem::size_of::(), 48); + assert_eq!(std::mem::size_of::(), 40); assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 40); assert_eq!(std::mem::size_of::(), 48); diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index bb81f5b19b..93a74aa7af 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -4,11 +4,11 @@ pub mod source_order; pub mod transformer; use crate::{ - self as ast, Alias, AnyParameterRef, Arguments, BoolOp, BytesLiteral, CmpOp, Comprehension, - Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, FString, FStringPartRef, - InterpolatedStringElement, Keyword, MatchCase, Operator, Parameter, Parameters, Pattern, - PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TypeParam, TypeParamParamSpec, - TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem, + self as ast, Alias, AnyParameterRef, Argument, Arguments, BoolOp, BytesLiteral, CmpOp, + Comprehension, Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, FString, + FStringPartRef, InterpolatedStringElement, Keyword, MatchCase, Operator, Parameter, Parameters, + Pattern, PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TypeParam, + TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem, }; /// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order. @@ -656,13 +656,22 @@ pub fn walk_except_handler<'a, V: Visitor<'a> + ?Sized>( } pub fn walk_arguments<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, arguments: &'a Arguments) { - // Note that there might be keywords before the last arg, e.g. in - // f(*args, a=2, *args2, **kwargs)`, but we follow Python in evaluating first `args` and then - // `keywords`. See also [Arguments::arguments_source_order`]. - for arg in &*arguments.args { + // In `f(first(), key=second(), *third())`, Python evaluates `first` and + // `third` before `second`. Only the suffix after the first keyword can + // still contain positional arguments that must move ahead of it. + let mut items = arguments.items.iter(); + let first_keyword = loop { + match items.next() { + Some(Argument::Positional(arg)) => visitor.visit_expr(arg), + Some(Argument::Keyword(keyword)) => break keyword, + None => return, + } + }; + for arg in items.clone().filter_map(Argument::as_positional) { visitor.visit_expr(arg); } - for keyword in &*arguments.keywords { + visitor.visit_keyword(first_keyword); + for keyword in items.filter_map(Argument::as_keyword) { visitor.visit_keyword(keyword); } } diff --git a/crates/ruff_python_ast/src/visitor/transformer.rs b/crates/ruff_python_ast/src/visitor/transformer.rs index 5895e59ea6..8e399fbccd 100644 --- a/crates/ruff_python_ast/src/visitor/transformer.rs +++ b/crates/ruff_python_ast/src/visitor/transformer.rs @@ -652,11 +652,15 @@ pub fn walk_arguments(visitor: &V, arguments: &mut Argu // Note that there might be keywords before the last arg, e.g. in // f(*args, a=2, *args2, **kwargs)`, but we follow Python in evaluating first `args` and then // `keywords`. See also [Arguments::arguments_source_order`]. - for arg in &mut *arguments.args { - visitor.visit_expr(arg); + for item in &mut arguments.items { + if let crate::Argument::Positional(arg) = item { + visitor.visit_expr(arg); + } } - for keyword in &mut *arguments.keywords { - visitor.visit_keyword(keyword); + for item in &mut arguments.items { + if let crate::Argument::Keyword(keyword) = item { + visitor.visit_keyword(keyword); + } } } diff --git a/crates/ruff_python_ast_integration_tests/tests/comparable.rs b/crates/ruff_python_ast_integration_tests/tests/comparable.rs index 71a98f40f8..1a78ba28b6 100644 --- a/crates/ruff_python_ast_integration_tests/tests/comparable.rs +++ b/crates/ruff_python_ast_integration_tests/tests/comparable.rs @@ -65,6 +65,7 @@ fn assert_hashable_unequal(left: &str, right: &str) -> Result<(), ParseError> { fn call_arguments() -> Result<(), ParseError> { let call = "factory(item, *items, limit=2, **options)"; assert_comparable(call, "factory(item, *items, limit=0x2, **options)")?; + assert_comparable(call, "factory(item, limit=2, *items, **options)")?; assert_noncomparable(call, "factory(item, *items, **options, limit=2)") } diff --git a/crates/ruff_python_ast_integration_tests/tests/parentheses.rs b/crates/ruff_python_ast_integration_tests/tests/parentheses.rs index 750549c3a0..aa541736dd 100644 --- a/crates/ruff_python_ast_integration_tests/tests/parentheses.rs +++ b/crates/ruff_python_ast_integration_tests/tests/parentheses.rs @@ -146,8 +146,8 @@ fn test_call_arguments_not_counted() { let arg = call .arguments - .args - .first() + .args() + .next() .expect("call should have an argument"); let result = parenthesized_range(arg.into(), (&call.arguments).into(), tokens); // The parentheses belong to the call, not the argument @@ -172,8 +172,8 @@ fn test_call_with_parenthesized_argument() { let arg = call .arguments - .args - .first() + .args() + .next() .expect("call should have an argument"); let result = parenthesized_range(arg.into(), (&call.arguments).into(), tokens); @@ -186,7 +186,7 @@ fn multiply_parenthesized_argument() { let source = "f(((a + 1)))"; let parsed = parse_expression(source).expect("valid expression"); let call = parsed.expr().as_call_expr().expect("call expression"); - let argument = call.arguments.args.first().expect("call argument"); + let argument = call.arguments.args().next().expect("call argument"); let range = parenthesized_range(argument.into(), (&call.arguments).into(), parsed.tokens()) .expect("parenthesized argument"); diff --git a/crates/ruff_python_ast_integration_tests/tests/snapshots/source_order__interleaved_call_arguments.snap b/crates/ruff_python_ast_integration_tests/tests/snapshots/source_order__interleaved_call_arguments.snap new file mode 100644 index 0000000000..bdec511553 --- /dev/null +++ b/crates/ruff_python_ast_integration_tests/tests/snapshots/source_order__interleaved_call_arguments.snap @@ -0,0 +1,17 @@ +--- +source: crates/ruff_python_ast_integration_tests/tests/source_order.rs +expression: trace +--- +- ModModule + - StmtExpr + - ExprCall + - ExprName + - Arguments + - ExprName + - Keyword + - Identifier + - ExprName + - ExprStarred + - ExprName + - Keyword + - ExprName diff --git a/crates/ruff_python_ast_integration_tests/tests/snapshots/visitor__interleaved_call_arguments.snap b/crates/ruff_python_ast_integration_tests/tests/snapshots/visitor__interleaved_call_arguments.snap new file mode 100644 index 0000000000..91c9103722 --- /dev/null +++ b/crates/ruff_python_ast_integration_tests/tests/snapshots/visitor__interleaved_call_arguments.snap @@ -0,0 +1,14 @@ +--- +source: crates/ruff_python_ast_integration_tests/tests/visitor.rs +expression: trace +--- +- StmtExpr + - ExprCall + - ExprName + - ExprName + - ExprStarred + - ExprName + - Keyword + - ExprName + - Keyword + - ExprName diff --git a/crates/ruff_python_ast_integration_tests/tests/source_order.rs b/crates/ruff_python_ast_integration_tests/tests/source_order.rs index ccb64c5b9e..b218a2ecf7 100644 --- a/crates/ruff_python_ast_integration_tests/tests/source_order.rs +++ b/crates/ruff_python_ast_integration_tests/tests/source_order.rs @@ -6,6 +6,12 @@ use ruff_python_ast::visitor::source_order::{SourceOrderVisitor, TraversalSignal use ruff_python_ast::{AnyNodeRef, BoolOp, CmpOp, Operator, Singleton, UnaryOp}; use ruff_python_parser::{Mode, ParseOptions, parse, parse_unchecked}; +#[test] +fn interleaved_call_arguments() { + let trace = trace_source_order_visitation("f(before, key=value, *after, **rest)"); + assert_snapshot!(trace); +} + #[test] fn function_arguments() { let source = r"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"; diff --git a/crates/ruff_python_ast_integration_tests/tests/visitor.rs b/crates/ruff_python_ast_integration_tests/tests/visitor.rs index 5f1d01f071..72962021da 100644 --- a/crates/ruff_python_ast_integration_tests/tests/visitor.rs +++ b/crates/ruff_python_ast_integration_tests/tests/visitor.rs @@ -15,6 +15,12 @@ use ruff_python_ast::{ }; use ruff_python_parser::{Mode, ParseOptions, parse}; +#[test] +fn interleaved_call_arguments() { + let trace = trace_visitation("f(before, key=value, *after, **rest)"); + assert_snapshot!(trace); +} + #[test] fn function_arguments() { let source = r"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"; diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 6e02ff557b..6bb20c6df3 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1214,18 +1214,15 @@ impl<'a> Generator<'a> { }) => { self.unparse_expr(func, precedence::MAX); self.p("("); - if let ( - [ - Expr::Generator(ast::ExprGenerator { - elt, - generators, - range: _, - node_index: _, - parenthesized: _, - }), - ], - [], - ) = (arguments.args.as_ref(), arguments.keywords.as_ref()) + if let [ + ast::Argument::Positional(Expr::Generator(ast::ExprGenerator { + elt, + generators, + range: _, + node_index: _, + parenthesized: _, + })), + ] = arguments.items.as_slice() { // Ensure that a single generator doesn't get double-parenthesized. self.unparse_expr(elt, precedence::COMMA); diff --git a/crates/ruff_python_edits/src/call.rs b/crates/ruff_python_edits/src/call.rs index ed5f341c13..90769f13c6 100644 --- a/crates/ruff_python_edits/src/call.rs +++ b/crates/ruff_python_edits/src/call.rs @@ -138,7 +138,7 @@ mod tests { let AnyNodeRef::ExprCall(call) = covering.node() else { return Err("expected a call expression".into()); }; - let argument = call.arguments.args.first().ok_or("missing argument")?; + let argument = call.arguments.args().next().ok_or("missing argument")?; let replacement = unwrapped_call_argument(call, argument, covering.parent(), parsed.tokens(), source); diff --git a/crates/ruff_python_formatter/src/other/arguments.rs b/crates/ruff_python_formatter/src/other/arguments.rs index 8c1b8f4f73..3f702e1c8f 100644 --- a/crates/ruff_python_formatter/src/other/arguments.rs +++ b/crates/ruff_python_formatter/src/other/arguments.rs @@ -1,5 +1,5 @@ use ruff_formatter::{FormatContext, write}; -use ruff_python_ast::{ArgOrKeyword, Arguments, Expr, StringFlags, StringLike}; +use ruff_python_ast::{ArgOrKeyword, Argument, Arguments, Expr, StringFlags, StringLike}; use ruff_python_trivia::{PythonWhitespace, SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; @@ -17,8 +17,7 @@ impl FormatNodeRule for FormatArguments { fn fmt_fields(&self, item: &Arguments, f: &mut PyFormatter) -> FormatResult<()> { let Arguments { range, - args, - keywords, + items, node_index: _, } = item; // We have a case with `f()` without any argument, which is a special case because we can @@ -28,7 +27,7 @@ impl FormatNodeRule for FormatArguments { // # This call has a dangling comment. // ) // ``` - if args.is_empty() && keywords.is_empty() { + if items.is_empty() { let comments = f.context().comments().clone(); let dangling = comments.dangling(item); return write!(f, [empty_parenthesized("(", dangling, ")")]); @@ -37,8 +36,8 @@ impl FormatNodeRule for FormatArguments { let all_arguments = format_with(|f: &mut PyFormatter| { let source = f.context().source(); let mut joiner = f.join_comma_separated(range.end()); - match args.as_ref() { - [arg] if keywords.is_empty() => { + match items.as_slice() { + [Argument::Positional(arg)] => { match arg { Expr::Generator(generator_exp) => joiner.entry( generator_exp, @@ -171,9 +170,11 @@ fn is_single_argument_parenthesized(argument: &Expr, call_end: TextSize, source: /// of those collections. fn is_arguments_huggable(arguments: &Arguments, context: &PyFormatContext) -> bool { // Find the lone argument or `**kwargs` keyword. - let arg = match (arguments.args.as_ref(), arguments.keywords.as_ref()) { - ([arg], []) => arg, - ([], [keyword]) if keyword.arg.is_none() && !context.comments().has(keyword) => { + let arg = match arguments.items.as_slice() { + [Argument::Positional(arg)] => arg, + [Argument::Keyword(keyword)] + if keyword.arg.is_none() && !context.comments().has(keyword) => + { &keyword.value } _ => return false, diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index ef79f0c04e..dc0ae7a356 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -726,13 +726,11 @@ impl<'src> Parser<'src> { return ast::Arguments { range: self.node_range(start), node_index: AtomicNodeIndex::NONE, - args: ThinVec::new(), - keywords: ThinVec::default(), + items: ThinVec::new(), }; } - let args_snapshot = self.expr_scratch.snapshot(); - let keywords_snapshot = self.keyword_scratch.snapshot(); + let snapshot = self.argument_scratch.snapshot(); let mut seen_keyword_argument = false; // foo = 1 let mut seen_keyword_unpacking = false; // **foo @@ -742,12 +740,14 @@ impl<'src> Parser<'src> { if parser.eat(TokenKind::DoubleStar) { let value = parser.parse_conditional_expression_or_higher(); - parser.keyword_scratch.push(ast::Keyword { - arg: None, - value: value.expr, - range: parser.node_range(argument_start), - node_index: AtomicNodeIndex::NONE, - }); + parser + .argument_scratch + .push(ast::Argument::Keyword(ast::Keyword { + arg: None, + value: Box::new(value.expr), + range: parser.node_range(argument_start), + node_index: AtomicNodeIndex::NONE, + })); seen_keyword_unpacking = true; } else { @@ -832,12 +832,14 @@ impl<'src> Parser<'src> { let value = parser.parse_conditional_expression_or_higher(); - parser.keyword_scratch.push(ast::Keyword { - arg: Some(arg), - value: value.expr, - range: parser.node_range(argument_start), - node_index: AtomicNodeIndex::NONE, - }); + parser + .argument_scratch + .push(ast::Argument::Keyword(ast::Keyword { + arg: Some(arg), + value: Box::new(value.expr), + range: parser.node_range(argument_start), + node_index: AtomicNodeIndex::NONE, + })); } else { if !parsed_expr.is_unparenthesized_starred_expr() { if seen_keyword_unpacking { @@ -852,19 +854,19 @@ impl<'src> Parser<'src> { ); } } - parser.expr_scratch.push(parsed_expr.expr); + parser + .argument_scratch + .push(ast::Argument::Positional(parsed_expr.expr)); } } }); self.expect(TokenKind::Rpar); - let keywords = self.keyword_scratch.take_thin_vec(keywords_snapshot); let arguments = ast::Arguments { range: self.node_range(start), node_index: AtomicNodeIndex::NONE, - args: self.expr_scratch.take_thin_vec(args_snapshot), - keywords, + items: self.argument_scratch.take_thin_vec(snapshot), }; self.validate_arguments(&arguments, has_trailing_comma, context); @@ -2997,7 +2999,7 @@ impl<'src> Parser<'src> { }; if generator_must_be_parenthesized { - for arg in &*arguments.args { + for arg in arguments.args() { if let Some(ast::ExprGenerator { range, parenthesized: false, diff --git a/crates/ruff_python_parser/src/parser/mod.rs b/crates/ruff_python_parser/src/parser/mod.rs index 8af421d0f8..595e1c0bd0 100644 --- a/crates/ruff_python_parser/src/parser/mod.rs +++ b/crates/ruff_python_parser/src/parser/mod.rs @@ -7,7 +7,7 @@ use hashbrown::HashSet; use ruff_python_ast::name::Name; use ruff_python_ast::token::TokenKind; use ruff_python_ast::{ - Alias, AtomicNodeIndex, ElifElseClause, Expr, Int, IpyEscapeKind, Keyword, Mod, ModExpression, + Alias, Argument, AtomicNodeIndex, ElifElseClause, Expr, Int, IpyEscapeKind, Mod, ModExpression, ModModule, ParameterItem, Stmt, StringFlags, }; use ruff_python_trivia::is_python_whitespace; @@ -100,7 +100,7 @@ pub(crate) struct Parser<'src> { expr_scratch: ScratchBuffer, /// Reusable, nesting-safe scratch storage for call keywords. - keyword_scratch: ScratchBuffer, + argument_scratch: ScratchBuffer, /// Reusable, nesting-safe scratch storage for function and lambda parameters. parameter_scratch: ScratchBuffer, @@ -144,7 +144,7 @@ impl<'src> Parser<'src> { recursion_depth: 0, current_token_id: TokenId::default(), expr_scratch: ScratchBuffer::with_capacity(16), - keyword_scratch: ScratchBuffer::new(), + argument_scratch: ScratchBuffer::new(), parameter_scratch: ScratchBuffer::new(), stmt_scratch: ScratchBuffer::with_capacity(32), alias_scratch: ScratchBuffer::new(), diff --git a/crates/ruff_python_parser/src/parser/recovery.rs b/crates/ruff_python_parser/src/parser/recovery.rs index 5cc3028826..8a7d2f04ba 100644 --- a/crates/ruff_python_parser/src/parser/recovery.rs +++ b/crates/ruff_python_parser/src/parser/recovery.rs @@ -1,7 +1,6 @@ use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr, ExprContext, Pattern}; use ruff_text_size::{Ranged, TextLen, TextRange}; -use thin_vec::ThinVec; /// Convert the given [`Pattern`] to an [`Expr`]. /// @@ -95,21 +94,23 @@ pub(super) fn pattern_to_expr(pattern: Pattern) -> Expr { }) => { debug_assert_eq!(range.end(), arguments.end()); - let mut args = ThinVec::new(); - let mut keywords = ThinVec::new(); - for item in arguments.items { - match item { + let items = arguments + .items + .into_iter() + .map(|item| match item { ast::PatternOrKeyword::Pattern(pattern) => { - args.push(pattern_to_expr(pattern)); + ast::Argument::Positional(pattern_to_expr(pattern)) } - ast::PatternOrKeyword::Keyword(keyword) => keywords.push(ast::Keyword { - range: keyword.range, - node_index: node_index.clone(), - arg: Some(keyword.attr), - value: pattern_to_expr(keyword.pattern), - }), - } - } + ast::PatternOrKeyword::Keyword(keyword) => { + ast::Argument::Keyword(ast::Keyword { + range: keyword.range, + node_index: node_index.clone(), + arg: Some(keyword.attr), + value: Box::new(pattern_to_expr(keyword.pattern)), + }) + } + }) + .collect(); Expr::Call(ast::ExprCall { range_start: range.start(), node_index: node_index.clone(), @@ -117,8 +118,7 @@ pub(super) fn pattern_to_expr(pattern: Pattern) -> Expr { arguments: ast::Arguments { range: arguments.range, node_index, - args, - keywords, + items, }, }) } diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap index 7f754a3377..fabb2dfaae 100644 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap @@ -249,18 +249,19 @@ Module( arguments: Arguments { range: 725..728, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 726..727, - value: Int( - 5, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 726..727, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/src/semantic_errors.rs b/crates/ruff_python_parser/src/semantic_errors.rs index b312b35e37..6a4dcc5c5b 100644 --- a/crates/ruff_python_parser/src/semantic_errors.rs +++ b/crates/ruff_python_parser/src/semantic_errors.rs @@ -798,18 +798,20 @@ impl SemanticSyntaxChecker { } fn duplicate_keyword_args(args: &ast::Arguments, ctx: &Ctx) { - if args.keywords.len() < 2 { + if args.len() < 2 { return; } - let mut all_arg_names = - FxHashSet::with_capacity_and_hasher(args.keywords.len(), FxBuildHasher); + let mut names = args + .keywords() + .filter_map(|kw| kw.arg.as_ref().map(|arg| (arg, kw.range))); + let (Some((first, _)), Some(second)) = (names.next(), names.next()) else { + return; + }; + let mut all_arg_names = FxHashSet::default(); + all_arg_names.insert(first.as_str()); - for (ident, range) in args - .keywords - .iter() - .filter_map(|keyword| keyword.arg.as_ref().map(|arg| (arg, keyword.range))) - { + for (ident, range) in std::iter::once(second).chain(names) { if !all_arg_names.insert(ident.as_str()) { // test_err duplicate_keyword_args // def foo(x): ... diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap index 12e797e812..58eb83e263 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap @@ -88,8 +88,7 @@ Module( arguments: Arguments { range: 23..25, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap index 49270f2b38..a839daf413 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap @@ -29,79 +29,83 @@ Module( arguments: Arguments { range: 3..28, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 4..24, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 4..5, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 6..24, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 10..11, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 15..24, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 15..20, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 20..24, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 4..24, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 4..5, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 6..24, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 21..23, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 10..11, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 15..24, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 15..20, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 20..24, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 21..23, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 26..27, - value: Int( - 5, - ), - }, + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 26..27, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -126,97 +130,105 @@ Module( arguments: Arguments { range: 34..64, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 35..36, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 35..36, + value: Int( + 1, + ), + }, + ), ), - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 38..39, - value: Int( - 2, - ), - }, + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 38..39, + value: Int( + 2, + ), + }, + ), ), - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 41..60, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 41..42, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 43..60, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 47..48, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 52..60, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 52..57, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 57..60, + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 41..60, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 41..42, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 43..60, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 58..59, - value: Int( - 5, - ), - }, - ), - ], - keywords: [], + range: 47..48, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 52..60, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 52..57, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 57..60, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 58..59, + value: Int( + 5, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 62..63, - value: Int( - 6, - ), - }, + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 62..63, + value: Int( + 6, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -241,70 +253,72 @@ Module( arguments: Arguments { range: 68..91, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 69..89, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 69..70, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 71..89, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 75..76, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 80..89, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 80..85, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 85..89, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 69..89, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 69..70, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 71..89, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 86..88, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 75..76, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 80..89, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 80..85, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 85..89, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 86..88, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap index 186eb41f69..03023c42b8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap @@ -124,8 +124,7 @@ Module( arguments: Arguments { range: 29..31, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap index 7a88362450..e3f5ce9663 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap @@ -40,8 +40,7 @@ Module( Arguments { range: 20..22, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [], diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap index ffb66e8ee6..9c22e9ca25 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap @@ -53,8 +53,7 @@ Module( Arguments { range: 18..20, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -88,27 +87,28 @@ Module( Arguments { range: 32..47, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 33..46, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("metaclass"), - range: 33..42, - node_index: NodeIndex(None), - }, - ), - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 43..46, - id: Name("ABC"), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 33..46, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("metaclass"), + range: 33..42, + node_index: NodeIndex(None), + }, + ), + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 43..46, + id: Name("ABC"), + ctx: Load, + }, + ), + }, + ), ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap index 515534ed26..500d1a6bef 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap @@ -57,25 +57,28 @@ Module( Arguments { range: 17..23, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 18..19, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 18..19, + id: Name("a"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 21..22, - id: Name("b"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 21..22, + id: Name("b"), + ctx: Load, + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unparenthesized_generator_argument.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unparenthesized_generator_argument.py.snap index 6a5ebeb17c..e2c56f24bd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unparenthesized_generator_argument.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unparenthesized_generator_argument.py.snap @@ -25,48 +25,49 @@ Module( Arguments { range: 9..33, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 10..32, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 10..14, - id: Name("base"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 15..32, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 19..23, - id: Name("base"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 27..32, - id: Name("bases"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 10..32, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 10..14, + id: Name("base"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 15..32, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 19..23, + id: Name("base"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 27..32, + id: Name("bases"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap index d5cb24b9ff..033814b56d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap @@ -29,31 +29,33 @@ Module( arguments: Arguments { range: 4..14, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { + items: [ + Keyword( + Keyword { + range: 5..8, node_index: NodeIndex(None), - range: 12..13, - value: Int( - 1, + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 7..8, + id: Name("x"), + ctx: Load, + }, ), }, ), - ], - keywords: [ - Keyword { - range: 5..8, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + Positional( + NumberLiteral( + ExprNumberLiteral { node_index: NodeIndex(None), - range: 7..8, - id: Name("x"), - ctx: Load, + range: 12..13, + value: Int( + 1, + ), }, ), - }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap index 48bd834ed4..dacd17407f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap @@ -29,18 +29,19 @@ Module( arguments: Arguments { range: 4..9, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 7..8, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 7..8, + value: Int( + 1, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap index c0e68ac262..5762ca98e5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap @@ -34,30 +34,31 @@ Module( arguments: Arguments { range: 9..20, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 10..19, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 10..19, - node_index: NodeIndex(None), - value: "foo.txt", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 10..19, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 10..19, + node_index: NodeIndex(None), + value: "foo.txt", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap index 8951e9ab1f..a89c2c3fcd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap @@ -79,17 +79,18 @@ Module( arguments: Arguments { range: 64..69, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 65..68, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 65..68, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap index 937ba4fee2..14aeed5b42 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap @@ -42,8 +42,7 @@ Module( arguments: Arguments { range: 49..51, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -58,8 +57,7 @@ Module( arguments: Arguments { range: 55..57, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_keyword_args.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_keyword_args.py.snap index f19991385a..018949f1ea 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_keyword_args.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_keyword_args.py.snap @@ -81,48 +81,51 @@ Module( arguments: Arguments { range: 19..29, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 20..23, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 20..21, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 22..23, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 25..28, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 25..26, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 27..28, - value: Int( - 2, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 20..23, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 20..21, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 22..23, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 25..28, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 25..26, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 27..28, + value: Int( + 2, + ), + }, + ), + }, + ), ], }, }, @@ -234,77 +237,83 @@ Module( arguments: Arguments { range: 55..73, node_index: NodeIndex(None), - args: [ - Name( - ExprName { + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 56..57, + id: Name("x"), + ctx: Load, + }, + ), + ), + Keyword( + Keyword { + range: 59..62, node_index: NodeIndex(None), - range: 56..57, - id: Name("x"), - ctx: Load, + arg: Some( + Identifier { + id: Name("y"), + range: 59..60, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 61..62, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 64..67, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("z"), + range: 64..65, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 66..67, + value: Int( + 3, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 69..72, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("y"), + range: 69..70, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 71..72, + value: Int( + 4, + ), + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 59..62, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 59..60, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 61..62, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 64..67, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("z"), - range: 64..65, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 66..67, - value: Int( - 3, - ), - }, - ), - }, - Keyword { - range: 69..72, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 69..70, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 71..72, - value: Int( - 4, - ), - }, - ), - }, ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap index 58d3cd2c1c..76090df0bf 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap @@ -29,29 +29,30 @@ Module( arguments: Arguments { range: 4..15, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 5..14, - node_index: NodeIndex(None), - arg: None, - value: Yield( - ExprYield { - node_index: NodeIndex(None), - range: 7..14, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 13..14, - id: Name("x"), - ctx: Load, - }, + items: [ + Keyword( + Keyword { + range: 5..14, + node_index: NodeIndex(None), + arg: None, + value: Yield( + ExprYield { + node_index: NodeIndex(None), + range: 7..14, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 13..14, + id: Name("x"), + ctx: Load, + }, + ), ), - ), - }, - ), - }, + }, + ), + }, + ), ], }, }, @@ -77,28 +78,29 @@ Module( arguments: Arguments { range: 20..27, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 21..26, - node_index: NodeIndex(None), - arg: None, - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 24..26, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 25..26, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 21..26, + node_index: NodeIndex(None), + arg: None, + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 24..26, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 25..26, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -124,28 +126,29 @@ Module( arguments: Arguments { range: 32..38, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 33..37, - node_index: NodeIndex(None), - arg: None, - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 35..37, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 36..37, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 33..37, + node_index: NodeIndex(None), + arg: None, + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 35..37, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 36..37, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -171,31 +174,33 @@ Module( arguments: Arguments { range: 44..54, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { + items: [ + Keyword( + Keyword { + range: 45..48, node_index: NodeIndex(None), - range: 52..53, - value: Int( - 1, + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 47..48, + id: Name("x"), + ctx: Load, + }, ), }, ), - ], - keywords: [ - Keyword { - range: 45..48, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + Positional( + NumberLiteral( + ExprNumberLiteral { node_index: NodeIndex(None), - range: 47..48, - id: Name("x"), - ctx: Load, + range: 52..53, + value: Int( + 1, + ), }, ), - }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap index 182ca169e0..9305176d10 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap @@ -29,108 +29,117 @@ Module( arguments: Arguments { range: 3..28, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 4..7, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 4..5, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 6..7, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 9..12, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("b"), - range: 9..10, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 11..12, - value: Int( - 2, - ), - }, - ), - }, - Keyword { - range: 14..17, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("c"), - range: 14..15, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 16..17, - value: Int( - 3, - ), - }, - ), - }, - Keyword { - range: 19..22, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("b"), - range: 19..20, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 21..22, - value: Int( - 4, - ), - }, - ), - }, - Keyword { - range: 24..27, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 24..25, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 26..27, - value: Int( - 5, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 4..7, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 4..5, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 6..7, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 9..12, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("b"), + range: 9..10, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 11..12, + value: Int( + 2, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 14..17, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("c"), + range: 14..15, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 16..17, + value: Int( + 3, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 19..22, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("b"), + range: 19..20, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 21..22, + value: Int( + 4, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 24..27, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 24..25, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 26..27, + value: Int( + 5, + ), + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap index b444c4d79d..c2c13a7f6b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap @@ -29,28 +29,29 @@ Module( arguments: Arguments { range: 4..15, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 5..14, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name(""), - range: 5..10, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 13..14, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 5..14, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name(""), + range: 5..10, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 13..14, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -76,28 +77,29 @@ Module( arguments: Arguments { range: 20..32, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 21..31, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name(""), - range: 21..27, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 30..31, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 21..31, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name(""), + range: 21..27, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 30..31, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -123,25 +125,26 @@ Module( arguments: Arguments { range: 38..47, node_index: NodeIndex(None), - args: [ - Yield( - ExprYield { - node_index: NodeIndex(None), - range: 39..46, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 45..46, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Yield( + ExprYield { + node_index: NodeIndex(None), + range: 39..46, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 45..46, + id: Name("x"), + ctx: Load, + }, + ), ), - ), - }, + }, + ), ), ], - keywords: [], }, }, ), @@ -166,23 +169,24 @@ Module( arguments: Arguments { range: 52..66, node_index: NodeIndex(None), - args: [ - YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 53..65, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 64..65, - id: Name("x"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 53..65, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 64..65, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap index 551521976d..8f44a0585e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap @@ -29,35 +29,36 @@ Module( arguments: Arguments { range: 4..17, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 5..16, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 5..6, - node_index: NodeIndex(None), - }, - ), - value: Yield( - ExprYield { - node_index: NodeIndex(None), - range: 9..16, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 15..16, - id: Name("y"), - ctx: Load, - }, + items: [ + Keyword( + Keyword { + range: 5..16, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 5..6, + node_index: NodeIndex(None), + }, + ), + value: Yield( + ExprYield { + node_index: NodeIndex(None), + range: 9..16, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 15..16, + id: Name("y"), + ctx: Load, + }, + ), ), - ), - }, - ), - }, + }, + ), + }, + ), ], }, }, @@ -83,33 +84,34 @@ Module( arguments: Arguments { range: 22..40, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 23..39, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 23..24, - node_index: NodeIndex(None), - }, - ), - value: YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 27..39, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 38..39, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 23..39, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 23..24, + node_index: NodeIndex(None), + }, + ), + value: YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 27..39, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 38..39, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, @@ -135,34 +137,35 @@ Module( arguments: Arguments { range: 45..53, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 46..52, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 46..47, - node_index: NodeIndex(None), - }, - ), - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 50..52, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 51..52, - id: Name("y"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 46..52, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 46..47, + node_index: NodeIndex(None), + }, + ), + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 50..52, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 51..52, + id: Name("y"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -188,34 +191,35 @@ Module( arguments: Arguments { range: 58..68, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 59..67, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 59..60, - node_index: NodeIndex(None), - }, - ), - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 64..66, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 65..66, - id: Name("y"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 59..67, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 59..60, + node_index: NodeIndex(None), + }, + ), + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 64..66, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 65..66, + id: Name("y"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap index 9ccc48a630..df09c45c43 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap @@ -29,30 +29,32 @@ Module( arguments: Arguments { range: 4..17, node_index: NodeIndex(None), - args: [ - Name( - ExprName { + items: [ + Keyword( + Keyword { + range: 5..13, node_index: NodeIndex(None), - range: 15..16, - id: Name("x"), - ctx: Load, + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 7..13, + id: Name("kwargs"), + ctx: Load, + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 5..13, - node_index: NodeIndex(None), - arg: None, - value: Name( + Positional( + Name( ExprName { node_index: NodeIndex(None), - range: 7..13, - id: Name("kwargs"), + range: 15..16, + id: Name("x"), ctx: Load, }, ), - }, + ), ], }, }, @@ -78,37 +80,39 @@ Module( arguments: Arguments { range: 22..30, node_index: NodeIndex(None), - args: [ - Name( - ExprName { + items: [ + Keyword( + Keyword { + range: 23..26, node_index: NodeIndex(None), - range: 28..29, - id: Name("y"), - ctx: Load, + arg: Some( + Identifier { + id: Name("x"), + range: 23..24, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 25..26, + value: Int( + 1, + ), + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 23..26, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 23..24, + Positional( + Name( + ExprName { node_index: NodeIndex(None), + range: 28..29, + id: Name("y"), + ctx: Load, }, ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 25..26, - value: Int( - 1, - ), - }, - ), - }, + ), ], }, }, @@ -134,50 +138,54 @@ Module( arguments: Arguments { range: 35..53, node_index: NodeIndex(None), - args: [ - Name( - ExprName { + items: [ + Keyword( + Keyword { + range: 36..39, node_index: NodeIndex(None), - range: 51..52, - id: Name("y"), - ctx: Load, + arg: Some( + Identifier { + id: Name("x"), + range: 36..37, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 38..39, + value: Int( + 1, + ), + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 36..39, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 36..37, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 38..39, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 41..49, - node_index: NodeIndex(None), - arg: None, - value: Name( + Keyword( + Keyword { + range: 41..49, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 43..49, + id: Name("kwargs"), + ctx: Load, + }, + ), + }, + ), + Positional( + Name( ExprName { node_index: NodeIndex(None), - range: 43..49, - id: Name("kwargs"), + range: 51..52, + id: Name("y"), ctx: Load, }, ), - }, + ), ], }, }, @@ -203,37 +211,39 @@ Module( arguments: Arguments { range: 58..75, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { + items: [ + Keyword( + Keyword { + range: 59..67, node_index: NodeIndex(None), - range: 69..74, + arg: None, value: Name( ExprName { node_index: NodeIndex(None), - range: 70..74, - id: Name("args"), + range: 61..67, + id: Name("kwargs"), ctx: Load, }, ), - ctx: Load, }, ), - ], - keywords: [ - Keyword { - range: 59..67, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - range: 61..67, - id: Name("kwargs"), + range: 69..74, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 70..74, + id: Name("args"), + ctx: Load, + }, + ), ctx: Load, }, ), - }, + ), ], }, }, @@ -259,37 +269,39 @@ Module( arguments: Arguments { range: 80..99, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { + items: [ + Keyword( + Keyword { + range: 81..89, node_index: NodeIndex(None), - range: 92..97, + arg: None, value: Name( ExprName { node_index: NodeIndex(None), - range: 93..97, - id: Name("args"), + range: 83..89, + id: Name("kwargs"), ctx: Load, }, ), - ctx: Load, }, ), - ], - keywords: [ - Keyword { - range: 81..89, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - range: 83..89, - id: Name("kwargs"), + range: 92..97, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 93..97, + id: Name("args"), + ctx: Load, + }, + ), ctx: Load, }, ), - }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap index 9525b67f76..5941f5c2ff 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap @@ -29,25 +29,28 @@ Module( arguments: Arguments { range: 4..10, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("x"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 8..9, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 8..9, + id: Name("y"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap index 9f115bdf9c..8acaa4e9c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap @@ -29,25 +29,28 @@ Module( arguments: Arguments { range: 4..9, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("x"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 7..8, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 7..8, + id: Name("y"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap index 83e062828f..f242f1092d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap @@ -29,18 +29,19 @@ Module( arguments: Arguments { range: 4..10, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 8..9, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 8..9, + value: Int( + 1, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -65,27 +66,28 @@ Module( arguments: Arguments { range: 15..21, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 16..19, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 16..17, - node_index: NodeIndex(None), - }, - ), - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 19..19, - id: Name(""), - ctx: Invalid, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 16..19, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 16..17, + node_index: NodeIndex(None), + }, + ), + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 19..19, + id: Name(""), + ctx: Invalid, + }, + ), + }, + ), ], }, }, @@ -111,32 +113,35 @@ Module( arguments: Arguments { range: 26..32, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 27..28, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 28..28, - id: Name(""), - ctx: Invalid, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 27..28, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 28..28, + id: Name(""), + ctx: Invalid, + }, + ), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 30..31, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 30..31, + id: Name("y"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap index f74d95974c..5d840f6e85 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap @@ -29,55 +29,56 @@ Module( arguments: Arguments { range: 4..28, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 5..27, - elt: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 5..10, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 6..10, - id: Name("data"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 11..27, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 15..19, - id: Name("data"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 23..27, - id: Name("iter"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 5..27, + elt: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 5..10, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 6..10, + id: Name("data"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 11..27, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 15..19, + id: Name("data"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 23..27, + id: Name("iter"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), @@ -102,32 +103,33 @@ Module( arguments: Arguments { range: 33..43, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 34..42, - value: Yield( - ExprYield { - node_index: NodeIndex(None), - range: 35..42, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 41..42, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 34..42, + value: Yield( + ExprYield { + node_index: NodeIndex(None), + range: 35..42, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 41..42, + id: Name("x"), + ctx: Load, + }, + ), ), - ), - }, - ), - ctx: Load, - }, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -152,30 +154,31 @@ Module( arguments: Arguments { range: 48..63, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 49..62, - value: YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 50..62, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 61..62, - id: Name("x"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 49..62, + value: YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 50..62, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 61..62, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap index 42fb04c2f1..1331c82086 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap @@ -29,8 +29,7 @@ Module( arguments: Arguments { range: 4..5, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap index 99044741a7..3a7c54b89d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap @@ -29,17 +29,18 @@ Module( arguments: Arguments { range: 4..6, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("x"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap index 541d313db8..0a02c95708 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap @@ -29,17 +29,18 @@ Module( arguments: Arguments { range: 4..7, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("x"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap index 06f18a89d8..0c9cfd0611 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap @@ -177,8 +177,7 @@ Module( arguments: Arguments { range: 69..71, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap index dcc7317c17..e760afb099 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap @@ -56,8 +56,7 @@ Module( arguments: Arguments { range: 12..14, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap index fc926ff4dc..8c333daac3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap @@ -147,8 +147,7 @@ Module( arguments: Arguments { range: 60..62, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap index 5a0d5690a6..e08cd6d7e5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap @@ -57,8 +57,7 @@ Module( arguments: Arguments { range: 75..77, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap index 634105e9e0..8e6ab67b95 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap @@ -147,8 +147,7 @@ Module( arguments: Arguments { range: 60..62, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap index d3abfa92b1..8e5238c286 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap @@ -68,8 +68,7 @@ Module( arguments: Arguments { range: 13..15, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap index b2ea34abc3..559905d83d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap @@ -30,36 +30,37 @@ Module( arguments: Arguments { range: 5..13, node_index: NodeIndex(None), - args: [ - Compare( - ExprCompare { - node_index: NodeIndex(None), - range: 6..12, - ops: [ - In, - ], - operands: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 6..7, - id: Name("x"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 11..12, - id: Name("y"), - ctx: Load, - }, - ), - ], - }, + items: [ + Positional( + Compare( + ExprCompare { + node_index: NodeIndex(None), + range: 6..12, + ops: [ + In, + ], + operands: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 6..7, + id: Name("x"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 11..12, + id: Name("y"), + ctx: Load, + }, + ), + ], + }, + ), ), ], - keywords: [], }, }, ), @@ -127,8 +128,7 @@ Module( arguments: Arguments { range: 41..43, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap index 9876d8216b..993c6905a3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap @@ -45,31 +45,32 @@ Module( Arguments { range: 10..21, node_index: NodeIndex(None), - args: [ - Named( - ExprNamed { - node_index: NodeIndex(None), - range: 11..20, - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 11..12, - id: Name("y"), - ctx: Store, - }, - ), - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 16..20, - id: Name("list"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + Named( + ExprNamed { + node_index: NodeIndex(None), + range: 11..20, + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 11..12, + id: Name("y"), + ctx: Store, + }, + ), + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 16..20, + id: Name("list"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ @@ -123,26 +124,27 @@ Module( Arguments { range: 37..48, node_index: NodeIndex(None), - args: [ - Yield( - ExprYield { - node_index: NodeIndex(None), - range: 39..46, - value: Some( - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 45..46, - value: Int( - 1, - ), - }, + items: [ + Positional( + Yield( + ExprYield { + node_index: NodeIndex(None), + range: 39..46, + value: Some( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 45..46, + value: Int( + 1, + ), + }, + ), ), - ), - }, + }, + ), ), ], - keywords: [], }, ), body: [ @@ -196,24 +198,25 @@ Module( Arguments { range: 64..80, node_index: NodeIndex(None), - args: [ - YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 66..78, - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 77..78, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Positional( + YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 66..78, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 77..78, + value: Int( + 1, + ), + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ @@ -405,24 +408,25 @@ Module( Arguments { range: 203..214, node_index: NodeIndex(None), - args: [ - Await( - ExprAwait { - node_index: NodeIndex(None), - range: 205..212, - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 211..212, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Positional( + Await( + ExprAwait { + node_index: NodeIndex(None), + range: 205..212, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 211..212, + value: Int( + 1, + ), + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap index 0a1783181c..66718ef4c2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap @@ -77,17 +77,18 @@ Module( arguments: Arguments { range: 88..91, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 89..90, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 89..90, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -124,18 +125,19 @@ Module( arguments: Arguments { range: 107..110, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 108..109, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 108..109, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -229,17 +231,18 @@ Module( arguments: Arguments { range: 169..172, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 170..171, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 170..171, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -276,18 +279,19 @@ Module( arguments: Arguments { range: 188..191, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 189..190, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 189..190, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -370,17 +374,18 @@ Module( arguments: Arguments { range: 244..247, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 245..246, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 245..246, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -417,18 +422,19 @@ Module( arguments: Arguments { range: 263..266, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 264..265, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 264..265, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -516,18 +522,19 @@ Module( arguments: Arguments { range: 324..327, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 325..326, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 325..326, + value: Int( + 1, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -576,18 +583,19 @@ Module( arguments: Arguments { range: 347..350, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 348..349, - value: Int( - 2, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 348..349, + value: Int( + 2, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -629,18 +637,19 @@ Module( arguments: Arguments { range: 367..370, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 368..369, - value: Int( - 5, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 368..369, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -728,18 +737,19 @@ Module( arguments: Arguments { range: 413..416, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 414..415, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 414..415, + value: Int( + 1, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -788,18 +798,19 @@ Module( arguments: Arguments { range: 442..445, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 443..444, - value: Int( - 2, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 443..444, + value: Int( + 2, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -841,18 +852,19 @@ Module( arguments: Arguments { range: 462..465, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 463..464, - value: Int( - 5, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 463..464, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap index 6a2b1560fd..152dccd235 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap @@ -29,28 +29,29 @@ Module( arguments: Arguments { range: 44..51, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 45..50, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 46..47, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 49..50, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 45..50, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 46..47, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 49..50, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -76,28 +77,29 @@ Module( arguments: Arguments { range: 53..62, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 54..61, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 55..56, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 60..61, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 54..61, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 55..56, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 60..61, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -123,28 +125,29 @@ Module( arguments: Arguments { range: 64..76, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 66..75, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 68..69, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 74..75, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 66..75, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 68..69, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 74..75, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap index c148b9af9a..e1e1d74bad 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap @@ -148,17 +148,18 @@ Module( arguments: Arguments { range: 107..110, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 108..109, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 108..109, + id: Name("a"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -820,81 +821,82 @@ Module( arguments: Arguments { range: 493..513, node_index: NodeIndex(None), - args: [ - List( - ExprList { - node_index: NodeIndex(None), - range: 494..512, - elts: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 495..499, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 495..499, - node_index: NodeIndex(None), - value: "\t", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 494..512, + elts: [ + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 495..499, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 495..499, + node_index: NodeIndex(None), + value: "\t", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, - ), - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 501..505, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 501..505, - node_index: NodeIndex(None), - value: "\u{b}", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + ), + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 501..505, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 501..505, + node_index: NodeIndex(None), + value: "\u{b}", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, - ), - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 507..511, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 507..511, - node_index: NodeIndex(None), - value: "\r", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + ), + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 507..511, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 507..511, + node_index: NodeIndex(None), + value: "\r", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, - ), - ], - ctx: Load, - }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep_798_unpacking_comprehensions_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep_798_unpacking_comprehensions_py314.py.snap index 86297c504c..c9396d6b1b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep_798_unpacking_comprehensions_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep_798_unpacking_comprehensions_py314.py.snap @@ -228,55 +228,56 @@ Module( arguments: Arguments { range: 110..125, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 111..124, - elt: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 111..113, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 112..113, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 114..124, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 118..119, - id: Name("x"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 123..124, - id: Name("y"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 111..124, + elt: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 111..113, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 112..113, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 114..124, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 118..119, + id: Name("x"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 123..124, + id: Name("y"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap index ef044c35dd..0ecd27cff5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap @@ -29,17 +29,18 @@ Module( arguments: Arguments { range: 55..59, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 56..59, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 56..59, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -94,17 +95,18 @@ Module( arguments: Arguments { range: 120..124, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 121..124, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 121..124, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -160,17 +162,18 @@ Module( arguments: Arguments { range: 235..239, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 236..239, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 236..239, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -226,17 +229,18 @@ Module( arguments: Arguments { range: 351..355, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 352..355, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 352..355, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -292,42 +296,45 @@ Module( arguments: Arguments { range: 460..471, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 461..464, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 461..464, + id: Name("foo"), + ctx: Load, + }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 466..471, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 467..468, - id: Name("a"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 470..471, - id: Name("b"), - ctx: Load, - }, - ), - ], - ctx: Load, - }, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 466..471, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 467..468, + id: Name("a"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 470..471, + id: Name("b"), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -383,42 +390,45 @@ Module( arguments: Arguments { range: 571..583, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 572..575, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 572..575, + id: Name("foo"), + ctx: Load, + }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 577..582, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 578..579, - id: Name("a"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 581..582, - id: Name("b"), - ctx: Load, - }, - ), - ], - ctx: Load, - }, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 577..582, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 578..579, + id: Name("a"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 581..582, + id: Name("b"), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -474,42 +484,45 @@ Module( arguments: Arguments { range: 779..796, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 780..783, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 780..783, + id: Name("foo"), + ctx: Load, + }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 785..794, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 786..787, - id: Name("a"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 793..794, - id: Name("b"), - ctx: Load, - }, - ), - ], - ctx: Load, - }, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 785..794, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 786..787, + id: Name("a"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 793..794, + id: Name("b"), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -565,55 +578,56 @@ Module( arguments: Arguments { range: 894..905, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 895..905, - value: FStringValue { - inner: Single( - FString { - range: 895..905, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 897..903, - node_index: NodeIndex(None), - value: "hello ", - }, - ), - Interpolation( - InterpolatedElement { - range: 903..905, - node_index: NodeIndex(None), - expression: Name( - ExprName { - node_index: NodeIndex(None), - range: 904..905, - id: Name("x"), - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: true, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 895..905, + value: FStringValue { + inner: Single( + FString { + range: 895..905, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 897..903, + node_index: NodeIndex(None), + value: "hello ", + }, + ), + Interpolation( + InterpolatedElement { + range: 903..905, + node_index: NodeIndex(None), + expression: Name( + ExprName { + node_index: NodeIndex(None), + range: 904..905, + id: Name("x"), + ctx: Load, + }, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: true, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -669,38 +683,39 @@ Module( arguments: Arguments { range: 943..956, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 944..951, - value: FStringValue { - inner: Single( - FString { - range: 944..951, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 946..951, - node_index: NodeIndex(None), - value: "hello", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: true, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 944..951, + value: FStringValue { + inner: Single( + FString { + range: 944..951, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 946..951, + node_index: NodeIndex(None), + value: "hello", + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: true, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap index de14fda240..dfbaf547ac 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap @@ -29,42 +29,45 @@ Module( arguments: Arguments { range: 7..18, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 8..11, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 8..11, + id: Name("foo"), + ctx: Load, + }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 13..18, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 14..15, - id: Name("a"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 17..18, - id: Name("b"), - ctx: Load, - }, - ), - ], - ctx: Load, - }, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 13..18, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 14..15, + id: Name("a"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 17..18, + id: Name("b"), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap index 180d60d8c1..23138c4f06 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap @@ -29,42 +29,45 @@ Module( arguments: Arguments { range: 7..18, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 8..11, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 8..11, + id: Name("foo"), + ctx: Load, + }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 13..18, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 14..15, - id: Name("a"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 17..18, - id: Name("b"), - ctx: Load, - }, - ), - ], - ctx: Load, - }, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 13..18, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 14..15, + id: Name("a"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 17..18, + id: Name("b"), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap index a4012922a9..447ee06dc5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap @@ -29,25 +29,28 @@ Module( arguments: Arguments { range: 4..13, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("a"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 8..9, - id: Name("b"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 8..9, + id: Name("b"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap index d69cb99254..2b349c6e50 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap @@ -29,25 +29,28 @@ Module( arguments: Arguments { range: 4..10, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("a"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 8..9, - id: Name("b"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 8..9, + id: Name("b"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap index afc38b5b29..d49e316cc9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap @@ -29,62 +29,63 @@ Module( arguments: Arguments { range: 238..253, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 239..253, - value: FStringValue { - inner: Single( - FString { - range: 239..253, - node_index: NodeIndex(None), - elements: [ - Interpolation( - InterpolatedElement { - range: 243..250, - node_index: NodeIndex(None), - expression: Name( - ExprName { - node_index: NodeIndex(None), - range: 244..245, - id: Name("x"), - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: Some( - InterpolatedStringFormatSpec { - range: 246..250, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 246..250, - node_index: NodeIndex(None), - value: ".3f\n", - }, - ), - ], - }, - ), - }, - ), - ], - flags: FStringFlags { - quote_style: Single, - prefix: Regular, - triple_quoted: true, - unclosed: false, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 239..253, + value: FStringValue { + inner: Single( + FString { + range: 239..253, + node_index: NodeIndex(None), + elements: [ + Interpolation( + InterpolatedElement { + range: 243..250, + node_index: NodeIndex(None), + expression: Name( + ExprName { + node_index: NodeIndex(None), + range: 244..245, + id: Name("x"), + ctx: Load, + }, + ), + debug_text: None, + conversion: None, + format_spec: Some( + InterpolatedStringFormatSpec { + range: 246..250, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 246..250, + node_index: NodeIndex(None), + value: ".3f\n", + }, + ), + ], + }, + ), + }, + ), + ], + flags: FStringFlags { + quote_style: Single, + prefix: Regular, + triple_quoted: true, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__ty_1828.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__ty_1828.py.snap index 0b514de1ea..c96e2d6f0c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__ty_1828.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__ty_1828.py.snap @@ -130,8 +130,7 @@ Module( arguments: Arguments { range: 92..93, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap index 932b4f7ac2..61f35c11e2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap @@ -68,18 +68,19 @@ Module( arguments: Arguments { range: 24..27, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 25..26, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 25..26, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -149,18 +150,19 @@ Module( arguments: Arguments { range: 53..56, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 54..55, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 54..55, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -240,18 +242,19 @@ Module( arguments: Arguments { range: 87..90, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 88..89, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 88..89, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -331,18 +334,19 @@ Module( arguments: Arguments { range: 121..124, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 122..123, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 122..123, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -412,18 +416,19 @@ Module( arguments: Arguments { range: 150..153, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 151..152, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 151..152, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -503,18 +508,19 @@ Module( arguments: Arguments { range: 181..184, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 182..183, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 182..183, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -584,18 +590,19 @@ Module( arguments: Arguments { range: 211..214, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 212..213, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 212..213, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -628,18 +635,19 @@ Module( arguments: Arguments { range: 229..232, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 230..231, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 230..231, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -709,18 +717,19 @@ Module( arguments: Arguments { range: 259..262, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 260..261, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 260..261, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -753,18 +762,19 @@ Module( arguments: Arguments { range: 277..280, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 278..279, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 278..279, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -867,18 +877,19 @@ Module( arguments: Arguments { range: 319..322, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 320..321, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 320..321, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -911,18 +922,19 @@ Module( arguments: Arguments { range: 337..340, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 338..339, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 338..339, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@semicolon_before_match_statement.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@semicolon_before_match_statement.py.snap index 888c0d12d6..32c31df3c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@semicolon_before_match_statement.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@semicolon_before_match_statement.py.snap @@ -29,8 +29,7 @@ Module( arguments: Arguments { range: 5..7, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -92,8 +91,7 @@ Module( arguments: Arguments { range: 44..46, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@signed_pattern_non_literal_operand.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@signed_pattern_non_literal_operand.py.snap index c73bdb4962..daba008f4c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@signed_pattern_non_literal_operand.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@signed_pattern_non_literal_operand.py.snap @@ -218,8 +218,7 @@ Module( arguments: Arguments { range: 131..133, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap index c10eb737d2..72b4bff08d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap @@ -71,57 +71,58 @@ Module( Arguments { range: 83..107, node_index: NodeIndex(None), - args: [ - Subscript( - ExprSubscript { - node_index: NodeIndex(None), - range: 84..106, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 84..91, - id: Name("Generic"), - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 92..105, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 92..97, - id: Name("DType"), - ctx: Load, - }, - ), - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 99..105, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 100..105, - id: Name("Shape"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Subscript( + ExprSubscript { + node_index: NodeIndex(None), + range: 84..106, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 84..91, + id: Name("Generic"), + ctx: Load, + }, + ), + slice: Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 92..105, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 92..97, + id: Name("DType"), + ctx: Load, + }, + ), + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 99..105, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 100..105, + id: Name("Shape"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: false, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@starred_starred_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@starred_starred_expression.py.snap index 5e7b922cfa..2607d84fad 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@starred_starred_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@starred_starred_expression.py.snap @@ -29,31 +29,32 @@ Module( arguments: Arguments { range: 5..12, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 6..11, - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 8..11, - value: List( - ExprList { - node_index: NodeIndex(None), - range: 9..11, - elts: [], - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 6..11, + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 8..11, + value: List( + ExprList { + node_index: NodeIndex(None), + range: 9..11, + elts: [], + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -78,31 +79,32 @@ Module( arguments: Arguments { range: 18..25, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 19..24, - value: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 21..24, - value: List( - ExprList { - node_index: NodeIndex(None), - range: 22..24, - elts: [], - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 19..24, + value: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 21..24, + value: List( + ExprList { + node_index: NodeIndex(None), + range: 22..24, + elts: [], + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap index b469e7418a..50894b9894 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap @@ -426,8 +426,7 @@ Module( arguments: Arguments { range: 774..777, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap index 4e6786c7f8..7c4b59429c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap @@ -861,8 +861,7 @@ Module( arguments: Arguments { range: 567..569, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1214,8 +1213,7 @@ Module( arguments: Arguments { range: 681..683, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1267,8 +1265,7 @@ Module( arguments: Arguments { range: 696..698, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1505,8 +1502,7 @@ Module( arguments: Arguments { range: 766..768, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap index 3ca27eb0e9..1af76e7e7f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap @@ -758,8 +758,7 @@ Module( arguments: Arguments { range: 377..379, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1102,8 +1101,7 @@ Module( arguments: Arguments { range: 500..502, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1154,8 +1152,7 @@ Module( arguments: Arguments { range: 516..518, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1390,8 +1387,7 @@ Module( arguments: Arguments { range: 588..590, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap index 4f3a4512a1..a7fd4e99da 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap @@ -49,8 +49,7 @@ Module( arguments: Arguments { range: 39..41, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -480,17 +479,18 @@ Module( arguments: Arguments { range: 305..313, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 306..312, - id: Name(""), - ctx: Invalid, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 306..312, + id: Name(""), + ctx: Invalid, + }, + ), ), ], - keywords: [], }, }, ), @@ -571,8 +571,7 @@ Module( arguments: Arguments { range: 377..379, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -941,17 +940,18 @@ Module( arguments: Arguments { range: 603..611, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 604..610, - id: Name(""), - ctx: Invalid, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 604..610, + id: Name(""), + ctx: Invalid, + }, + ), ), ], - keywords: [], }, }, ), @@ -1011,8 +1011,7 @@ Module( arguments: Arguments { range: 670..672, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1032,8 +1031,7 @@ Module( arguments: Arguments { range: 678..680, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap index 0e04467e7d..76cceec0ca 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap @@ -479,17 +479,18 @@ Module( arguments: Arguments { range: 492..500, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 493..499, - id: Name(""), - ctx: Invalid, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 493..499, + id: Name(""), + ctx: Invalid, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap index 441cae77b7..013c45303b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap @@ -474,18 +474,19 @@ Module( arguments: Arguments { range: 380..384, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 381..383, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 381..383, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -597,18 +598,19 @@ Module( arguments: Arguments { range: 425..429, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 426..428, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 426..428, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap index f9d47d4923..3f8ae8d5d8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap @@ -169,8 +169,7 @@ Module( Arguments { range: 104..106, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -268,8 +267,7 @@ Module( Arguments { range: 141..143, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap index ecc5a6040e..7c6f1fd407 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap @@ -67,18 +67,19 @@ Module( arguments: Arguments { range: 68..71, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 69..70, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 69..70, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap index 4592b27f79..7ccedfd4ce 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap @@ -77,17 +77,18 @@ Module( arguments: Arguments { range: 96..99, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 97..98, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 97..98, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -124,18 +125,19 @@ Module( arguments: Arguments { range: 121..124, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 122..123, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 122..123, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap index 495601cfa5..f779243623 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap @@ -29,131 +29,136 @@ Module( arguments: Arguments { range: 3..51, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 4..26, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 5..6, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 7..25, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 11..12, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 16..25, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 16..21, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 21..25, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 4..26, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 5..6, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 7..25, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 22..24, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 11..12, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 16..25, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 16..21, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 21..25, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 22..24, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: true, + }, + ), ), - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 28..50, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 29..30, - id: Name("y"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 31..49, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 35..36, - id: Name("y"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 40..49, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 40..45, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 45..49, + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 28..50, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 29..30, + id: Name("y"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 31..49, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 46..48, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 35..36, + id: Name("y"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 40..49, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 40..45, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 45..49, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 46..48, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), @@ -178,70 +183,72 @@ Module( arguments: Arguments { range: 55..77, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 56..76, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 56..57, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 58..76, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 62..63, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 67..76, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 67..72, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 72..76, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 56..76, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 56..57, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 58..76, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 73..75, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 62..63, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 67..76, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 67..72, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 72..76, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 73..75, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), @@ -266,70 +273,72 @@ Module( arguments: Arguments { range: 81..106, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 82..104, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 83..84, - id: Name("x"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 85..103, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 89..90, - id: Name("x"), - ctx: Store, - }, - ), - iter: Call( - ExprCall { - node_index: NodeIndex(None), - range: 94..103, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 94..99, - id: Name("range"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 99..103, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 82..104, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 83..84, + id: Name("x"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 85..103, + node_index: NodeIndex(None), + target: Name( + ExprName { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 100..102, - value: Int( - 10, - ), - }, - ), - ], - keywords: [], + range: 89..90, + id: Name("x"), + ctx: Store, }, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, + ), + iter: Call( + ExprCall { + node_index: NodeIndex(None), + range: 94..103, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 94..99, + id: Name("range"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 99..103, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 100..102, + value: Int( + 10, + ), + }, + ), + ), + ], + }, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@bare_raise_before_semicolon.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@bare_raise_before_semicolon.py.snap index 5cf2c6b0bc..4f91ce2de5 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@bare_raise_before_semicolon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@bare_raise_before_semicolon.py.snap @@ -34,8 +34,7 @@ Module( arguments: Arguments { range: 9..11, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -86,8 +85,7 @@ Module( arguments: Arguments { range: 44..46, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap index 6a275e46d0..00233308f8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap @@ -53,8 +53,7 @@ Module( Arguments { range: 24..26, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -88,48 +87,49 @@ Module( Arguments { range: 41..67, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 42..66, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 43..47, - id: Name("base"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 48..65, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 52..56, - id: Name("base"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 60..65, - id: Name("bases"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 42..66, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 43..47, + id: Name("base"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 48..65, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 52..56, + id: Name("base"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 60..65, + id: Name("bases"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: true, + }, + ), ), ], - keywords: [], }, ), body: [ @@ -163,55 +163,56 @@ Module( Arguments { range: 82..109, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 83..108, - value: Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 84..108, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 85..89, - id: Name("base"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 90..107, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 94..98, - id: Name("base"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 102..107, - id: Name("bases"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: true, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 83..108, + value: Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 84..108, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 85..89, + id: Name("base"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 90..107, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 94..98, + id: Name("base"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 102..107, + id: Name("bases"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: true, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap index 817d4529e5..a1a37228ec 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap @@ -34,30 +34,31 @@ Module( arguments: Arguments { range: 50..80, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 51..79, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 51..79, - node_index: NodeIndex(None), - value: "buttons[0].clicked.connect", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 51..79, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 51..79, + node_index: NodeIndex(None), + value: "buttons[0].clicked.connect", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap index 80ac90091d..44c43a6f33 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap @@ -90,57 +90,58 @@ Module( arguments: Arguments { range: 66..94, node_index: NodeIndex(None), - args: [ - Attribute( - ExprAttribute { - node_index: NodeIndex(None), - range: 67..93, - value: Attribute( - ExprAttribute { - node_index: NodeIndex(None), - range: 67..85, - value: Subscript( - ExprSubscript { - node_index: NodeIndex(None), - range: 67..77, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 67..74, - id: Name("buttons"), - ctx: Load, - }, - ), - slice: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 75..76, - value: Int( - 0, - ), - }, - ), - ctx: Load, - }, - ), - attr: Identifier { - id: Name("clicked"), - range: 78..85, - node_index: NodeIndex(None), - }, - ctx: Load, - }, - ), - attr: Identifier { - id: Name("connect"), - range: 86..93, + items: [ + Positional( + Attribute( + ExprAttribute { node_index: NodeIndex(None), + range: 67..93, + value: Attribute( + ExprAttribute { + node_index: NodeIndex(None), + range: 67..85, + value: Subscript( + ExprSubscript { + node_index: NodeIndex(None), + range: 67..77, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 67..74, + id: Name("buttons"), + ctx: Load, + }, + ), + slice: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 75..76, + value: Int( + 0, + ), + }, + ), + ctx: Load, + }, + ), + attr: Identifier { + id: Name("clicked"), + range: 78..85, + node_index: NodeIndex(None), + }, + ctx: Load, + }, + ), + attr: Identifier { + id: Name("connect"), + range: 86..93, + node_index: NodeIndex(None), + }, + ctx: Load, }, - ctx: Load, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap index 6c2e23d231..8262afa731 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap @@ -166,17 +166,18 @@ Module( arguments: Arguments { range: 108..113, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 109..112, - id: Name("foo"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 109..112, + id: Name("foo"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap index ed2af92c76..bd707ba6b7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap @@ -29,8 +29,7 @@ Module( arguments: Arguments { range: 106..108, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -55,25 +54,28 @@ Module( arguments: Arguments { range: 113..119, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 114..115, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 114..115, + id: Name("x"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 117..118, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 117..118, + id: Name("y"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -98,25 +100,28 @@ Module( arguments: Arguments { range: 124..131, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 125..126, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 125..126, + id: Name("x"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 128..129, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 128..129, + id: Name("y"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -141,48 +146,51 @@ Module( arguments: Arguments { range: 154..164, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 155..158, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 155..156, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 157..158, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 160..163, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 160..161, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 162..163, - value: Int( - 2, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 155..158, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 155..156, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 157..158, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 160..163, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("y"), + range: 160..161, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 162..163, + value: Int( + 2, + ), + }, + ), + }, + ), ], }, }, @@ -208,24 +216,25 @@ Module( arguments: Arguments { range: 169..173, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 170..172, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 171..172, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 170..172, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 171..172, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -250,21 +259,22 @@ Module( arguments: Arguments { range: 178..183, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 179..182, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 181..182, - id: Name("x"), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 179..182, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 181..182, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -290,38 +300,40 @@ Module( arguments: Arguments { range: 197..205, node_index: NodeIndex(None), - args: [ - Name( - ExprName { + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 198..199, + id: Name("x"), + ctx: Load, + }, + ), + ), + Keyword( + Keyword { + range: 201..204, node_index: NodeIndex(None), - range: 198..199, - id: Name("x"), - ctx: Load, + arg: Some( + Identifier { + id: Name("y"), + range: 201..202, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 203..204, + value: Int( + 1, + ), + }, + ), }, ), ], - keywords: [ - Keyword { - range: 201..204, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 201..202, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 203..204, - value: Int( - 1, - ), - }, - ), - }, - ], }, }, ), @@ -346,32 +358,35 @@ Module( arguments: Arguments { range: 210..217, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 211..212, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 211..212, + id: Name("x"), + ctx: Load, + }, + ), ), - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 214..216, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 215..216, - id: Name("y"), - ctx: Load, - }, - ), - ctx: Load, - }, + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 214..216, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 215..216, + id: Name("y"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -396,30 +411,32 @@ Module( arguments: Arguments { range: 222..230, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 223..224, - id: Name("x"), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 226..229, - node_index: NodeIndex(None), - arg: None, - value: Name( + items: [ + Positional( + Name( ExprName { node_index: NodeIndex(None), - range: 228..229, - id: Name("y"), + range: 223..224, + id: Name("x"), ctx: Load, }, ), - }, + ), + Keyword( + Keyword { + range: 226..229, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 228..229, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -445,44 +462,46 @@ Module( arguments: Arguments { range: 235..244, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { + items: [ + Keyword( + Keyword { + range: 236..239, node_index: NodeIndex(None), - range: 241..243, - value: Name( - ExprName { + arg: Some( + Identifier { + id: Name("x"), + range: 236..237, node_index: NodeIndex(None), - range: 242..243, - id: Name("y"), - ctx: Load, }, ), - ctx: Load, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 238..239, + value: Int( + 1, + ), + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 236..239, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 236..237, + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 238..239, - value: Int( - 1, + range: 241..243, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 242..243, + id: Name("y"), + ctx: Load, + }, ), + ctx: Load, }, ), - }, + ), ], }, }, @@ -508,41 +527,44 @@ Module( arguments: Arguments { range: 249..259, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 250..253, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 250..251, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 252..253, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 255..258, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 257..258, - id: Name("y"), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 250..253, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 250..251, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 252..253, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 255..258, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 257..258, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -568,37 +590,39 @@ Module( arguments: Arguments { range: 264..273, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 265..267, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 266..267, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 269..272, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + items: [ + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - range: 271..272, - id: Name("y"), + range: 265..267, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 266..267, + id: Name("x"), + ctx: Load, + }, + ), ctx: Load, }, ), - }, + ), + Keyword( + Keyword { + range: 269..272, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 271..272, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -624,40 +648,45 @@ Module( arguments: Arguments { range: 278..288, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 279..281, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 280..281, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 279..281, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 280..281, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 283..284, - id: Name("y"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 283..284, + id: Name("y"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 286..287, - id: Name("z"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 286..287, + id: Name("z"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -682,61 +711,66 @@ Module( arguments: Arguments { range: 293..308, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 294..297, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 296..297, - id: Name("x"), - ctx: Load, - }, - ), - }, - Keyword { - range: 299..302, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 299..300, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 301..302, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 304..307, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("z"), - range: 304..305, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 306..307, - value: Int( - 2, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 294..297, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 296..297, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + Keyword( + Keyword { + range: 299..302, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("y"), + range: 299..300, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 301..302, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 304..307, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("z"), + range: 304..305, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 306..307, + value: Int( + 2, + ), + }, + ), + }, + ), ], }, }, @@ -762,65 +796,71 @@ Module( arguments: Arguments { range: 313..335, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 314..317, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 315..317, - id: Name("x1"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 319..322, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 320..322, - id: Name("x2"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - keywords: [ - Keyword { - range: 324..328, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + items: [ + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - range: 326..328, - id: Name("y1"), + range: 314..317, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 315..317, + id: Name("x1"), + ctx: Load, + }, + ), ctx: Load, }, ), - }, - Keyword { - range: 330..334, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { + ), + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - range: 332..334, - id: Name("y2"), + range: 319..322, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 320..322, + id: Name("x2"), + ctx: Load, + }, + ), ctx: Load, }, ), - }, + ), + Keyword( + Keyword { + range: 324..328, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 326..328, + id: Name("y1"), + ctx: Load, + }, + ), + }, + ), + Keyword( + Keyword { + range: 330..334, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 332..334, + id: Name("y2"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -846,61 +886,66 @@ Module( arguments: Arguments { range: 340..355, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 341..344, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 341..342, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 343..344, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 346..349, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 348..349, - id: Name("y"), - ctx: Load, - }, - ), - }, - Keyword { - range: 351..354, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("z"), - range: 351..352, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 353..354, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 341..344, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 341..342, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 343..344, + value: Int( + 1, + ), + }, + ), + }, + ), + Keyword( + Keyword { + range: 346..349, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 348..349, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + Keyword( + Keyword { + range: 351..354, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("z"), + range: 351..352, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 353..354, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -926,50 +971,51 @@ Module( arguments: Arguments { range: 382..402, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 383..401, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 383..384, - node_index: NodeIndex(None), - }, - ), - value: If( - ExprIf { - node_index: NodeIndex(None), - range: 385..401, - test: BooleanLiteral( - ExprBooleanLiteral { - node_index: NodeIndex(None), - range: 390..394, - value: true, - }, - ), - body: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 385..386, - value: Int( - 1, - ), - }, - ), - orelse: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 400..401, - value: Int( - 2, - ), - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 383..401, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 383..384, + node_index: NodeIndex(None), + }, + ), + value: If( + ExprIf { + node_index: NodeIndex(None), + range: 385..401, + test: BooleanLiteral( + ExprBooleanLiteral { + node_index: NodeIndex(None), + range: 390..394, + value: true, + }, + ), + body: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 385..386, + value: Int( + 1, + ), + }, + ), + orelse: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 400..401, + value: Int( + 2, + ), + }, + ), + }, + ), + }, + ), ], }, }, @@ -995,33 +1041,34 @@ Module( arguments: Arguments { range: 407..418, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 408..417, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 408..409, - node_index: NodeIndex(None), - }, - ), - value: Await( - ExprAwait { - node_index: NodeIndex(None), - range: 410..417, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 416..417, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 408..417, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 408..409, + node_index: NodeIndex(None), + }, + ), + value: Await( + ExprAwait { + node_index: NodeIndex(None), + range: 410..417, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 416..417, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, @@ -1047,58 +1094,59 @@ Module( arguments: Arguments { range: 423..438, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 424..437, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 424..425, - node_index: NodeIndex(None), - }, - ), - value: Lambda( - ExprLambda { - node_index: NodeIndex(None), - range: 426..437, - parameters: Some( - Parameters { - range: 433..434, - node_index: NodeIndex(None), - items: [ - PositionalOrKeyword( - ParameterWithDefault { - range: 433..434, - node_index: NodeIndex(None), - parameter: Parameter { + items: [ + Keyword( + Keyword { + range: 424..437, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 424..425, + node_index: NodeIndex(None), + }, + ), + value: Lambda( + ExprLambda { + node_index: NodeIndex(None), + range: 426..437, + parameters: Some( + Parameters { + range: 433..434, + node_index: NodeIndex(None), + items: [ + PositionalOrKeyword( + ParameterWithDefault { range: 433..434, node_index: NodeIndex(None), - name: Identifier { - id: Name("y"), + parameter: Parameter { range: 433..434, node_index: NodeIndex(None), + name: Identifier { + id: Name("y"), + range: 433..434, + node_index: NodeIndex(None), + }, + annotation: None, }, - annotation: None, + default: None, }, - default: None, - }, - ), - ], - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 436..437, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - }, + ), + ], + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 436..437, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, @@ -1124,42 +1172,43 @@ Module( arguments: Arguments { range: 443..455, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 444..454, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 444..445, - node_index: NodeIndex(None), - }, - ), - value: Named( - ExprNamed { - node_index: NodeIndex(None), - range: 447..453, - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 447..448, - id: Name("y"), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 452..453, - value: Int( - 1, - ), - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 444..454, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 444..445, + node_index: NodeIndex(None), + }, + ), + value: Named( + ExprNamed { + node_index: NodeIndex(None), + range: 447..453, + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 447..448, + id: Name("y"), + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 452..453, + value: Int( + 1, + ), + }, + ), + }, + ), + }, + ), ], }, }, @@ -1185,25 +1234,26 @@ Module( arguments: Arguments { range: 480..491, node_index: NodeIndex(None), - args: [ - Yield( - ExprYield { - node_index: NodeIndex(None), - range: 482..489, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 488..489, - id: Name("x"), - ctx: Load, - }, + items: [ + Positional( + Yield( + ExprYield { + node_index: NodeIndex(None), + range: 482..489, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 488..489, + id: Name("x"), + ctx: Load, + }, + ), ), - ), - }, + }, + ), ), ], - keywords: [], }, }, ), @@ -1228,23 +1278,24 @@ Module( arguments: Arguments { range: 496..512, node_index: NodeIndex(None), - args: [ - YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 498..510, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 509..510, - id: Name("x"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 498..510, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 509..510, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1269,32 +1320,33 @@ Module( arguments: Arguments { range: 537..545, node_index: NodeIndex(None), - args: [ - Named( - ExprNamed { - node_index: NodeIndex(None), - range: 538..544, - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 538..539, - id: Name("x"), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 543..544, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Positional( + Named( + ExprNamed { + node_index: NodeIndex(None), + range: 538..544, + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 538..539, + id: Name("x"), + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 543..544, + value: Int( + 1, + ), + }, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1319,63 +1371,64 @@ Module( arguments: Arguments { range: 550..572, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 551..571, - elt: Named( - ExprNamed { - node_index: NodeIndex(None), - range: 551..557, - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 551..552, - id: Name("x"), - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 556..557, - value: Int( - 1, - ), - }, - ), - }, - ), - generators: [ - Comprehension { - range: 558..571, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 562..563, - id: Name("i"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 567..571, - id: Name("iter"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 551..571, + elt: Named( + ExprNamed { + node_index: NodeIndex(None), + range: 551..557, + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 551..552, + id: Name("x"), + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 556..557, + value: Int( + 1, + ), + }, + ), + }, + ), + generators: [ + Comprehension { + range: 558..571, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 562..563, + id: Name("i"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 567..571, + id: Name("iter"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), @@ -1400,41 +1453,42 @@ Module( arguments: Arguments { range: 600..610, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 601..609, - value: BoolOp( - ExprBoolOp { - node_index: NodeIndex(None), - range: 602..609, - op: And, - values: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 602..603, - id: Name("x"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 608..609, - id: Name("y"), - ctx: Load, - }, - ), - ], - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 601..609, + value: BoolOp( + ExprBoolOp { + node_index: NodeIndex(None), + range: 602..609, + op: And, + values: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 602..603, + id: Name("x"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 608..609, + id: Name("y"), + ctx: Load, + }, + ), + ], + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1459,39 +1513,40 @@ Module( arguments: Arguments { range: 615..623, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 616..622, - value: BinOp( - ExprBinOp { - node_index: NodeIndex(None), - range: 617..622, - left: Name( - ExprName { - node_index: NodeIndex(None), - range: 617..618, - id: Name("x"), - ctx: Load, - }, - ), - op: BitOr, - right: Name( - ExprName { - node_index: NodeIndex(None), - range: 621..622, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 616..622, + value: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 617..622, + left: Name( + ExprName { + node_index: NodeIndex(None), + range: 617..618, + id: Name("x"), + ctx: Load, + }, + ), + op: BitOr, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 621..622, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1516,30 +1571,31 @@ Module( arguments: Arguments { range: 628..638, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 629..637, - value: Await( - ExprAwait { - node_index: NodeIndex(None), - range: 630..637, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 636..637, - id: Name("x"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 629..637, + value: Await( + ExprAwait { + node_index: NodeIndex(None), + range: 630..637, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 636..637, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1564,55 +1620,56 @@ Module( arguments: Arguments { range: 643..657, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 644..656, - value: Lambda( - ExprLambda { - node_index: NodeIndex(None), - range: 645..656, - parameters: Some( - Parameters { - range: 652..653, - node_index: NodeIndex(None), - items: [ - PositionalOrKeyword( - ParameterWithDefault { - range: 652..653, - node_index: NodeIndex(None), - parameter: Parameter { + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 644..656, + value: Lambda( + ExprLambda { + node_index: NodeIndex(None), + range: 645..656, + parameters: Some( + Parameters { + range: 652..653, + node_index: NodeIndex(None), + items: [ + PositionalOrKeyword( + ParameterWithDefault { range: 652..653, node_index: NodeIndex(None), - name: Identifier { - id: Name("x"), + parameter: Parameter { range: 652..653, node_index: NodeIndex(None), + name: Identifier { + id: Name("x"), + range: 652..653, + node_index: NodeIndex(None), + }, + annotation: None, }, - annotation: None, + default: None, }, - default: None, - }, - ), - ], - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 655..656, - id: Name("x"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + ), + ], + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 655..656, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1637,45 +1694,46 @@ Module( arguments: Arguments { range: 662..681, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 663..680, - value: If( - ExprIf { - node_index: NodeIndex(None), - range: 664..680, - test: BooleanLiteral( - ExprBooleanLiteral { - node_index: NodeIndex(None), - range: 669..673, - value: true, - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 664..665, - id: Name("x"), - ctx: Load, - }, - ), - orelse: Name( - ExprName { - node_index: NodeIndex(None), - range: 679..680, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 663..680, + value: If( + ExprIf { + node_index: NodeIndex(None), + range: 664..680, + test: BooleanLiteral( + ExprBooleanLiteral { + node_index: NodeIndex(None), + range: 669..673, + value: true, + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 664..665, + id: Name("x"), + ctx: Load, + }, + ), + orelse: Name( + ExprName { + node_index: NodeIndex(None), + range: 679..680, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1700,21 +1758,22 @@ Module( arguments: Arguments { range: 704..709, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 705..708, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 707..708, - id: Name("x"), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 705..708, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 707..708, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), ], }, }, @@ -1740,38 +1799,39 @@ Module( arguments: Arguments { range: 714..725, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 715..724, - node_index: NodeIndex(None), - arg: None, - value: BoolOp( - ExprBoolOp { - node_index: NodeIndex(None), - range: 717..724, - op: And, - values: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 717..718, - id: Name("x"), - ctx: Load, - }, - ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 723..724, - id: Name("y"), - ctx: Load, - }, - ), - ], - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 715..724, + node_index: NodeIndex(None), + arg: None, + value: BoolOp( + ExprBoolOp { + node_index: NodeIndex(None), + range: 717..724, + op: And, + values: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 717..718, + id: Name("x"), + ctx: Load, + }, + ), + Name( + ExprName { + node_index: NodeIndex(None), + range: 723..724, + id: Name("y"), + ctx: Load, + }, + ), + ], + }, + ), + }, + ), ], }, }, @@ -1797,27 +1857,28 @@ Module( arguments: Arguments { range: 730..741, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 731..740, - node_index: NodeIndex(None), - arg: None, - value: Await( - ExprAwait { - node_index: NodeIndex(None), - range: 733..740, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 739..740, - id: Name("x"), - ctx: Load, - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 731..740, + node_index: NodeIndex(None), + arg: None, + value: Await( + ExprAwait { + node_index: NodeIndex(None), + range: 733..740, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 739..740, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, @@ -1843,42 +1904,43 @@ Module( arguments: Arguments { range: 746..766, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 747..765, - node_index: NodeIndex(None), - arg: None, - value: If( - ExprIf { - node_index: NodeIndex(None), - range: 749..765, - test: BooleanLiteral( - ExprBooleanLiteral { - node_index: NodeIndex(None), - range: 754..758, - value: true, - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 749..750, - id: Name("x"), - ctx: Load, - }, - ), - orelse: Name( - ExprName { - node_index: NodeIndex(None), - range: 764..765, - id: Name("y"), - ctx: Load, - }, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 747..765, + node_index: NodeIndex(None), + arg: None, + value: If( + ExprIf { + node_index: NodeIndex(None), + range: 749..765, + test: BooleanLiteral( + ExprBooleanLiteral { + node_index: NodeIndex(None), + range: 754..758, + value: true, + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 749..750, + id: Name("x"), + ctx: Load, + }, + ), + orelse: Name( + ExprName { + node_index: NodeIndex(None), + range: 764..765, + id: Name("y"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, @@ -1904,29 +1966,30 @@ Module( arguments: Arguments { range: 771..784, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 772..783, - node_index: NodeIndex(None), - arg: None, - value: Yield( - ExprYield { - node_index: NodeIndex(None), - range: 775..782, - value: Some( - Name( - ExprName { - node_index: NodeIndex(None), - range: 781..782, - id: Name("x"), - ctx: Load, - }, + items: [ + Keyword( + Keyword { + range: 772..783, + node_index: NodeIndex(None), + arg: None, + value: Yield( + ExprYield { + node_index: NodeIndex(None), + range: 775..782, + value: Some( + Name( + ExprName { + node_index: NodeIndex(None), + range: 781..782, + id: Name("x"), + ctx: Load, + }, + ), ), - ), - }, - ), - }, + }, + ), + }, + ), ], }, }, @@ -1952,52 +2015,53 @@ Module( arguments: Arguments { range: 789..804, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 790..803, - node_index: NodeIndex(None), - arg: None, - value: Lambda( - ExprLambda { - node_index: NodeIndex(None), - range: 792..803, - parameters: Some( - Parameters { - range: 799..800, - node_index: NodeIndex(None), - items: [ - PositionalOrKeyword( - ParameterWithDefault { - range: 799..800, - node_index: NodeIndex(None), - parameter: Parameter { + items: [ + Keyword( + Keyword { + range: 790..803, + node_index: NodeIndex(None), + arg: None, + value: Lambda( + ExprLambda { + node_index: NodeIndex(None), + range: 792..803, + parameters: Some( + Parameters { + range: 799..800, + node_index: NodeIndex(None), + items: [ + PositionalOrKeyword( + ParameterWithDefault { range: 799..800, node_index: NodeIndex(None), - name: Identifier { - id: Name("x"), + parameter: Parameter { range: 799..800, node_index: NodeIndex(None), + name: Identifier { + id: Name("x"), + range: 799..800, + node_index: NodeIndex(None), + }, + annotation: None, }, - annotation: None, + default: None, }, - default: None, - }, - ), - ], - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 802..803, - id: Name("x"), - ctx: Load, - }, - ), - }, - ), - }, + ), + ], + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 802..803, + id: Name("x"), + ctx: Load, + }, + ), + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap index baa336d282..83355028d2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap @@ -67,8 +67,7 @@ Module( arguments: Arguments { range: 21..23, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -97,8 +96,7 @@ Module( arguments: Arguments { range: 29..31, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -143,8 +141,7 @@ Module( arguments: Arguments { range: 42..44, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -159,8 +156,7 @@ Module( arguments: Arguments { range: 49..51, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -247,8 +243,7 @@ Module( arguments: Arguments { range: 83..85, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap index 4534340e06..d6d5dff400 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap @@ -126,8 +126,7 @@ Module( arguments: Arguments { range: 41..43, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap index 5f931e1947..0b390846d2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap @@ -29,8 +29,7 @@ Module( arguments: Arguments { range: 118..120, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -67,8 +66,7 @@ Module( arguments: Arguments { range: 130..132, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -128,8 +126,7 @@ Module( arguments: Arguments { range: 148..150, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -180,8 +177,7 @@ Module( arguments: Arguments { range: 160..162, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -234,8 +230,7 @@ Module( arguments: Arguments { range: 172..174, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -289,8 +284,7 @@ Module( arguments: Arguments { range: 184..186, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -346,8 +340,7 @@ Module( arguments: Arguments { range: 204..206, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -399,8 +392,7 @@ Module( arguments: Arguments { range: 216..218, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -469,8 +461,7 @@ Module( arguments: Arguments { range: 231..233, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -503,8 +494,7 @@ Module( arguments: Arguments { range: 243..245, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -528,8 +518,7 @@ Module( arguments: Arguments { range: 310..312, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -553,8 +542,7 @@ Module( arguments: Arguments { range: 318..320, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -577,8 +565,7 @@ Module( arguments: Arguments { range: 325..327, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -616,8 +603,7 @@ Module( arguments: Arguments { range: 336..338, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -643,8 +629,7 @@ Module( arguments: Arguments { range: 340..342, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -670,8 +655,7 @@ Module( arguments: Arguments { range: 346..348, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap index 786876d5af..5be07c1a85 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap @@ -1001,8 +1001,7 @@ Module( arguments: Arguments { range: 390..392, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1174,18 +1173,19 @@ Module( arguments: Arguments { range: 551..555, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 552..554, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 552..554, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1218,18 +1218,19 @@ Module( arguments: Arguments { range: 570..574, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 571..573, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 571..573, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap index d629f1f8e5..48666b7447 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap @@ -219,18 +219,19 @@ Module( arguments: Arguments { range: 69..72, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 70..71, - value: Int( - 5, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 70..71, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap index 0e276faa8e..7aa712247c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap @@ -1747,8 +1747,7 @@ Module( arguments: Arguments { range: 563..565, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap index 2871d852f2..fe12c02ab8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap @@ -634,162 +634,163 @@ Module( arguments: Arguments { range: 348..481, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 354..479, - elt: Name( - ExprName { - node_index: NodeIndex(None), - range: 354..357, - id: Name("sql"), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 362..479, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 366..369, - id: Name("sql"), - ctx: Store, - }, - ), - iter: Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 373..479, - elts: [ - If( - ExprIf { - node_index: NodeIndex(None), - range: 383..420, - test: Name( - ExprName { - node_index: NodeIndex(None), - range: 405..410, - id: Name("limit"), - ctx: Load, - }, - ), - body: BinOp( - ExprBinOp { - node_index: NodeIndex(None), - range: 383..401, - left: StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 383..393, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 383..393, - node_index: NodeIndex(None), - value: "LIMIT %d", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 354..479, + elt: Name( + ExprName { + node_index: NodeIndex(None), + range: 354..357, + id: Name("sql"), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 362..479, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 366..369, + id: Name("sql"), + ctx: Store, + }, + ), + iter: Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 373..479, + elts: [ + If( + ExprIf { + node_index: NodeIndex(None), + range: 383..420, + test: Name( + ExprName { + node_index: NodeIndex(None), + range: 405..410, + id: Name("limit"), + ctx: Load, + }, + ), + body: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 383..401, + left: StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 383..393, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 383..393, + node_index: NodeIndex(None), + value: "LIMIT %d", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, - ), - op: Mod, - right: Name( - ExprName { - node_index: NodeIndex(None), - range: 396..401, - id: Name("limit"), - ctx: Load, - }, - ), - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - node_index: NodeIndex(None), - range: 416..420, - }, - ), - }, - ), - If( - ExprIf { - node_index: NodeIndex(None), - range: 430..472, - test: Name( - ExprName { - node_index: NodeIndex(None), - range: 456..462, - id: Name("offset"), - ctx: Load, - }, - ), - body: BinOp( - ExprBinOp { - node_index: NodeIndex(None), - range: 431..451, - left: StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 431..442, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 431..442, - node_index: NodeIndex(None), - value: "OFFSET %d", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + ), + op: Mod, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 396..401, + id: Name("limit"), + ctx: Load, + }, + ), + }, + ), + orelse: NoneLiteral( + ExprNoneLiteral { + node_index: NodeIndex(None), + range: 416..420, + }, + ), + }, + ), + If( + ExprIf { + node_index: NodeIndex(None), + range: 430..472, + test: Name( + ExprName { + node_index: NodeIndex(None), + range: 456..462, + id: Name("offset"), + ctx: Load, + }, + ), + body: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 431..451, + left: StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 431..442, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 431..442, + node_index: NodeIndex(None), + value: "OFFSET %d", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, - ), - op: Mod, - right: Name( - ExprName { - node_index: NodeIndex(None), - range: 445..451, - id: Name("offset"), - ctx: Load, - }, - ), - }, - ), - orelse: NoneLiteral( - ExprNoneLiteral { - node_index: NodeIndex(None), - range: 468..472, - }, - ), - }, - ), - ], - ctx: Load, - parenthesized: true, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + op: Mod, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 445..451, + id: Name("offset"), + ctx: Load, + }, + ), + }, + ), + orelse: NoneLiteral( + ExprNoneLiteral { + node_index: NodeIndex(None), + 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 b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap index f1e416b8d5..0e80ef0230 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap @@ -76,8 +76,7 @@ Module( arguments: Arguments { range: 18..20, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap index c693cb7b3b..8d656f3930 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap @@ -962,8 +962,7 @@ Module( arguments: Arguments { range: 260..262, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1030,8 +1029,7 @@ Module( arguments: Arguments { range: 288..290, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1154,8 +1152,7 @@ Module( arguments: Arguments { range: 328..330, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap index b93fd0db86..9ba49b9611 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap @@ -823,93 +823,94 @@ Module( arguments: Arguments { range: 341..382, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 342..381, - elt: Call( - ExprCall { - node_index: NodeIndex(None), - range: 342..361, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 342..347, - id: Name("call2"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 347..361, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 342..381, + elt: Call( + ExprCall { node_index: NodeIndex(None), - args: [ - Call( - ExprCall { - node_index: NodeIndex(None), - range: 348..360, - func: Attribute( - ExprAttribute { + range: 342..361, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 342..347, + id: Name("call2"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 347..361, + node_index: NodeIndex(None), + items: [ + Positional( + Call( + ExprCall { node_index: NodeIndex(None), - range: 348..358, - value: Name( - ExprName { + range: 348..360, + func: Attribute( + ExprAttribute { node_index: NodeIndex(None), - range: 348..353, - id: Name("value"), + range: 348..358, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 348..353, + id: Name("value"), + ctx: Load, + }, + ), + attr: Identifier { + id: Name("attr"), + range: 354..358, + node_index: NodeIndex(None), + }, ctx: Load, }, ), - attr: Identifier { - id: Name("attr"), - range: 354..358, + arguments: Arguments { + range: 358..360, node_index: NodeIndex(None), + items: [], }, - ctx: Load, }, ), - arguments: Arguments { - range: 358..360, - node_index: NodeIndex(None), - args: [], - keywords: [], - }, - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, - ), - generators: [ - Comprehension { - range: 362..381, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 366..373, - id: Name("element"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 377..381, - id: Name("iter"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + ), + generators: [ + Comprehension { + range: 362..381, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 366..373, + id: Name("element"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 377..381, + id: Name("iter"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap index 2378341004..69f15b8a69 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap @@ -136,18 +136,19 @@ Module( arguments: Arguments { range: 45..48, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 46..47, - value: Int( - 5, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 46..47, + value: Int( + 5, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1051,38 +1052,39 @@ Module( arguments: Arguments { range: 437..456, node_index: NodeIndex(None), - args: [ - If( - ExprIf { - node_index: NodeIndex(None), - range: 438..455, - test: BooleanLiteral( - ExprBooleanLiteral { - node_index: NodeIndex(None), - range: 443..447, - value: true, - }, - ), - body: Name( - ExprName { - node_index: NodeIndex(None), - range: 438..439, - id: Name("x"), - ctx: Load, - }, - ), - orelse: List( - ExprList { - node_index: NodeIndex(None), - range: 453..455, - elts: [], - ctx: Load, - }, - ), - }, + items: [ + Positional( + If( + ExprIf { + node_index: NodeIndex(None), + range: 438..455, + test: BooleanLiteral( + ExprBooleanLiteral { + node_index: NodeIndex(None), + range: 443..447, + value: true, + }, + ), + body: Name( + ExprName { + node_index: NodeIndex(None), + range: 438..439, + id: Name("x"), + ctx: Load, + }, + ), + orelse: List( + ExprList { + node_index: NodeIndex(None), + range: 453..455, + elts: [], + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap index ad313fbab1..f343c4b7dc 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap @@ -615,8 +615,7 @@ Module( arguments: Arguments { range: 354..356, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -701,8 +700,7 @@ Module( arguments: Arguments { range: 431..433, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -789,42 +787,42 @@ Module( arguments: Arguments { range: 486..507, node_index: NodeIndex(None), - args: [ - Call( - ExprCall { - node_index: NodeIndex(None), - range: 487..506, - func: Attribute( - ExprAttribute { - node_index: NodeIndex(None), - range: 487..504, - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 487..493, - value: Int( - 11, - ), - }, - ), - attr: Identifier { - id: Name("bit_length"), - range: 494..504, - node_index: NodeIndex(None), - }, - ctx: Load, - }, - ), - arguments: Arguments { - range: 504..506, + items: [ + Positional( + Call( + ExprCall { node_index: NodeIndex(None), - args: [], - keywords: [], + range: 487..506, + func: Attribute( + ExprAttribute { + node_index: NodeIndex(None), + range: 487..504, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 487..493, + value: Int( + 11, + ), + }, + ), + attr: Identifier { + id: Name("bit_length"), + range: 494..504, + node_index: NodeIndex(None), + }, + ctx: Load, + }, + ), + arguments: Arguments { + range: 504..506, + node_index: NodeIndex(None), + items: [], + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -872,8 +870,7 @@ Module( arguments: Arguments { range: 529..531, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -921,8 +918,7 @@ Module( arguments: Arguments { range: 553..555, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1007,8 +1003,7 @@ Module( arguments: Arguments { range: 593..595, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1159,17 +1154,18 @@ Module( arguments: Arguments { range: 696..700, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 697..699, - id: Name("no"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 697..699, + id: Name("no"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap index 3f2d34df72..64b0c04410 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap @@ -43,8 +43,7 @@ Module( arguments: Arguments { range: 13..15, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -77,24 +76,21 @@ Module( arguments: Arguments { range: 22..24, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), arguments: Arguments { range: 24..26, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), arguments: Arguments { range: 26..28, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap index 329ee4b44b..1fa927ed71 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap @@ -1757,8 +1757,7 @@ Module( arguments: Arguments { range: 565..567, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap index 2a3291790b..0a92d34193 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap @@ -146,8 +146,7 @@ Module( arguments: Arguments { range: 50..52, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap index 7030c8e5a7..41f3448acb 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap @@ -126,8 +126,7 @@ Module( arguments: Arguments { range: 64..66, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lazy_import_semantic_ok_py315.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lazy_import_semantic_ok_py315.py.snap index 7acadae885..941df2c912 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lazy_import_semantic_ok_py315.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lazy_import_semantic_ok_py315.py.snap @@ -65,8 +65,7 @@ Module( arguments: Arguments { range: 89..91, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -132,8 +131,7 @@ Module( arguments: Arguments { range: 139..141, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap index c92dcca44f..754a08b084 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap @@ -548,8 +548,7 @@ Module( arguments: Arguments { range: 299..301, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap index 40eb8aafef..93006b3e48 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap @@ -29,27 +29,30 @@ Module( arguments: Arguments { range: 6..12, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 7..8, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 7..8, + value: Int( + 1, + ), + }, + ), ), - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 10..11, - value: Int( - 2, - ), - }, + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 10..11, + value: Int( + 2, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap index 707f5d2520..4865aafd19 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap @@ -72,18 +72,19 @@ Module( arguments: Arguments { range: 80..83, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 81..82, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 81..82, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -138,18 +139,19 @@ Module( arguments: Arguments { range: 112..115, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 113..114, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 113..114, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -260,18 +262,19 @@ Module( arguments: Arguments { range: 176..179, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 177..178, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 177..178, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap index cc2274a17e..cc83c74c04 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap @@ -77,17 +77,18 @@ Module( arguments: Arguments { range: 88..91, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 89..90, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 89..90, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -124,18 +125,19 @@ Module( arguments: Arguments { range: 107..110, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 108..109, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 108..109, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -229,17 +231,18 @@ Module( arguments: Arguments { range: 169..172, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 170..171, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 170..171, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -276,18 +279,19 @@ Module( arguments: Arguments { range: 188..191, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 189..190, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 189..190, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -370,17 +374,18 @@ Module( arguments: Arguments { range: 244..247, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 245..246, - id: Name("n"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 245..246, + id: Name("n"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -417,18 +422,19 @@ Module( arguments: Arguments { range: 263..266, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 264..265, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 264..265, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_keyword_args.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_keyword_args.py.snap index d96fb5a70f..a1f1aa8265 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_keyword_args.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_keyword_args.py.snap @@ -81,28 +81,29 @@ Module( arguments: Arguments { range: 19..24, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 20..23, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 20..21, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 22..23, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 20..23, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 20..21, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 22..23, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, @@ -214,78 +215,83 @@ Module( arguments: Arguments { range: 50..70, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 51..56, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("x"), - range: 51..52, - node_index: NodeIndex(None), - }, - ), - value: StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 53..56, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 53..56, - node_index: NodeIndex(None), - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Keyword( + Keyword { + range: 51..56, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("x"), + range: 51..52, + node_index: NodeIndex(None), + }, + ), + value: StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 53..56, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 53..56, + node_index: NodeIndex(None), + value: "a", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, + ), + }, + }, + ), + }, + ), + Keyword( + Keyword { + range: 58..61, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("y"), + range: 58..59, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 60..61, + value: Int( + 1, ), }, - }, - ), - }, - Keyword { - range: 58..61, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("y"), - range: 58..59, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 60..61, - value: Int( - 1, - ), - }, - ), - }, - Keyword { - range: 63..69, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("z"), - range: 63..64, - node_index: NodeIndex(None), - }, - ), - value: BooleanLiteral( - ExprBooleanLiteral { - node_index: NodeIndex(None), - range: 65..69, - value: true, - }, - ), - }, + ), + }, + ), + Keyword( + Keyword { + range: 63..69, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("z"), + range: 63..64, + node_index: NodeIndex(None), + }, + ), + value: BooleanLiteral( + ExprBooleanLiteral { + node_index: NodeIndex(None), + range: 65..69, + value: true, + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap index 32f31b1690..4c03b15f09 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap @@ -68,18 +68,19 @@ Module( arguments: Arguments { range: 22..25, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 23..24, - value: Int( - 0, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 23..24, + value: Int( + 0, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap index 91e6d3ec22..d0d05afe27 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap @@ -29,28 +29,29 @@ Module( arguments: Arguments { range: 44..51, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 45..50, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 46..47, - node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 49..50, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 45..50, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("a"), + range: 46..47, + node_index: NodeIndex(None), + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 49..50, + value: Int( + 1, + ), + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap index 1f14d31def..f922602b72 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap @@ -122,18 +122,19 @@ Module( arguments: Arguments { range: 87..90, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 88..89, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 88..89, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap index cfae3dd052..758e3480e8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap @@ -55,15 +55,16 @@ Module( arguments: Arguments { range: 56..62, node_index: NodeIndex(None), - args: [ - NoneLiteral( - ExprNoneLiteral { - node_index: NodeIndex(None), - range: 57..61, - }, + items: [ + Positional( + NoneLiteral( + ExprNoneLiteral { + node_index: NodeIndex(None), + range: 57..61, + }, + ), ), ], - keywords: [], }, }, ), @@ -94,18 +95,19 @@ Module( arguments: Arguments { range: 77..80, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 78..79, - value: Int( - 2, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 78..79, + value: Int( + 2, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap index 18d2a0eeff..f149cae7c8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap @@ -148,17 +148,18 @@ Module( arguments: Arguments { range: 107..110, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 108..109, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 108..109, + id: Name("a"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap index 0d5db2d14d..0bfc0df79e 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap @@ -148,17 +148,18 @@ Module( arguments: Arguments { range: 107..110, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 108..109, - id: Name("a"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 108..109, + id: Name("a"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep_798_unpacking_comprehensions_py315.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep_798_unpacking_comprehensions_py315.py.snap index 7ed54cd39f..5819eff205 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep_798_unpacking_comprehensions_py315.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep_798_unpacking_comprehensions_py315.py.snap @@ -228,55 +228,56 @@ Module( arguments: Arguments { range: 110..125, node_index: NodeIndex(None), - args: [ - Generator( - ExprGenerator { - node_index: NodeIndex(None), - range: 111..124, - elt: Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 111..113, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 112..113, - id: Name("x"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - generators: [ - Comprehension { - range: 114..124, - node_index: NodeIndex(None), - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 118..119, - id: Name("x"), - ctx: Store, - }, - ), - iter: Name( - ExprName { - node_index: NodeIndex(None), - range: 123..124, - id: Name("y"), - ctx: Load, - }, - ), - ifs: [], - is_async: false, - }, - ], - parenthesized: false, - }, + items: [ + Positional( + Generator( + ExprGenerator { + node_index: NodeIndex(None), + range: 111..124, + elt: Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 111..113, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 112..113, + id: Name("x"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + generators: [ + Comprehension { + range: 114..124, + node_index: NodeIndex(None), + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 118..119, + id: Name("x"), + ctx: Store, + }, + ), + iter: Name( + ExprName { + node_index: NodeIndex(None), + range: 123..124, + id: Name("y"), + ctx: Load, + }, + ), + ifs: [], + is_async: false, + }, + ], + parenthesized: false, + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@semicolon_before_match_identifier.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@semicolon_before_match_identifier.py.snap index a9380ddcfd..b3c3cd0445 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@semicolon_before_match_identifier.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@semicolon_before_match_identifier.py.snap @@ -29,8 +29,7 @@ Module( arguments: Arguments { range: 5..7, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -79,8 +78,7 @@ Module( arguments: Arguments { range: 28..30, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -105,17 +103,18 @@ Module( arguments: Arguments { range: 37..44, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 38..43, - id: Name("value"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 38..43, + id: Name("value"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -140,8 +139,7 @@ Module( arguments: Arguments { range: 50..52, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -206,8 +204,7 @@ Module( arguments: Arguments { range: 73..75, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_parenthesized_item_context_manager_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_parenthesized_item_context_manager_py38.py.snap index 09e2f6d782..b75ca6f690 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_parenthesized_item_context_manager_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_parenthesized_item_context_manager_py38.py.snap @@ -34,30 +34,31 @@ Module( arguments: Arguments { range: 56..67, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 57..66, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 57..66, - node_index: NodeIndex(None), - value: "foo.txt", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 57..66, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 57..66, + node_index: NodeIndex(None), + value: "foo.txt", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -113,30 +114,31 @@ Module( arguments: Arguments { range: 94..105, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 95..104, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 95..104, - node_index: NodeIndex(None), - value: "foo.txt", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 95..104, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 95..104, + node_index: NodeIndex(None), + value: "foo.txt", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap index 562a74ae6d..7f323e4ac0 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap @@ -71,57 +71,58 @@ Module( Arguments { range: 83..107, node_index: NodeIndex(None), - args: [ - Subscript( - ExprSubscript { - node_index: NodeIndex(None), - range: 84..106, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 84..91, - id: Name("Generic"), - ctx: Load, - }, - ), - slice: Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 92..105, - elts: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 92..97, - id: Name("DType"), - ctx: Load, - }, - ), - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 99..105, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 100..105, - id: Name("Shape"), - ctx: Load, - }, - ), - ctx: Load, - }, - ), - ], - ctx: Load, - parenthesized: false, - }, - ), - ctx: Load, - }, + items: [ + Positional( + Subscript( + ExprSubscript { + node_index: NodeIndex(None), + range: 84..106, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 84..91, + id: Name("Generic"), + ctx: Load, + }, + ), + slice: Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 92..105, + elts: [ + Name( + ExprName { + node_index: NodeIndex(None), + range: 92..97, + id: Name("DType"), + ctx: Load, + }, + ), + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 99..105, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 100..105, + id: Name("Shape"), + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ], + ctx: Load, + parenthesized: false, + }, + ), + ctx: Load, + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap index 306cefa984..de72d5763a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap @@ -946,8 +946,7 @@ Module( arguments: Arguments { range: 1129..1131, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -994,8 +993,7 @@ Module( arguments: Arguments { range: 1147..1149, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1042,8 +1040,7 @@ Module( arguments: Arguments { range: 1166..1168, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -1286,18 +1283,19 @@ Module( arguments: Arguments { range: 1261..1265, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 1262..1264, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 1262..1264, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1401,18 +1399,19 @@ Module( arguments: Arguments { range: 1308..1312, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 1309..1311, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 1309..1311, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -1503,18 +1502,19 @@ Module( arguments: Arguments { range: 1349..1353, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 1350..1352, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 1350..1352, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -2108,8 +2108,7 @@ Module( arguments: Arguments { range: 1821..1823, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2183,8 +2182,7 @@ Module( arguments: Arguments { range: 1878..1880, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2240,8 +2238,7 @@ Module( arguments: Arguments { range: 1923..1925, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2288,8 +2285,7 @@ Module( arguments: Arguments { range: 1963..1965, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2345,8 +2341,7 @@ Module( arguments: Arguments { range: 2007..2009, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2703,30 +2698,31 @@ Module( arguments: Arguments { range: 2180..2188, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 2181..2187, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2181..2187, - node_index: NodeIndex(None), - value: "a.py", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 2181..2187, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 2181..2187, + node_index: NodeIndex(None), + value: "a.py", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -2750,30 +2746,31 @@ Module( arguments: Arguments { range: 2196..2204, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 2197..2203, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2197..2203, - node_index: NodeIndex(None), - value: "b.py", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 2197..2203, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 2197..2203, + node_index: NodeIndex(None), + value: "b.py", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -4412,18 +4409,19 @@ Module( arguments: Arguments { range: 3532..3536, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 3533..3535, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 3533..3535, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -4501,18 +4499,19 @@ Module( arguments: Arguments { range: 3571..3575, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 3572..3574, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 3572..3574, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -4590,18 +4589,19 @@ Module( arguments: Arguments { range: 3604..3608, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 3605..3607, - value: Int( - 10, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 3605..3607, + value: Int( + 10, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap index 12e4eede1a..bd0a87aec7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap @@ -65,8 +65,7 @@ Module( arguments: Arguments { range: 24..26, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap index fc067dce47..0ac48d9fb2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap @@ -53,8 +53,7 @@ Module( Arguments { range: 32..34, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -122,57 +121,61 @@ Module( Arguments { range: 93..107, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { + items: [ + Keyword( + Keyword { + range: 94..97, node_index: NodeIndex(None), - range: 99..101, - value: Name( - ExprName { + arg: Some( + Identifier { + id: Name("a"), + range: 94..95, node_index: NodeIndex(None), - range: 100..101, - id: Name("A"), - ctx: Load, }, ), - ctx: Load, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 96..97, + value: Int( + 1, + ), + }, + ), }, ), - ], - keywords: [ - Keyword { - range: 94..97, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("a"), - range: 94..95, + Positional( + Starred( + ExprStarred { node_index: NodeIndex(None), - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 96..97, - value: Int( - 1, + range: 99..101, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 100..101, + id: Name("A"), + ctx: Load, + }, ), - }, - ), - }, - Keyword { - range: 103..106, - node_index: NodeIndex(None), - arg: None, - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 105..106, - id: Name("k"), ctx: Load, }, ), - }, + ), + Keyword( + Keyword { + range: 103..106, + node_index: NodeIndex(None), + arg: None, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 105..106, + id: Name("k"), + ctx: Load, + }, + ), + }, + ), ], }, ), @@ -287,25 +290,28 @@ Module( Arguments { range: 181..187, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 182..183, - id: Name("A"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 182..183, + id: Name("A"), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 185..186, - id: Name("B"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 185..186, + id: Name("B"), + ctx: Load, + }, + ), ), ], - keywords: [], }, ), body: [ @@ -478,8 +484,7 @@ Module( Arguments { range: 344..346, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -542,8 +547,7 @@ Module( Arguments { range: 395..397, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -606,8 +610,7 @@ Module( Arguments { range: 443..445, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -694,8 +697,7 @@ Module( Arguments { range: 515..517, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -776,8 +778,7 @@ Module( Arguments { range: 578..580, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -844,8 +845,7 @@ Module( Arguments { range: 622..624, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -912,8 +912,7 @@ Module( Arguments { range: 665..667, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -966,8 +965,7 @@ Module( Arguments { range: 704..706, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -1077,8 +1075,7 @@ Module( Arguments { range: 782..784, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -1180,8 +1177,7 @@ Module( Arguments { range: 861..863, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -1234,8 +1230,7 @@ Module( Arguments { range: 897..899, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -1314,8 +1309,7 @@ Module( Arguments { range: 959..961, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ @@ -1415,8 +1409,7 @@ Module( Arguments { range: 1012..1014, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap index a76750ea9d..a602c45e54 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap @@ -143,8 +143,7 @@ Module( arguments: Arguments { range: 88..90, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap index 8786f832a1..cd4160a071 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap @@ -3147,8 +3147,7 @@ Module( arguments: Arguments { range: 2045..2047, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap index e5254c3ee6..c77d71ec04 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap @@ -407,8 +407,7 @@ Module( arguments: Arguments { range: 201..203, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap index b92ffb2a01..5d05eed2e6 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap @@ -1613,8 +1613,7 @@ Module( arguments: Arguments { range: 1130..1132, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -4419,17 +4418,18 @@ Module( arguments: Arguments { range: 3019..3025, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 3020..3024, - id: Name("rest"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 3020..3024, + id: Name("rest"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -4603,17 +4603,18 @@ Module( arguments: Arguments { range: 3122..3129, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 3123..3128, - id: Name("label"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 3123..3128, + id: Name("label"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -8113,47 +8114,50 @@ Module( arguments: Arguments { range: 5225..5236, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 5226..5232, - value: BinOp( - ExprBinOp { - node_index: NodeIndex(None), - range: 5227..5232, - left: Name( - ExprName { - node_index: NodeIndex(None), - range: 5227..5228, - id: Name("a"), - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - node_index: NodeIndex(None), - range: 5231..5232, - id: Name("b"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 5226..5232, + value: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 5227..5232, + left: Name( + ExprName { + node_index: NodeIndex(None), + range: 5227..5228, + id: Name("a"), + ctx: Load, + }, + ), + op: Add, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 5231..5232, + id: Name("b"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 5234..5235, - id: Name("c"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 5234..5235, + id: Name("c"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -8304,24 +8308,25 @@ Module( arguments: Arguments { range: 5357..5361, node_index: NodeIndex(None), - args: [ - UnaryOp( - ExprUnaryOp { - node_index: NodeIndex(None), - range: 5358..5360, - op: USub, - operand: Name( - ExprName { - node_index: NodeIndex(None), - range: 5359..5360, - id: Name("a"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + UnaryOp( + ExprUnaryOp { + node_index: NodeIndex(None), + range: 5358..5360, + op: USub, + operand: Name( + ExprName { + node_index: NodeIndex(None), + range: 5359..5360, + id: Name("a"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -8372,8 +8377,7 @@ Module( arguments: Arguments { range: 5403..5405, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -8410,18 +8414,19 @@ Module( arguments: Arguments { range: 5430..5434, node_index: NodeIndex(None), - args: [ - Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 5431..5433, - elts: [], - ctx: Load, - parenthesized: true, - }, + items: [ + Positional( + Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 5431..5433, + elts: [], + ctx: Load, + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), @@ -8458,18 +8463,19 @@ Module( arguments: Arguments { range: 5461..5466, node_index: NodeIndex(None), - args: [ - Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 5462..5464, - elts: [], - ctx: Load, - parenthesized: true, - }, + items: [ + Positional( + Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 5462..5464, + elts: [], + ctx: Load, + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), @@ -8649,8 +8655,7 @@ Module( arguments: Arguments { range: 5609..5611, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -8889,39 +8894,41 @@ Module( arguments: Arguments { range: 5758..5769, node_index: NodeIndex(None), - args: [ - Call( - ExprCall { - node_index: NodeIndex(None), - range: 5759..5768, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 5759..5764, - id: Name("match"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 5764..5768, + items: [ + Positional( + Call( + ExprCall { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 5765..5767, - value: Int( - 12, + range: 5759..5768, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 5759..5764, + id: Name("match"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 5764..5768, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 5765..5767, + value: Int( + 12, + ), + }, ), - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap index a0ffcef8c0..0a695fe0dc 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap @@ -252,8 +252,7 @@ Module( arguments: Arguments { range: 110..112, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -292,8 +291,7 @@ Module( arguments: Arguments { range: 130..132, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap index 69c815cecb..88c5a5e6d1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap @@ -591,18 +591,19 @@ Module( arguments: Arguments { range: 468..471, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 469..470, - value: Int( - 1, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 469..470, + value: Int( + 1, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -653,76 +654,78 @@ Module( arguments: Arguments { range: 504..525, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 505..524, - value: FStringValue { - inner: Single( - FString { - range: 505..524, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 507..514, - node_index: NodeIndex(None), - value: "caught ", - }, - ), - Interpolation( - InterpolatedElement { - range: 514..523, - node_index: NodeIndex(None), - expression: Call( - ExprCall { - node_index: NodeIndex(None), - range: 515..522, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 515..519, - id: Name("type"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 519..522, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 505..524, + value: FStringValue { + inner: Single( + FString { + range: 505..524, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 507..514, + node_index: NodeIndex(None), + value: "caught ", + }, + ), + Interpolation( + InterpolatedElement { + range: 514..523, + node_index: NodeIndex(None), + expression: Call( + ExprCall { node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 520..521, - id: Name("e"), - ctx: Load, - }, - ), - ], - keywords: [], + range: 515..522, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 515..519, + id: Name("type"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 519..522, + node_index: NodeIndex(None), + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 520..521, + id: Name("e"), + ctx: Load, + }, + ), + ), + ], + }, }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: false, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -772,76 +775,78 @@ Module( arguments: Arguments { range: 556..577, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 557..576, - value: FStringValue { - inner: Single( - FString { - range: 557..576, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 559..566, - node_index: NodeIndex(None), - value: "caught ", - }, - ), - Interpolation( - InterpolatedElement { - range: 566..575, - node_index: NodeIndex(None), - expression: Call( - ExprCall { - node_index: NodeIndex(None), - range: 567..574, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 567..571, - id: Name("type"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 571..574, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 557..576, + value: FStringValue { + inner: Single( + FString { + range: 557..576, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 559..566, + node_index: NodeIndex(None), + value: "caught ", + }, + ), + Interpolation( + InterpolatedElement { + range: 566..575, + node_index: NodeIndex(None), + expression: Call( + ExprCall { node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 572..573, - id: Name("e"), - ctx: Load, - }, - ), - ], - keywords: [], + range: 567..574, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 567..571, + id: Name("type"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 571..574, + node_index: NodeIndex(None), + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 572..573, + id: Name("e"), + ctx: Load, + }, + ), + ), + ], + }, }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: false, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -881,159 +886,166 @@ Module( arguments: Arguments { range: 608..669, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 609..613, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 609..613, - node_index: NodeIndex(None), - value: "eg", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 609..613, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 609..613, + node_index: NodeIndex(None), + value: "eg", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), - List( - ExprList { - node_index: NodeIndex(None), - range: 615..668, - elts: [ - Call( - ExprCall { - node_index: NodeIndex(None), - range: 616..629, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 616..626, - id: Name("ValueError"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 626..629, + Positional( + List( + ExprList { + node_index: NodeIndex(None), + range: 615..668, + elts: [ + Call( + ExprCall { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 627..628, - value: Int( - 1, - ), - }, - ), - ], - keywords: [], - }, - }, - ), - Call( - ExprCall { - node_index: NodeIndex(None), - range: 631..643, - func: Name( - ExprName { + range: 616..629, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 616..626, + id: Name("ValueError"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 626..629, node_index: NodeIndex(None), - range: 631..640, - id: Name("TypeError"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 640..643, - node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 641..642, - value: Int( - 2, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 627..628, + value: Int( + 1, + ), + }, ), - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, - ), - Call( - ExprCall { - node_index: NodeIndex(None), - range: 645..655, - func: Name( - ExprName { + ), + Call( + ExprCall { + node_index: NodeIndex(None), + range: 631..643, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 631..640, + id: Name("TypeError"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 640..643, node_index: NodeIndex(None), - range: 645..652, - id: Name("OSError"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 652..655, - node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 653..654, - value: Int( - 3, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 641..642, + value: Int( + 2, + ), + }, ), - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, - ), - Call( - ExprCall { - node_index: NodeIndex(None), - range: 657..667, - func: Name( - ExprName { + ), + Call( + ExprCall { + node_index: NodeIndex(None), + range: 645..655, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 645..652, + id: Name("OSError"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 652..655, node_index: NodeIndex(None), - range: 657..664, - id: Name("OSError"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 664..667, - node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 665..666, - value: Int( - 4, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 653..654, + value: Int( + 3, + ), + }, ), - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, - ), - ], - ctx: Load, - }, + ), + Call( + ExprCall { + node_index: NodeIndex(None), + range: 657..667, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 657..664, + id: Name("OSError"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 664..667, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 665..666, + value: Int( + 4, + ), + }, + ), + ), + ], + }, + }, + ), + ], + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -1084,112 +1096,114 @@ Module( arguments: Arguments { range: 703..751, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 704..750, - value: FStringValue { - inner: Single( - FString { - range: 704..750, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 706..713, - node_index: NodeIndex(None), - value: "caught ", - }, - ), - Interpolation( - InterpolatedElement { - range: 713..722, - node_index: NodeIndex(None), - expression: Call( - ExprCall { - node_index: NodeIndex(None), - range: 714..721, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 714..718, - id: Name("type"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 718..721, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 704..750, + value: FStringValue { + inner: Single( + FString { + range: 704..750, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 706..713, + node_index: NodeIndex(None), + value: "caught ", + }, + ), + Interpolation( + InterpolatedElement { + range: 713..722, + node_index: NodeIndex(None), + expression: Call( + ExprCall { node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 719..720, - id: Name("e"), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - InterpolatedStringLiteralElement { - range: 722..735, - node_index: NodeIndex(None), - value: " with nested ", - }, - ), - Interpolation( - InterpolatedElement { - range: 735..749, - node_index: NodeIndex(None), - expression: Attribute( - ExprAttribute { - node_index: NodeIndex(None), - range: 736..748, - value: Name( - ExprName { + range: 714..721, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 714..718, + id: Name("type"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 718..721, node_index: NodeIndex(None), - range: 736..737, - id: Name("e"), - ctx: Load, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 719..720, + id: Name("e"), + ctx: Load, + }, + ), + ), + ], }, - ), - attr: Identifier { - id: Name("exceptions"), - range: 738..748, - node_index: NodeIndex(None), }, - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: false, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + Literal( + InterpolatedStringLiteralElement { + range: 722..735, + node_index: NodeIndex(None), + value: " with nested ", + }, + ), + Interpolation( + InterpolatedElement { + range: 735..749, + node_index: NodeIndex(None), + expression: Attribute( + ExprAttribute { + node_index: NodeIndex(None), + range: 736..748, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 736..737, + id: Name("e"), + ctx: Load, + }, + ), + attr: Identifier { + id: Name("exceptions"), + range: 738..748, + node_index: NodeIndex(None), + }, + ctx: Load, + }, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -1239,112 +1253,114 @@ Module( arguments: Arguments { range: 783..831, node_index: NodeIndex(None), - args: [ - FString( - ExprFString { - node_index: NodeIndex(None), - range: 784..830, - value: FStringValue { - inner: Single( - FString { - range: 784..830, - node_index: NodeIndex(None), - elements: [ - Literal( - InterpolatedStringLiteralElement { - range: 786..793, - node_index: NodeIndex(None), - value: "caught ", - }, - ), - Interpolation( - InterpolatedElement { - range: 793..802, - node_index: NodeIndex(None), - expression: Call( - ExprCall { - node_index: NodeIndex(None), - range: 794..801, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 794..798, - id: Name("type"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 798..801, + items: [ + Positional( + FString( + ExprFString { + node_index: NodeIndex(None), + range: 784..830, + value: FStringValue { + inner: Single( + FString { + range: 784..830, + node_index: NodeIndex(None), + elements: [ + Literal( + InterpolatedStringLiteralElement { + range: 786..793, + node_index: NodeIndex(None), + value: "caught ", + }, + ), + Interpolation( + InterpolatedElement { + range: 793..802, + node_index: NodeIndex(None), + expression: Call( + ExprCall { node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 799..800, - id: Name("e"), - ctx: Load, - }, - ), - ], - keywords: [], - }, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - InterpolatedStringLiteralElement { - range: 802..815, - node_index: NodeIndex(None), - value: " with nested ", - }, - ), - Interpolation( - InterpolatedElement { - range: 815..829, - node_index: NodeIndex(None), - expression: Attribute( - ExprAttribute { - node_index: NodeIndex(None), - range: 816..828, - value: Name( - ExprName { + range: 794..801, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 794..798, + id: Name("type"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 798..801, node_index: NodeIndex(None), - range: 816..817, - id: Name("e"), - ctx: Load, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 799..800, + id: Name("e"), + ctx: Load, + }, + ), + ), + ], }, - ), - attr: Identifier { - id: Name("exceptions"), - range: 818..828, - node_index: NodeIndex(None), }, - ctx: Load, - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, - unclosed: false, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + Literal( + InterpolatedStringLiteralElement { + range: 802..815, + node_index: NodeIndex(None), + value: " with nested ", + }, + ), + Interpolation( + InterpolatedElement { + range: 815..829, + node_index: NodeIndex(None), + expression: Attribute( + ExprAttribute { + node_index: NodeIndex(None), + range: 816..828, + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 816..817, + id: Name("e"), + ctx: Load, + }, + ), + attr: Identifier { + id: Name("exceptions"), + range: 818..828, + node_index: NodeIndex(None), + }, + ctx: Load, + }, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap index 2c6419571a..109d2582be 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap @@ -2120,47 +2120,50 @@ Module( arguments: Arguments { range: 1249..1260, node_index: NodeIndex(None), - args: [ - Starred( - ExprStarred { - node_index: NodeIndex(None), - range: 1250..1256, - value: BinOp( - ExprBinOp { - node_index: NodeIndex(None), - range: 1251..1256, - left: Name( - ExprName { - node_index: NodeIndex(None), - range: 1251..1252, - id: Name("a"), - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - node_index: NodeIndex(None), - range: 1255..1256, - id: Name("b"), - ctx: Load, - }, - ), - }, - ), - ctx: Load, - }, + items: [ + Positional( + Starred( + ExprStarred { + node_index: NodeIndex(None), + range: 1250..1256, + value: BinOp( + ExprBinOp { + node_index: NodeIndex(None), + range: 1251..1256, + left: Name( + ExprName { + node_index: NodeIndex(None), + range: 1251..1252, + id: Name("a"), + ctx: Load, + }, + ), + op: Add, + right: Name( + ExprName { + node_index: NodeIndex(None), + range: 1255..1256, + id: Name("b"), + ctx: Load, + }, + ), + }, + ), + ctx: Load, + }, + ), ), - Name( - ExprName { - node_index: NodeIndex(None), - range: 1258..1259, - id: Name("c"), - ctx: Load, - }, + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 1258..1259, + id: Name("c"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -2311,24 +2314,25 @@ Module( arguments: Arguments { range: 1375..1379, node_index: NodeIndex(None), - args: [ - UnaryOp( - ExprUnaryOp { - node_index: NodeIndex(None), - range: 1376..1378, - op: USub, - operand: Name( - ExprName { - node_index: NodeIndex(None), - range: 1377..1378, - id: Name("a"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + UnaryOp( + ExprUnaryOp { + node_index: NodeIndex(None), + range: 1376..1378, + op: USub, + operand: Name( + ExprName { + node_index: NodeIndex(None), + range: 1377..1378, + id: Name("a"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, }, ), @@ -2379,8 +2383,7 @@ Module( arguments: Arguments { range: 1419..1421, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2417,18 +2420,19 @@ Module( arguments: Arguments { range: 1444..1448, node_index: NodeIndex(None), - args: [ - Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 1445..1447, - elts: [], - ctx: Load, - parenthesized: true, - }, + items: [ + Positional( + Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 1445..1447, + elts: [], + ctx: Load, + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), @@ -2465,18 +2469,19 @@ Module( arguments: Arguments { range: 1473..1478, node_index: NodeIndex(None), - args: [ - Tuple( - ExprTuple { - node_index: NodeIndex(None), - range: 1474..1476, - elts: [], - ctx: Load, - parenthesized: true, - }, + items: [ + Positional( + Tuple( + ExprTuple { + node_index: NodeIndex(None), + range: 1474..1476, + elts: [], + ctx: Load, + parenthesized: true, + }, + ), ), ], - keywords: [], }, }, ), @@ -2656,8 +2661,7 @@ Module( arguments: Arguments { range: 1612..1614, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -2824,39 +2828,41 @@ Module( arguments: Arguments { range: 1703..1713, node_index: NodeIndex(None), - args: [ - Call( - ExprCall { - node_index: NodeIndex(None), - range: 1704..1712, - func: Name( - ExprName { - node_index: NodeIndex(None), - range: 1704..1708, - id: Name("type"), - ctx: Load, - }, - ), - arguments: Arguments { - range: 1708..1712, + items: [ + Positional( + Call( + ExprCall { node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 1709..1711, - value: Int( - 12, + range: 1704..1712, + func: Name( + ExprName { + node_index: NodeIndex(None), + range: 1704..1708, + id: Name("type"), + ctx: Load, + }, + ), + arguments: Arguments { + range: 1708..1712, + node_index: NodeIndex(None), + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 1709..1711, + value: Int( + 12, + ), + }, ), - }, - ), - ], - keywords: [], + ), + ], + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -2881,17 +2887,18 @@ Module( arguments: Arguments { range: 1718..1724, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 1719..1723, - id: Name("type"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 1719..1723, + id: Name("type"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -2969,17 +2976,18 @@ Module( arguments: Arguments { range: 1755..1758, node_index: NodeIndex(None), - args: [ - Name( - ExprName { - node_index: NodeIndex(None), - range: 1756..1757, - id: Name("b"), - ctx: Load, - }, + items: [ + Positional( + Name( + ExprName { + node_index: NodeIndex(None), + range: 1756..1757, + id: Name("b"), + ctx: Load, + }, + ), ), ], - keywords: [], }, }, ), @@ -3004,27 +3012,28 @@ Module( arguments: Arguments { range: 1766..1778, node_index: NodeIndex(None), - args: [], - keywords: [ - Keyword { - range: 1769..1776, - node_index: NodeIndex(None), - arg: Some( - Identifier { - id: Name("X"), - range: 1769..1770, - node_index: NodeIndex(None), - }, - ), - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 1773..1776, - id: Name("int"), - ctx: Load, - }, - ), - }, + items: [ + Keyword( + Keyword { + range: 1769..1776, + node_index: NodeIndex(None), + arg: Some( + Identifier { + id: Name("X"), + range: 1769..1770, + node_index: NodeIndex(None), + }, + ), + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 1773..1776, + id: Name("int"), + ctx: Load, + }, + ), + }, + ), ], }, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap index 283a612ef9..34c842a9bf 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap @@ -173,30 +173,31 @@ Module( arguments: Arguments { range: 95..111, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 96..110, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 96..110, - node_index: NodeIndex(None), - value: "Hello World!", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 96..110, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 96..110, + node_index: NodeIndex(None), + value: "Hello World!", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), @@ -223,30 +224,31 @@ Module( arguments: Arguments { range: 128..144, node_index: NodeIndex(None), - args: [ - StringLiteral( - ExprStringLiteral { - node_index: NodeIndex(None), - range: 129..143, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 129..143, - node_index: NodeIndex(None), - value: "Olá, Mundo!", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - unclosed: false, + items: [ + Positional( + StringLiteral( + ExprStringLiteral { + node_index: NodeIndex(None), + range: 129..143, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 129..143, + node_index: NodeIndex(None), + value: "Olá, Mundo!", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + unclosed: false, + }, }, - }, - ), + ), + }, }, - }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap index 7919e803c8..e898431584 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap @@ -354,8 +354,7 @@ Module( arguments: Arguments { range: 322..324, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), @@ -411,8 +410,7 @@ Module( arguments: Arguments { range: 344..346, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap index 98f879bacd..566df8d69d 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap @@ -169,8 +169,7 @@ Module( Arguments { range: 104..106, node_index: NodeIndex(None), - args: [], - keywords: [], + items: [], }, ), body: [ diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap index e95fef868f..c880e26ef4 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap @@ -122,18 +122,19 @@ Module( arguments: Arguments { range: 83..86, node_index: NodeIndex(None), - args: [ - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 84..85, - value: Int( - 3, - ), - }, + items: [ + Positional( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 84..85, + value: Int( + 3, + ), + }, + ), ), ], - keywords: [], }, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap index 93560699cf..a3dab986c7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap @@ -25,31 +25,32 @@ Module( Arguments { range: 7..18, node_index: NodeIndex(None), - args: [ - Named( - ExprNamed { - node_index: NodeIndex(None), - range: 8..17, - target: Name( - ExprName { - node_index: NodeIndex(None), - range: 8..9, - id: Name("y"), - ctx: Store, - }, - ), - value: Name( - ExprName { - node_index: NodeIndex(None), - range: 13..17, - id: Name("list"), - ctx: Load, - }, - ), - }, + items: [ + Positional( + Named( + ExprNamed { + node_index: NodeIndex(None), + range: 8..17, + target: Name( + ExprName { + node_index: NodeIndex(None), + range: 8..9, + id: Name("y"), + ctx: Store, + }, + ), + value: Name( + ExprName { + node_index: NodeIndex(None), + range: 13..17, + id: Name("list"), + ctx: Load, + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ @@ -102,26 +103,27 @@ Module( Arguments { range: 44..55, node_index: NodeIndex(None), - args: [ - Yield( - ExprYield { - node_index: NodeIndex(None), - range: 46..53, - value: Some( - NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 52..53, - value: Int( - 1, - ), - }, + items: [ + Positional( + Yield( + ExprYield { + node_index: NodeIndex(None), + range: 46..53, + value: Some( + NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 52..53, + value: Int( + 1, + ), + }, + ), ), - ), - }, + }, + ), ), ], - keywords: [], }, ), body: [ @@ -155,24 +157,25 @@ Module( Arguments { range: 72..88, node_index: NodeIndex(None), - args: [ - YieldFrom( - ExprYieldFrom { - node_index: NodeIndex(None), - range: 74..86, - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 85..86, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Positional( + YieldFrom( + ExprYieldFrom { + node_index: NodeIndex(None), + range: 74..86, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 85..86, + value: Int( + 1, + ), + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ @@ -228,24 +231,25 @@ Module( Arguments { range: 120..131, node_index: NodeIndex(None), - args: [ - Await( - ExprAwait { - node_index: NodeIndex(None), - range: 122..129, - value: NumberLiteral( - ExprNumberLiteral { - node_index: NodeIndex(None), - range: 128..129, - value: Int( - 1, - ), - }, - ), - }, + items: [ + Positional( + Await( + ExprAwait { + node_index: NodeIndex(None), + range: 122..129, + value: NumberLiteral( + ExprNumberLiteral { + node_index: NodeIndex(None), + range: 128..129, + value: Int( + 1, + ), + }, + ), + }, + ), ), ], - keywords: [], }, ), body: [ diff --git a/crates/ruff_python_semantic/src/analyze/class.rs b/crates/ruff_python_semantic/src/analyze/class.rs index 9e3100c04c..c7aa9d2540 100644 --- a/crates/ruff_python_semantic/src/analyze/class.rs +++ b/crates/ruff_python_semantic/src/analyze/class.rs @@ -43,7 +43,7 @@ where func: &mut dyn FnMut(&Expr) -> bool, seen: &mut FxHashSet, ) -> bool { - class_def.bases().iter().any(|expr| { + class_def.bases().any(|expr| { // If the base class itself matches the pattern, then this does too. // Ex) `class Foo(BaseModel): ...` if func(expr) { @@ -71,7 +71,7 @@ where }) } - if class_def.bases().is_empty() { + if class_def.bases().next().is_none() { return false; } @@ -432,7 +432,7 @@ pub fn is_metaclass(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> (false, _) => { // If it has >1 base class and a metaclass-like signature for `__new__`, // then it might be a metaclass. - if class_def.bases().is_empty() { + if class_def.bases().next().is_none() { IsMetaclass::No } else if has_metaclass_new_signature(class_def, semantic) { IsMetaclass::Maybe @@ -457,7 +457,7 @@ pub fn might_be_generic(class_def: &ast::StmtClassDef, semantic: &SemanticModel) return true; } - class_def.bases().iter().any(|base| { + class_def.bases().any(|base| { let Expr::Subscript(ExprSubscript { slice, .. }) = base else { return false; }; diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index f2bcf8d4ea..36e6831cba 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -2424,7 +2424,6 @@ impl<'a> SemanticModel<'a> { self.current_scopes().any(|scope| match scope.kind { ScopeKind::Class(class_def) => class_def .bases() - .iter() .any(|base| self.match_typing_expr(map_subscript(base), "Protocol")), ScopeKind::Function(function_def) => { visibility::is_abstract(&function_def.decorator_list, self) diff --git a/crates/ruff_python_semantic/src/model/all.rs b/crates/ruff_python_semantic/src/model/all.rs index 4ffefcd717..073d0dd4a1 100644 --- a/crates/ruff_python_semantic/src/model/all.rs +++ b/crates/ruff_python_semantic/src/model/all.rs @@ -170,13 +170,14 @@ impl SemanticModel<'_> { // Allow `tuple()`, `list()`, and their generic forms, like `list[int]()`. Expr::Call(ast::ExprCall { func, arguments, .. - }) if arguments.keywords.is_empty() - && arguments.args.len() <= 1 - && self - .resolve_builtin_symbol(map_subscript(func)) - .is_some_and(|symbol| matches!(symbol, "tuple" | "list")) => + }) if matches!( + arguments.items.as_slice(), + [] | [ast::Argument::Positional(_)] + ) && self + .resolve_builtin_symbol(map_subscript(func)) + .is_some_and(|symbol| matches!(symbol, "tuple" | "list")) => { - let [arg] = arguments.args.as_ref() else { + let [ast::Argument::Positional(arg)] = arguments.items.as_slice() else { return (None, DunderAllFlags::empty()); }; match arg { diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 43aadad240..164feff8dd 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -1571,7 +1571,7 @@ impl<'m> ContextCursor<'m> { // arguments := (positional arguments | keyword arguments | "*" expression | "**" expression)* ast::AnyNodeRef::Arguments(args) => { - args.args.iter().any(contains) || args.keywords.iter().any(|kw| contains(&kw.value)) + args.iter_source_order().any(|arg| contains(arg.value())) } ast::AnyNodeRef::Parameter(param) => param.annotation.as_deref().is_some_and(contains), ast::AnyNodeRef::ParameterWithDefault(param) => { @@ -1788,7 +1788,6 @@ impl<'db> CollectionContext<'db> { fn extract_base_class_names(class_def: &ast::StmtClassDef) -> FxHashSet { class_def .bases() - .iter() .filter_map(UnqualifiedName::from_expr) .map(|name| name.segments().join_compact(".")) .collect() @@ -2238,8 +2237,7 @@ fn detect_set_function_args<'m>(cursor: &ContextCursor<'m>) -> FxHashSet<&'m str _ => None, }) .map_or_default(|args| { - args.keywords - .iter() + args.keywords() .filter_map(|kw| kw.arg.as_ref().map(|ident| ident.id.as_str())) .collect() }) diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index f4b2e81cc0..d33a4bcdf0 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -585,12 +585,13 @@ impl<'a> SourceOrderVisitor<'a> for InlayHintVisitor<'a, '_> { source_order::walk_expr(self, expr); } Expr::Call(call) => { - let details = - if self.settings.call_argument_names && !call.arguments.args.is_empty() { - inlay_hint_call_argument_details(self.db, &self.model, call) - } else { - None - }; + let details = if self.settings.call_argument_names + && call.arguments.args().next().is_some() + { + inlay_hint_call_argument_details(self.db, &self.model, call) + } else { + None + }; self.visit_expr(&call.func); @@ -609,7 +610,7 @@ impl<'a> SourceOrderVisitor<'a> for InlayHintVisitor<'a, '_> { // `f(x=value(), *items())` would evaluate `items()` first and could // pass `x` twice. let is_last_positional = - positional_index + 1 == call.arguments.args.len(); + positional_index + 1 == call.arguments.args().count(); // For `def f(if): ...`, `name` is already normalized to the // reserved word `if`. Inserting `if=` would be a syntax error. // Repeating an existing keyword, as in `f(x=1, x=2)`, would be too. diff --git a/crates/ty_python_core/src/builder.rs b/crates/ty_python_core/src/builder.rs index 5ab913207e..f3e7a6db92 100644 --- a/crates/ty_python_core/src/builder.rs +++ b/crates/ty_python_core/src/builder.rs @@ -1239,10 +1239,10 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> { } } ast::Expr::Call(call) => { - for arg in &call.arguments.args { + for arg in call.arguments.args() { Self::walk_narrowing_alias_predicate(arg, f); } - for keyword in &call.arguments.keywords { + for keyword in call.arguments.keywords() { Self::walk_narrowing_alias_predicate(&keyword.value, f); } } @@ -6148,15 +6148,7 @@ impl<'ast> Unpackable<'ast> { /// Else, returns `None`. fn dunder_all_extend_argument(value: &ast::Expr) -> Option<&ast::Expr> { let ast::ExprCall { - func, - arguments: - ast::Arguments { - args, - keywords, - range: _, - node_index: _, - }, - .. + func, arguments, .. } = value.as_call_expr()?; let ast::ExprAttribute { value, attr, .. } = func.as_attribute_expr()?; @@ -6171,11 +6163,7 @@ fn dunder_all_extend_argument(value: &ast::Expr) -> Option<&ast::Expr> { return None; } - if !keywords.is_empty() { - return None; - } - - let [single_argument] = &**args else { + let [ast::Argument::Positional(single_argument)] = arguments.items.as_slice() else { return None; }; diff --git a/crates/ty_python_core/src/place.rs b/crates/ty_python_core/src/place.rs index 75b261e998..b7a01f38b1 100644 --- a/crates/ty_python_core/src/place.rs +++ b/crates/ty_python_core/src/place.rs @@ -668,13 +668,12 @@ impl<'db, 'a> PossiblyNarrowedPlacesBuilder<'db, 'a> { // narrow an explicit keyword argument. We don't know which keyword maps to the target // parameter while building the semantic index, so include every explicit keyword here. // This set is only a conservative upper bound. - for argument in expr_call.arguments.args.iter().take(2).chain( + for argument in expr_call.arguments.args().take(2).chain( expr_call .arguments - .keywords - .iter() + .keywords() .filter(|keyword| keyword.arg.is_some()) - .map(|keyword| &keyword.value), + .map(|keyword| keyword.value.as_ref()), ) { if let Some(place_expr) = PlaceExpr::try_from_expr(argument) && let Some(place) = self.places.place_id((&place_expr).into()) @@ -691,8 +690,10 @@ impl<'db, 'a> PossiblyNarrowedPlacesBuilder<'db, 'a> { } // `bool(expr)` can delegate to narrowing `expr` itself, e.g. `bool(x is not None)` - if let Some(first_arg) = expr_call.arguments.args.first() { - if expr_call.arguments.args.len() == 1 && expr_call.arguments.keywords.is_empty() { + if let Some(first_arg) = expr_call.arguments.args().next() { + if expr_call.arguments.args().count() == 1 + && expr_call.arguments.keywords().next().is_none() + { places.extend(self.expression_node(first_arg)); } } @@ -726,8 +727,8 @@ impl<'db, 'a> PossiblyNarrowedPlacesBuilder<'db, 'a> { match expr.expression_value() { // type(x) is Y can narrow x - ast::Expr::Call(call) if call.arguments.args.len() == 1 => { - if let Some(first_arg) = call.arguments.args.first() + ast::Expr::Call(call) if call.arguments.args().count() == 1 => { + if let Some(first_arg) = call.arguments.args().next() && let Some(place_expr) = PlaceExpr::try_from_expr(first_arg) && let Some(place) = self.places.place_id((&place_expr).into()) { diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 4a87b508bf..24559ddba1 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -419,9 +419,11 @@ fn definition_expression_type<'db>( /// Find a factory's `name` argument. If it is supplied twice, use the positional /// argument for error recovery. fn factory_name_argument(arguments: &ast::Arguments) -> Option<&ast::Expr> { - arguments - .find_positional(0) - .or_else(|| arguments.find_keyword("name").map(|keyword| &keyword.value)) + arguments.find_positional(0).or_else(|| { + arguments + .find_keyword("name") + .map(|keyword| keyword.value.as_ref()) + }) } /// Infer the literal name argument in a `TypeAliasType`, `TypeVar`, `ParamSpec`, or diff --git a/crates/ty_python_semantic/src/types/call/arguments.rs b/crates/ty_python_semantic/src/types/call/arguments.rs index d35b633f97..e580a3114c 100644 --- a/crates/ty_python_semantic/src/types/call/arguments.rs +++ b/crates/ty_python_semantic/src/types/call/arguments.rs @@ -683,7 +683,7 @@ impl<'a, 'db> CallArguments<'a, 'db> { arg: None, value, .. }), ) => { - let ast::Expr::Dict(ast::ExprDict { items, .. }) = value else { + let ast::Expr::Dict(ast::ExprDict { items, .. }) = value.as_ref() else { continue; }; let mut keywords = FxIndexMap::with_capacity_and_hasher( diff --git a/crates/ty_python_semantic/src/types/class/dynamic_literal.rs b/crates/ty_python_semantic/src/types/class/dynamic_literal.rs index 1fc60260d7..dd2d3b7ba5 100644 --- a/crates/ty_python_semantic/src/types/class/dynamic_literal.rs +++ b/crates/ty_python_semantic/src/types/class/dynamic_literal.rs @@ -154,12 +154,11 @@ impl get_size2::GetSize for DynamicClassLiteral<'_> {} /// Dynamic class constructors accept `bases` either as the second positional argument or as a /// `bases=` keyword argument. pub(crate) fn dynamic_class_bases_argument(arguments: &ast::Arguments) -> Option<&ast::Expr> { - arguments.args.get(1).or_else(|| { + arguments.args().nth(1).or_else(|| { arguments - .keywords - .iter() + .keywords() .find(|kw| kw.arg.as_deref() == Some("bases")) - .map(|kw| &kw.value) + .map(|kw| kw.value.as_ref()) }) } diff --git a/crates/ty_python_semantic/src/types/class/named_tuple.rs b/crates/ty_python_semantic/src/types/class/named_tuple.rs index e6416a2e2f..b2668298d9 100644 --- a/crates/ty_python_semantic/src/types/class/named_tuple.rs +++ b/crates/ty_python_semantic/src/types/class/named_tuple.rs @@ -460,7 +460,10 @@ impl<'db> DynamicNamedTupleLiteral<'db> { .expect("Expected `NamedTuple` definition to be an assignment") .as_call_expr() .expect("Expected `NamedTuple` definition r.h.s. to be a call expression"); - match definition_expression_type(db, definition, &node.arguments.args[1]) { + let Some(fields) = node.arguments.args().nth(1) else { + return NamedTupleSpec::unknown(db); + }; + match definition_expression_type(db, definition, fields) { Type::KnownInstance(KnownInstanceType::NamedTupleSpec(spec)) => spec, _ => NamedTupleSpec::unknown(db), } diff --git a/crates/ty_python_semantic/src/types/class/static_literal.rs b/crates/ty_python_semantic/src/types/class/static_literal.rs index 1605b5baf4..2dbc616fec 100644 --- a/crates/ty_python_semantic/src/types/class/static_literal.rs +++ b/crates/ty_python_semantic/src/types/class/static_literal.rs @@ -1179,9 +1179,9 @@ impl<'db> StaticClassLiteral<'db> { if let Some(arguments) = &class_def.node(&module).arguments { let mut flags = transformer_params.flags(db); - for ast::Keyword { arg, value, .. } in &arguments.keywords { + for ast::Keyword { arg, value, .. } in arguments.keywords() { if let Some(arg_name) = arg - && let ast::Expr::BooleanLiteral(is_set) = value + && let ast::Expr::BooleanLiteral(is_set) = value.as_ref() { for (flag_name, flag) in DATACLASS_FLAGS { if arg_name == *flag_name { @@ -3559,7 +3559,7 @@ pub(crate) fn expanded_class_base_entries<'a, 'db>( // but this causes more problems than it fixes. Some(KnownClass::NotImplementedType) => vec![], _ => { - let mut expanded_bases = Vec::with_capacity(class_stmt.bases().len()); + let mut expanded_bases = Vec::with_capacity(class_stmt.bases().count()); for base_node in class_stmt.bases() { if let Some(tuple) = @@ -3865,7 +3865,7 @@ fn explicit_bases_cycle_initial<'db>( // Try to produce a list of `Divergent` types of the right length. However, if one or more of // the bases is a starred expression, we don't know how many entries that will eventually // expand to. - vec![Type::divergent(id); class_stmt.bases().len()].into_boxed_slice() + vec![Type::divergent(id); class_stmt.bases().count()].into_boxed_slice() } fn explicit_bases_cycle_fn<'db>( diff --git a/crates/ty_python_semantic/src/types/dedicated/pydantic.rs b/crates/ty_python_semantic/src/types/dedicated/pydantic.rs index 1a53c37660..33723abd2b 100644 --- a/crates/ty_python_semantic/src/types/dedicated/pydantic.rs +++ b/crates/ty_python_semantic/src/types/dedicated/pydantic.rs @@ -891,8 +891,7 @@ fn own_model_config(db: &dyn Db, class: StaticClassLiteral<'_>) -> Option) -> ModelConf let Some(arguments) = class_node.arguments.as_ref() else { return ModelConfig::default(); }; - if arguments - .keywords - .iter() - .any(|keyword| keyword.arg.is_none()) - { + if arguments.keywords().any(|keyword| keyword.arg.is_none()) { return ModelConfig::unknown(); } // Keep this list of recognized options in sync with `own_model_config` and @@ -1156,7 +1151,7 @@ fn raw_input_validator_targets<'db>( continue; } - fields.extend(call.arguments.args.iter().filter_map(|field| { + fields.extend(call.arguments.args().filter_map(|field| { let name = decorators .expression_type(field)? .as_string_literal()? diff --git a/crates/ty_python_semantic/src/types/dedicated/pytest/fixtures.rs b/crates/ty_python_semantic/src/types/dedicated/pytest/fixtures.rs index e250eb2844..ba2af667ab 100644 --- a/crates/ty_python_semantic/src/types/dedicated/pytest/fixtures.rs +++ b/crates/ty_python_semantic/src/types/dedicated/pytest/fixtures.rs @@ -570,8 +570,7 @@ fn pytest_builtin_plugin_names<'db>(db: &'db dyn Db, program: Program<'db>) -> B .value .as_name_expr() .is_some_and(|name| name.id == "builtin_plugins") - && let [ast::Expr::StringLiteral(string)] = call.arguments.args.as_ref() - && call.arguments.keywords.is_empty() + && let Some(ast::Expr::StringLiteral(string)) = call.arguments.as_single_positional() { names.insert(string.value.to_str().to_owned()); } diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index c0ef04a38e..745dfff576 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -3664,10 +3664,10 @@ pub(crate) fn report_invalid_exception_cause(context: &InferContext, node: &ast: ); } -pub(crate) fn report_instance_layout_conflict( +pub(crate) fn report_instance_layout_conflict<'ast>( context: &InferContext, header_range: TextRange, - base_nodes: Option<&[ast::Expr]>, + base_node_at: impl Fn(usize) -> Option<&'ast ast::Expr>, disjoint_bases: &IncompatibleBases, ) { debug_assert!(disjoint_bases.len() > 1); @@ -3699,7 +3699,7 @@ pub(crate) fn report_instance_layout_conflict( } = disjoint_base_info; // Get the span for this base from the AST (if available) - let Some(base_node) = base_nodes.and_then(|nodes| nodes.get(*node_index)) else { + let Some(base_node) = base_node_at(*node_index) else { continue; }; @@ -5225,11 +5225,11 @@ struct GenericBaseConstraint<'db> { /// /// Returns `true` if an inconsistency was found, even when it is inherited or the diagnostic is /// disabled. -pub(crate) fn report_inconsistent_generic_bases<'db>( +pub(crate) fn report_inconsistent_generic_bases<'db, 'ast>( context: &InferContext<'db, '_>, header_range: TextRange, explicit_bases: &[Type<'db>], - base_nodes: Option<&[ast::Expr]>, + base_node_at: impl Fn(usize) -> Option<&'ast ast::Expr>, ) -> bool { let db = context.db(); let env = &context.program_environment(); @@ -5291,10 +5291,9 @@ pub(crate) fn report_inconsistent_generic_bases<'db>( Type::GenericAlias(alias) if alias.origin(db) == origin ); - if let (Some(earlier_base), Some(later_base)) = ( - base_nodes.and_then(|nodes| nodes.get(earlier.base_index)), - base_nodes.and_then(|nodes| nodes.get(base_index)), - ) { + if let (Some(earlier_base), Some(later_base)) = + (base_node_at(earlier.base_index), base_node_at(base_index)) + { diagnostic.annotate(context.secondary(earlier_base).message(format_args!( "Earlier class base inherits from `{}`", earlier.alias.display(db, env) diff --git a/crates/ty_python_semantic/src/types/ide_support.rs b/crates/ty_python_semantic/src/types/ide_support.rs index 00bec833cf..bf36cf1d66 100644 --- a/crates/ty_python_semantic/src/types/ide_support.rs +++ b/crates/ty_python_semantic/src/types/ide_support.rs @@ -1645,7 +1645,7 @@ pub fn inlay_hint_call_argument_details<'db>( let mut argument_names = HashMap::new(); - for arg_index in 0..call_expr.arguments.args.len() { + for arg_index in 0..call_expr.arguments.args().count() { let Some(arg_mapping) = resolved.argument_to_parameter_mapping.get(arg_index) else { continue; }; diff --git a/crates/ty_python_semantic/src/types/infer/builder.rs b/crates/ty_python_semantic/src/types/infer/builder.rs index 50fb5f7e0b..4ee383168f 100644 --- a/crates/ty_python_semantic/src/types/infer/builder.rs +++ b/crates/ty_python_semantic/src/types/infer/builder.rs @@ -14,8 +14,7 @@ use ruff_diagnostics::{Edit, Fix}; use ruff_python_ast::helpers::is_dotted_name; use ruff_python_ast::name::Name; use ruff_python_ast::{ - self as ast, AnyNodeRef, ArgOrKeyword, ArgumentsSourceOrder, ExprContext, HasNodeIndex, - PythonVersion, + self as ast, AnyNodeRef, ArgOrKeyword, ExprContext, HasNodeIndex, PythonVersion, }; use ruff_python_stdlib::builtins::version_builtin_was_added; use ruff_python_stdlib::typing::as_pep_585_generic; @@ -3817,7 +3816,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let env = self.program_environment(); let arguments = &call_expr.arguments; - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { return error( &self.context, "Keyword arguments are not supported in `NewType` creation", @@ -3825,7 +3824,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - if let Some(starred) = arguments.args.iter().find(|arg| arg.is_starred_expr()) { + if let Some(starred) = arguments.args().find(|arg| arg.is_starred_expr()) { return error( &self.context, "Starred arguments are not supported in `NewType` creation", @@ -3833,18 +3832,22 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - if arguments.args.len() != 2 { + let [ + ast::Argument::Positional(name_arg), + ast::Argument::Positional(_), + ] = arguments.items.as_slice() + else { return error( &self.context, format!( "Wrong number of arguments in `NewType` creation: expected 2, found {}", - arguments.args.len() + arguments.args().count() ), call_expr, ); - } + }; - let name_param_ty = self.infer_expression(&arguments.args[0], TypeContext::default()); + let name_param_ty = self.infer_expression(name_arg, TypeContext::default()); let name = name_param_ty .resolve_string_literal(db) @@ -3875,7 +3878,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { report_mismatched_type_name( &self.context, &MISMATCHED_NEWTYPE_NAME, - &arguments.args[0], + name_arg, "NewType", target_name, name, @@ -3911,24 +3914,20 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { return None; }; - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; - if args.iter().any(ast::Expr::is_starred_expr) { + if arguments.args().any(ast::Expr::is_starred_expr) { return None; } - let (name_arg, mut repr_arg) = match &**args { - [name_arg] => (name_arg, None), - [name_arg, repr_arg] => (name_arg, Some(repr_arg)), - _ => return None, - }; + let mut positional = arguments.args(); + let name_arg = positional.next()?; + let mut repr_arg = positional.next(); + if positional.next().is_some() { + return None; + } - for keyword in keywords { + for keyword in arguments.keywords() { let Some(keyword_name) = &keyword.arg else { return None; }; @@ -3937,7 +3936,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { return None; } - repr_arg = Some(&keyword.value); + repr_arg = Some(keyword.value.as_ref()); } let ast::Expr::StringLiteral(name_arg) = name_arg else { @@ -4041,7 +4040,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if func_ty == Type::SpecialForm(SpecialFormType::NamedTuple) { // Only the `fields` argument is deferred for `NamedTuple`; // other arguments are inferred eagerly. - self.infer_typing_namedtuple_fields(&arguments.args[1]); + if let Some(fields) = arguments.args().nth(1) { + self.infer_typing_namedtuple_fields(fields); + } return; } let known_class = func_ty @@ -4057,7 +4058,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { InferenceRegion::Deferred(definition), ) => { self.infer_typealiastype_assignment_deferred(definition, target, arguments); - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { let mut call_arguments = self.prepare_call_arguments(arguments); // Leave the types of `name`, `value`, and `type_params` unset because // these parameters have their own validation rules. @@ -4069,7 +4070,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { call_arguments.insert_type( index, TypeContext::default(), - self.expression_type(&keyword.value), + self.expression_type(keyword.value.as_ref()), ); } } @@ -4098,7 +4099,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { return; } let mut constraint_tys = Vec::new(); - for arg in arguments.args.iter().skip(1) { + for arg in arguments.args().skip(1) { let constraint = self.infer_type_expression(arg); constraint_tys.push(constraint); @@ -4151,12 +4152,15 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let default_ty = self.infer_type_expression(&default.value); let bound_or_constraints_node = arguments .find_keyword("bound") - .map(|kw| BoundOrConstraintsNodes::Bound(&kw.value)) + .map(|kw| BoundOrConstraintsNodes::Bound(kw.value.as_ref())) .or_else(|| { - if arguments.args.len() < 3 { - return None; - } - Some(BoundOrConstraintsNodes::Constraints(&arguments.args[1..])) + let mut args = arguments.args(); + let first = args.nth(1)?; + let last = args.next_back()?; + Some(BoundOrConstraintsNodes::Constraints(TextRange::new( + first.start(), + last.end(), + ))) }); self.validate_typevar_default( target.as_name_expr().map(|name| &*name.id), @@ -4173,13 +4177,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { fn infer_newtype_assignment_deferred(&mut self, arguments: &ast::Arguments) { let db = self.db(); let env = self.program_environment(); - let inferred = self.infer_type_expression(&arguments.args[1]); + let Some(base) = arguments.args().nth(1) else { + return; + }; + let inferred = self.infer_type_expression(base); if inferred.has_typevar_or_typevar_instance(db, env) { - if let Some(builder) = self - .context - .report_lint(&INVALID_NEWTYPE, &arguments.args[1]) - { + if let Some(builder) = self.context.report_lint(&INVALID_NEWTYPE, base) { let mut diag = builder.into_diagnostic("invalid base for `typing.NewType`"); diag.set_primary_annotation_message("A `NewType` base cannot be generic"); } @@ -4202,10 +4206,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { Type::Dynamic(DynamicType::Unknown) => return, _ => {} } - if let Some(builder) = self - .context - .report_lint(&INVALID_NEWTYPE, &arguments.args[1]) - { + if let Some(builder) = self.context.report_lint(&INVALID_NEWTYPE, base) { let mut diag = builder.into_diagnostic("invalid base for `typing.NewType`"); diag.set_primary_annotation_message(format!("type `{}`", inferred.display(db, env))); if matches!(inferred, Type::ProtocolInstance(_)) { @@ -4245,7 +4246,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let env = self.program_environment(); let arguments = &call_expr.arguments; - if let Some(starred) = arguments.args.iter().find(|arg| arg.is_starred_expr()) { + if let Some(starred) = arguments.args().find(|arg| arg.is_starred_expr()) { return error( &self.context, "Starred arguments are not supported in `TypeAliasType` creation", @@ -4253,12 +4254,12 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - if arguments.args.len() > 2 { + if arguments.args().count() > 2 { return error( &self.context, format_args!( "Expected at most 2 positional arguments to `TypeAliasType`, got {}", - arguments.args.len() + arguments.args().count() ), call_expr, ); @@ -4345,7 +4346,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let mut type_params = FxHashSet::default(); let mut valid_type_params = true; // Infer keyword arguments (e.g. `type_params`) so their types are stored. - for ast::Keyword { arg, value, .. } in &arguments.keywords { + for ast::Keyword { arg, value, .. } in arguments.keywords() { + let value = value.as_ref(); if std::ptr::eq(value, name_arg) || std::ptr::eq(value, value_arg) { continue; } @@ -5784,10 +5786,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let db = self.db(); let env = self.program_environment(); let arguments = &call_expression.arguments; - let [decorated_expression] = &arguments.args[..] else { + let [ast::Argument::Positional(decorated_expression)] = arguments.items.as_slice() else { return return_ty; }; - if !arguments.keywords.is_empty() || decorated_expression.is_starred_expr() { + if decorated_expression.is_starred_expr() { return return_ty; } @@ -9509,7 +9511,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { }) .with_known_unpacking(arguments, |expression| self.try_expression_type(expression)); - for arg in &arguments.args { + for arg in arguments.args() { if let ast::Expr::Starred(ast::ExprStarred { value, .. }) = arg { let iterable_type = self.expression_type(value); if let Err(err) = iterable_type.try_iterate(db, env) { @@ -9518,12 +9520,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } - for keyword in arguments - .keywords - .iter() - .filter(|keyword| keyword.arg.is_none()) - { - let mapping_type = self.expression_type(&keyword.value); + for keyword in arguments.keywords().filter(|keyword| keyword.arg.is_none()) { + let mapping_type = self.expression_type(keyword.value.as_ref()); if mapping_type.as_paramspec_typevar(self.db()).is_some() || mapping_type.unpack_keys_and_items(db, env).is_some() @@ -9533,7 +9531,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let Some(builder) = self .context - .report_lint(&INVALID_ARGUMENT_TYPE, &keyword.value) + .report_lint(&INVALID_ARGUMENT_TYPE, keyword.value.as_ref()) else { continue; }; @@ -9652,8 +9650,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { return None; }; if !class.is_known(self.db(), KnownClass::Range) - || !arguments.keywords.is_empty() - || arguments.args.iter().any(ast::Expr::is_starred_expr) + || arguments.keywords().next().is_some() + || arguments.args().any(ast::Expr::is_starred_expr) { return None; } @@ -9665,7 +9663,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { .as_int_literal() }; - let is_non_empty = match arguments.args.len() { + let is_non_empty = match arguments.args().count() { 1 => int_literal(0)? > 0, 2 => int_literal(0)? < int_literal(1)?, 3 => { @@ -9866,10 +9864,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if let Type::TypedDict(typed_dict_ty) = value_type && matches!(method_name, "get" | "pop" | "setdefault") - && !arguments.args.is_empty() + && arguments.args().next().is_some() && let Some(first_arg) = ( // Validate the key argument for `TypedDict` methods - arguments.args.first() + arguments.args().next() ) && let Some(key) = (match first_arg { ast::Expr::StringLiteral(ast::ExprStringLiteral { @@ -9898,10 +9896,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if !is_declared && method_name == "get" - && arguments.keywords.is_empty() - && matches!(arguments.args.len(), 1 | 2) + && arguments.keywords().next().is_none() + && matches!(arguments.args().count(), 1 | 2) { - let default_ty = if let Some(default) = arguments.args.get(1) { + let default_ty = if let Some(default) = arguments.args().nth(1) { self.get_or_infer_expression( default, TypeContext::preference(Some(field.declared_ty)), @@ -9920,13 +9918,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if field.is_read_only() { let mutation = match method_name { "pop" - if arguments.keywords.is_empty() - && matches!(arguments.args.len(), 1 | 2) => + if arguments.keywords().next().is_none() + && matches!(arguments.args().count(), 1 | 2) => { Some(("pop", "from")) } "setdefault" - if arguments.keywords.is_empty() && arguments.args.len() == 2 => + if arguments.keywords().next().is_none() + && arguments.args().count() == 2 => { Some(("set default for", "on")) } @@ -9934,7 +9933,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { }; if let Some((action, preposition)) = mutation { // Report errors within the arguments even though this mutation is invalid. - for argument in &arguments.args { + for argument in arguments.args() { self.get_or_infer_expression(argument, TypeContext::default()); } if let Some(builder) = @@ -9956,10 +9955,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if !is_declared && !field.is_read_only() { match method_name { "pop" - if arguments.keywords.is_empty() - && matches!(arguments.args.len(), 1 | 2) => + if arguments.keywords().next().is_none() + && matches!(arguments.args().count(), 1 | 2) => { - return arguments.args.get(1).map_or( + return arguments.args().nth(1).map_or( field.declared_ty, |default| { UnionType::from_two_elements( @@ -9975,9 +9974,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } "setdefault" - if arguments.keywords.is_empty() && arguments.args.len() == 2 => + if let [ + ast::Argument::Positional(_), + ast::Argument::Positional(default), + ] = arguments.items.as_slice() => { - let default = &arguments.args[1]; let default_ty = self.get_or_infer_expression( default, TypeContext::preference(Some(field.declared_ty)), @@ -10301,7 +10302,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } _ => false, }; - if is_reveal_type && let Some(first_arg) = arguments.args.first() { + if is_reveal_type && let Some(first_arg) = arguments.args().next() { let revealed_ty = self.expression_type(first_arg); report_revealed_type(&self.context, revealed_ty, first_arg); } @@ -13334,13 +13335,13 @@ fn prefer_collection_literal_peer_context<'db>( /// An iterator over arguments to a functional call. #[derive(Clone)] enum ArgumentsIter<'a> { - FromAst(ArgumentsSourceOrder<'a>), + FromAst(std::slice::Iter<'a, ast::Argument>), Synthesized(std::slice::Iter<'a, ArgOrKeyword<'a>>), } impl<'a> ArgumentsIter<'a> { fn from_ast(arguments: &'a ast::Arguments) -> Self { - Self::FromAst(arguments.iter_source_order()) + Self::FromAst(arguments.items.iter()) } fn synthesized(arguments: &'a [ArgOrKeyword<'a>]) -> Self { @@ -13353,7 +13354,7 @@ impl<'a> Iterator for ArgumentsIter<'a> { fn next(&mut self) -> Option { match self { - ArgumentsIter::FromAst(args) => args.next(), + ArgumentsIter::FromAst(args) => args.next().map(ast::Argument::as_ref), ArgumentsIter::Synthesized(args) => args.next().copied(), } } @@ -13834,5 +13835,5 @@ impl<'db, 'ast> AddBinding<'db, 'ast> { #[derive(Copy, Clone, Debug)] enum BoundOrConstraintsNodes<'ast> { Bound(&'ast ast::Expr), - Constraints(&'ast [ast::Expr]), + Constraints(TextRange), } diff --git a/crates/ty_python_semantic/src/types/infer/builder/class.rs b/crates/ty_python_semantic/src/types/infer/builder/class.rs index 4a51110570..6926661774 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/class.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/class.rs @@ -154,7 +154,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let has_explicit_bases = class_node .arguments .as_deref() - .is_some_and(|arguments| !arguments.args.is_empty()); + .is_some_and(|arguments| arguments.args().next().is_some()); let has_explicit_metaclass = class_node .arguments .as_deref() @@ -465,7 +465,6 @@ impl<'db> TypeInferenceBuilder<'db, '_> { if self.in_stub() || class_node .bases() - .iter() .any(|expr| any_over_expr(expr, &ast::Expr::is_string_literal_expr)) || class_node .arguments diff --git a/crates/ty_python_semantic/src/types/infer/builder/dict.rs b/crates/ty_python_semantic/src/types/infer/builder/dict.rs index 9b845b4b28..7c8ccb23fe 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/dict.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/dict.rs @@ -18,7 +18,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { call_expression_tcx: TypeContext<'db>, ) -> Option> { let db = self.db(); - if !arguments.args.is_empty() { + if arguments.args().next().is_some() { return None; } @@ -73,11 +73,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } } - if arguments - .keywords - .iter() - .any(|keyword| keyword.arg.is_none()) - { + if arguments.keywords().any(|keyword| keyword.arg.is_none()) { return None; } @@ -85,13 +81,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // reuse dict-literal inference. We key the synthetic name off the value node because // `infer_collection_literal` operates on expressions rather than keywords. let items = arguments - .keywords - .iter() - .map(|keyword| [Some(&keyword.value), Some(&keyword.value)]) + .keywords() + .map(|keyword| [Some(keyword.value.as_ref()), Some(keyword.value.as_ref())]) .collect_vec(); let keyword_names = arguments - .keywords - .iter() + .keywords() .filter_map(|keyword| { Some(( keyword.value.node_index().load(), diff --git a/crates/ty_python_semantic/src/types/infer/builder/dynamic_class.rs b/crates/ty_python_semantic/src/types/infer/builder/dynamic_class.rs index f3407d55ed..80554e54bc 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/dynamic_class.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/dynamic_class.rs @@ -302,7 +302,7 @@ pub(super) fn report_inconsistent_dynamic_generic_bases<'db>( context, dynamic_class.header_range(db), explicit_bases, - base_nodes, + |index| base_nodes.and_then(|nodes| nodes.get(index)), ); } diff --git a/crates/ty_python_semantic/src/types/infer/builder/enum_call.rs b/crates/ty_python_semantic/src/types/infer/builder/enum_call.rs index 576216e683..ce648d5e97 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/enum_call.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/enum_call.rs @@ -300,14 +300,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> { base_class: KnownClass, ) -> Option> { let db = self.db(); - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; - for kw in keywords { + for kw in arguments.keywords() { let Some(name) = &kw.arg else { continue; }; @@ -328,9 +323,12 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let start_kw = call_expr.arguments.find_keyword("start"); let type_kw = call_expr.arguments.find_keyword("type"); + let mut positional = arguments.args(); + let first = positional.next(); + let second = positional.next(); let has_positional_keyword_conflict = - (!args.is_empty() && value_kw.is_some()) || (args.len() >= 2 && names_kw.is_some()); - if !args.is_empty() + (first.is_some() && value_kw.is_some()) || (second.is_some() && names_kw.is_some()); + if first.is_some() && let Some(keyword) = value_kw && let Some(builder) = self .context @@ -341,7 +339,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { base_name = base_class.name(self.program_environment().python_version(db)), )); } - if args.len() >= 2 + if second.is_some() && let Some(keyword) = names_kw && let Some(builder) = self .context @@ -353,19 +351,16 @@ impl<'db> TypeInferenceBuilder<'db, '_> { )); } - let (name_arg, names_arg): (Option<&ast::Expr>, Option<&ast::Expr>) = match &**args { - [name, names, ..] => (Some(name), Some(names)), - [name] => (Some(name), names_kw.map(|kw| &kw.value)), - [] => (value_kw.map(|kw| &kw.value), names_kw.map(|kw| &kw.value)), - }; + let name_arg = first.or_else(|| value_kw.map(|kw| kw.value.as_ref())); + let names_arg = second.or_else(|| names_kw.map(|kw| kw.value.as_ref())); let name_arg = name_arg?; let env = self.program_environment(); - for arg in args { + for arg in arguments.args() { self.infer_expression(arg, TypeContext::default()); } - for kw in keywords { + for kw in arguments.keywords() { self.infer_expression(&kw.value, TypeContext::default()); } @@ -400,15 +395,16 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // Only 1 extra positional arg is allowed (the `names` parameter). // `Enum("Color", "RED", "GREEN")` is invalid at runtime. - let has_too_many_positional = args.len() > 2; - if has_too_many_positional + let first_extra_arg = positional.next(); + let has_too_many_positional = first_extra_arg.is_some(); + if let Some(extra_arg) = first_extra_arg && let Some(builder) = self .context - .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, &args[2]) + .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, extra_arg) { builder.into_diagnostic(format_args!( "Too many positional arguments to function `{base_name}`: expected 2, got {}", - args.len(), + arguments.args().count(), base_name = base_class.name(self.program_environment().python_version(db)), )); } diff --git a/crates/ty_python_semantic/src/types/infer/builder/function.rs b/crates/ty_python_semantic/src/types/infer/builder/function.rs index e7541ba8a5..8d33e0c457 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/function.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/function.rs @@ -2069,7 +2069,7 @@ impl KnownFunction { call_expression, self, *second_argument, - call_expression.arguments.args.get(1), + call_expression.arguments.args().nth(1), ); if self == KnownFunction::IsInstance { diff --git a/crates/ty_python_semantic/src/types/infer/builder/named_tuple.rs b/crates/ty_python_semantic/src/types/infer/builder/named_tuple.rs index d385480f70..8d287ab2e7 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/named_tuple.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/named_tuple.rs @@ -55,16 +55,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ) }; - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; // Check for variadic arguments early, before extracting positional args. - let has_starred = args.iter().any(ast::Expr::is_starred_expr); - let has_double_starred = keywords.iter().any(|kw| kw.arg.is_none()); + let has_starred = arguments.args().any(ast::Expr::is_starred_expr); + let has_double_starred = arguments.keywords().any(|kw| kw.arg.is_none()); // Emit diagnostic for missing required arguments or unsupported variadic arguments. // For `typing.NamedTuple`, emit a diagnostic since variadic arguments are not supported. @@ -88,49 +83,33 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // Extract typename and fields from positional or keyword arguments. // For `collections.namedtuple`, both `typename` and `field_names` can be keyword arguments. // For `typing.NamedTuple`, only positional arguments are supported. - let (name_arg, fields_arg, rest, name_from_keyword, fields_from_keyword): ( - Option<&ast::Expr>, - Option<&ast::Expr>, - &[ast::Expr], - bool, - bool, - ) = match kind { - NamedTupleKind::Collections => { - let typename_kw = call_expr.arguments.find_keyword("typename"); - let field_names_kw = call_expr.arguments.find_keyword("field_names"); - - match &**args { - [name, fields, rest @ ..] => (Some(name), Some(fields), rest, false, false), - [name, rest @ ..] => ( - Some(name), - field_names_kw.map(|kw| &kw.value), - rest, - false, - field_names_kw.is_some(), - ), - [] => ( - typename_kw.map(|kw| &kw.value), - field_names_kw.map(|kw| &kw.value), - &[], - typename_kw.is_some(), - field_names_kw.is_some(), - ), - } + let mut rest = arguments.args(); + let mut name_arg = rest.next(); + let mut fields_arg = rest.next(); + let mut name_from_keyword = false; + let mut fields_from_keyword = false; + if matches!(kind, NamedTupleKind::Collections) { + if name_arg.is_none() { + name_arg = arguments + .find_keyword("typename") + .map(|kw| kw.value.as_ref()); + name_from_keyword = name_arg.is_some(); } - NamedTupleKind::Typing => match &**args { - [name, fields, rest @ ..] => (Some(name), Some(fields), rest, false, false), - [name, rest @ ..] => (Some(name), None, rest, false, false), - [] => (None, None, &[], false, false), - }, - }; + if fields_arg.is_none() { + fields_arg = arguments + .find_keyword("field_names") + .map(|kw| kw.value.as_ref()); + fields_from_keyword = fields_arg.is_some(); + } + } // Check if we have both required arguments. let (Some(name_arg), Some(fields_arg)) = (name_arg, fields_arg) else { - for arg in args { + for arg in arguments.args() { self.infer_expression(arg, TypeContext::default()); } - for kw in keywords { - self.infer_expression(&kw.value, TypeContext::default()); + for kw in arguments.keywords() { + self.infer_expression(kw.value.as_ref(), TypeContext::default()); } if !has_starred && !has_double_starred { @@ -157,7 +136,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let name_type = self.infer_expression(name_arg, TypeContext::default()); - for arg in rest { + for arg in rest.clone() { self.infer_expression(arg, TypeContext::default()); } @@ -166,7 +145,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { if has_starred || has_double_starred { self.infer_expression(fields_arg, TypeContext::default()); - for kw in keywords { + for kw in arguments.keywords() { if let Some(arg) = kw.arg.as_deref() { if name_from_keyword && arg == "typename" { continue; @@ -175,20 +154,20 @@ impl<'db> TypeInferenceBuilder<'db, '_> { continue; } } - self.infer_expression(&kw.value, TypeContext::default()); + self.infer_expression(kw.value.as_ref(), TypeContext::default()); } return fallback(); } // Check for excess positional arguments (only `typename` and `fields` are expected). - if !rest.is_empty() { + if let Some(first_extra_arg) = rest.next() { if let Some(builder) = self .context - .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, &rest[0]) + .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, first_extra_arg) { builder.into_diagnostic(format_args!( "Too many positional arguments to function `{kind}`: expected 2, got {}", - args.len() + arguments.args().count() )); } } @@ -198,7 +177,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let mut defaults_kw: Option<&ast::Keyword> = None; let mut rename_type = None; - for kw in keywords { + for kw in arguments.keywords() { // `kw.arg` is `None` for double-starred kwargs (`**kwargs`), but we already // returned early above if there were any, so this should always be `Some`. let arg = kw @@ -215,16 +194,17 @@ impl<'db> TypeInferenceBuilder<'db, '_> { continue; } - let kw_type = self.infer_expression(&kw.value, TypeContext::default()); + let kw_type = self.infer_expression(kw.value.as_ref(), TypeContext::default()); match arg.id.as_str() { "defaults" if kind.is_collections() => { defaults_kw = Some(kw); - if let Some(element_types) = - extract_fixed_length_iterable_element_types(db, env, &kw.value, |expr| { - self.expression_type(expr) - }) - { + if let Some(element_types) = extract_fixed_length_iterable_element_types( + db, + env, + kw.value.as_ref(), + |expr| self.expression_type(expr), + ) { default_types = element_types.into_vec(); } else { // Can't determine individual types; use Any for each element. @@ -240,8 +220,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let valid_type = UnionType::from_two_elements(db, env, iterable_any, Type::none(db, env)); if !kw_type.is_assignable_to(db, env, valid_type) - && let Some(builder) = - self.context.report_lint(&INVALID_ARGUMENT_TYPE, &kw.value) + && let Some(builder) = self + .context + .report_lint(&INVALID_ARGUMENT_TYPE, kw.value.as_ref()) { let mut diagnostic = builder.into_diagnostic(format_args!( "Invalid argument to parameter `defaults` of `namedtuple()`" @@ -257,8 +238,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // Emit diagnostic for non-bool types. if !kw_type.is_assignable_to(db, env, KnownClass::Bool.to_instance(db, env)) - && let Some(builder) = - self.context.report_lint(&INVALID_ARGUMENT_TYPE, &kw.value) + && let Some(builder) = self + .context + .report_lint(&INVALID_ARGUMENT_TYPE, kw.value.as_ref()) { let mut diagnostic = builder.into_diagnostic(format_args!( "Invalid argument to parameter `rename` of `namedtuple()`" @@ -278,8 +260,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> { Type::none(db, env), ); if !kw_type.is_assignable_to(db, env, valid_type) - && let Some(builder) = - self.context.report_lint(&INVALID_ARGUMENT_TYPE, &kw.value) + && let Some(builder) = self + .context + .report_lint(&INVALID_ARGUMENT_TYPE, kw.value.as_ref()) { let mut diagnostic = builder.into_diagnostic(format_args!( "Invalid argument to parameter `module` of `namedtuple()`" @@ -293,7 +276,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // `typename` is valid as a keyword argument only for `collections.namedtuple`. // If it was already provided positionally, emit an error. "typename" if kind.is_collections() => { - if !args.is_empty() { + if arguments.args().next().is_some() { if let Some(builder) = self.context.report_lint(&PARAMETER_ALREADY_ASSIGNED, kw) { @@ -306,7 +289,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // `field_names` is valid only for `collections.namedtuple`. // If it was already provided positionally, emit an error. "field_names" if kind.is_collections() => { - if args.len() >= 2 { + if arguments.args().nth(1).is_some() { if let Some(builder) = self.context.report_lint(&PARAMETER_ALREADY_ASSIGNED, kw) { diff --git a/crates/ty_python_semantic/src/types/infer/builder/new_class.rs b/crates/ty_python_semantic/src/types/infer/builder/new_class.rs index 612ba6f9db..994b6a05f7 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/new_class.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/new_class.rs @@ -31,23 +31,20 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let env = self.program_environment(); let db = self.db(); - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; // `new_class(name, bases=(), kwds=None, exec_body=None)` // We need at least the `name` argument. - let no_positional_args = args.is_empty(); + let no_positional_args = arguments.args().next().is_none(); if no_positional_args { // Check if `name` is provided as a keyword argument. - let name_keyword = keywords.iter().find(|kw| kw.arg.as_deref() == Some("name")); + let name_keyword = arguments + .keywords() + .find(|kw| kw.arg.as_deref() == Some("name")); if name_keyword.is_none() { // Infer all keyword values for side effects. - for keyword in keywords { + for keyword in arguments.keywords() { self.infer_expression(&keyword.value, TypeContext::default()); } if let Some(builder) = self.context.report_lint(&NO_MATCHING_OVERLOAD, call_expr) { @@ -58,11 +55,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } // Find the arguments we treat specially while preserving normal call-binding diagnostics. - let name_node = args.first().or_else(|| { - keywords - .iter() + let name_node = arguments.args().next().or_else(|| { + arguments + .keywords() .find(|kw| kw.arg.as_deref() == Some("name")) - .map(|kw| &kw.value) + .map(|kw| kw.value.as_ref()) }); let bases_arg = dynamic_class_bases_argument(&call_expr.arguments); @@ -131,11 +128,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // TODO: Model `kwds`, especially `{"metaclass": Meta}`. `types.new_class()` uses the // third argument for explicit metaclass overrides, but we currently only account for // metaclass behavior that follows from the resolved bases. - let exec_body_arg = args.get(3).or_else(|| { - keywords - .iter() + let exec_body_arg = arguments.args().nth(3).or_else(|| { + arguments + .keywords() .find(|kw| kw.arg.as_deref() == Some("exec_body")) - .map(|kw| &kw.value) + .map(|kw| kw.value.as_ref()) }); let has_exec_body = exec_body_arg.is_some_and(|arg| !arg.is_none_literal_expr()); let members: Box<[(ast::name::Name, Type<'db>)]> = Box::new([]); @@ -163,7 +160,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { report_instance_layout_conflict( &self.context, dynamic_class.header_range(db), - bases_arg.as_tuple_expr().map(|tuple| tuple.elts.as_slice()), + |index| { + bases_arg + .as_tuple_expr() + .and_then(|tuple| tuple.elts.get(index)) + }, &disjoint_bases, ); } diff --git a/crates/ty_python_semantic/src/types/infer/builder/post_inference/dynamic_class.rs b/crates/ty_python_semantic/src/types/infer/builder/post_inference/dynamic_class.rs index 7ebd5b17cd..e2c66814fa 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/post_inference/dynamic_class.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/post_inference/dynamic_class.rs @@ -74,7 +74,7 @@ pub(crate) fn check_dynamic_class_definition<'db>( report_instance_layout_conflict( context, dynamic_class.header_range(db), - bases_tuple_elts, + |index| bases_tuple_elts.and_then(|nodes| nodes.get(index)), &disjoint_bases, ); } diff --git a/crates/ty_python_semantic/src/types/infer/builder/post_inference/static_class.rs b/crates/ty_python_semantic/src/types/infer/builder/post_inference/static_class.rs index 2ec58a8e90..e596271611 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/post_inference/static_class.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/post_inference/static_class.rs @@ -565,20 +565,22 @@ pub(crate) fn check_static_class_definitions<'db>( .map(|base| base.display(db, env)) .join(", ") )); - let can_rewrite_bases = bases_list.len() == class_node.bases().len() - && !class_node.bases().iter().any(ast::Expr::is_starred_expr); + let can_rewrite_bases = bases_list.len() == class_node.bases().count() + && !class_node.bases().any(ast::Expr::is_starred_expr); + let mut bases = class_node.bases(); if can_rewrite_bases && let Some(index) = *generic_index - && let [first_base, .., last_base] = class_node.bases() + && let Some(generic_base) = class_node.bases().nth(index) + && let (Some(first_base), Some(last_base)) = + (bases.next(), bases.next_back()) { let source = source_text(db, context.file()); - let generic_base = &source[class_node.bases()[index].range()]; + let generic_base = &source[generic_base.range()]; diagnostic.help(format_args!( "Move `{generic_base}` to the end of the bases list" )); let reordered_bases = class_node .bases() - .iter() .enumerate() .filter(|(i, _)| *i != index) .map(|(_, base)| &source[base.range()]) @@ -612,24 +614,25 @@ pub(crate) fn check_static_class_definitions<'db>( Ok(_) => { disjoint_bases.remove_redundant_entries(db); + let base_node = |index: usize| { + expanded_base_entries + .get(index) + .map(|entry| entry.source_node()) + }; if disjoint_bases.len() > 1 { report_instance_layout_conflict( context, class.header_range(db), - Some(class_node.bases()), + base_node, &disjoint_bases, ); } - let explicit_bases = class.explicit_bases(context.db()); - let base_nodes = (class_node.bases().len() == explicit_bases.len() - && !class_node.bases().iter().any(ast::Expr::is_starred_expr)) - .then_some(class_node.bases()); inconsistent_generic_bases = report_inconsistent_generic_bases( context, class.header_range(db), - explicit_bases, - base_nodes, + class.explicit_bases(db), + base_node, ); } } @@ -748,7 +751,7 @@ pub(crate) fn check_static_class_definitions<'db>( || class.typed_dict_module(db) == Some(TypingModule::TypingExtensions) || env.python_version(db) >= PythonVersion::PY315; - for keyword in &args.keywords { + for keyword in args.keywords() { if !supports_pep_728 && let Some(arg_name @ ("closed" | "extra_items")) = keyword.arg.as_deref() && let Some(builder) = context.report_lint(&UNKNOWN_ARGUMENT, keyword) @@ -809,8 +812,7 @@ pub(crate) fn check_static_class_definitions<'db>( } } else { let call_args: CallArguments = args - .keywords - .iter() + .keywords() .filter_map(|keyword| match keyword.arg.as_ref() { // We mimic the runtime behaviour and discard the metaclass argument Some(name) if name.id.as_str() == "metaclass" => None, diff --git a/crates/ty_python_semantic/src/types/infer/builder/suspicious_conditions/diagnostic.rs b/crates/ty_python_semantic/src/types/infer/builder/suspicious_conditions/diagnostic.rs index e6ea78a643..5a6181bec2 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/suspicious_conditions/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/suspicious_conditions/diagnostic.rs @@ -860,9 +860,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { && let (ast::Expr::Call(call), other) | (other, ast::Expr::Call(call)) = (left, single_comparator) && matches!(single_op, ast::CmpOp::Eq | ast::CmpOp::NotEq) - && let ast::Arguments { args, keywords, .. } = &call.arguments - && keywords.is_empty() - && let [single_arg] = &**args + && let [ast::Argument::Positional(single_arg)] = call.arguments.items.as_slice() && let Type::FunctionLiteral(function) = self.expression_type(&call.func) && function.is_known(db, KnownFunction::Len) && self.expression_type(other).is_int_literal() @@ -1501,7 +1499,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let (left, _, right) = compare.as_single()?; [Some(left), Some(right)] } - ast::Expr::Call(call) => [call.arguments.args.first(), None], + ast::Expr::Call(call) => [call.arguments.args().next(), None], _ => return None, }; diff --git a/crates/ty_python_semantic/src/types/infer/builder/type_call.rs b/crates/ty_python_semantic/src/types/infer/builder/type_call.rs index b0b70027fe..6b26790e39 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/type_call.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/type_call.rs @@ -12,6 +12,7 @@ use crate::types::infer::builder::{ }, }; use crate::types::{KnownClass, SubclassOfType, Type, TypeContext, definition_expression_type}; +use itertools::Itertools; use ruff_python_ast as ast; use ty_python_core::definition::Definition; @@ -34,25 +35,26 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let env = self.program_environment(); let db = self.db(); - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; - for keyword in keywords { + for keyword in arguments.keywords() { self.infer_expression(&keyword.value, TypeContext::default()); } - let [name_arg, bases_arg, namespace_arg] = match &**args { - [single] => { + let mut positional = arguments.args(); + let [name_arg, bases_arg, namespace_arg] = match ( + positional.next(), + positional.next(), + positional.next(), + positional.next(), + ) { + (Some(single), None, None, None) => { let arg_type = self.infer_expression(single, TypeContext::default()); - return if keywords.is_empty() { + return if arguments.keywords().next().is_none() { arg_type.dunder_class(db, env) } else { - if keywords.iter().any(|keyword| keyword.arg.is_some()) + if arguments.keywords().any(|keyword| keyword.arg.is_some()) && let Some(builder) = self.context.report_lint(&NO_MATCHING_OVERLOAD, call_expr) { @@ -66,12 +68,12 @@ impl<'db> TypeInferenceBuilder<'db, '_> { }; } - [first, second] if second.is_starred_expr() => { + (Some(first), Some(second), None, None) if second.is_starred_expr() => { self.infer_expression(first, TypeContext::default()); self.infer_expression(second, TypeContext::default()); - match &**keywords { - [single] if single.arg.is_none() => { + match arguments.keywords().collect_array() { + Some([single]) if single.arg.is_none() => { return SubclassOfType::subclass_of_unknown(); } _ => { @@ -90,10 +92,10 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } } - [name, bases, namespace] => [name, bases, namespace], + (Some(name), Some(bases), Some(namespace), None) => [name, bases, namespace], _ => { - for arg in args { + for arg in arguments.args() { self.infer_expression(arg, TypeContext::default()); } @@ -103,7 +105,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { diagnostic.help(format_args!( "`builtins.type()` can either be called with one or three \ positional arguments (got {})", - args.len() + arguments.args().count() )); } @@ -116,8 +118,8 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let namespace_type = self.infer_expression(namespace_arg, TypeContext::default()); // TODO: validate other keywords against `__init_subclass__` methods of superclasses - if keywords - .iter() + if arguments + .keywords() .any(|keyword| keyword.arg.as_deref() == Some("metaclass")) { if let Some(builder) = self.context.report_lint(&NO_MATCHING_OVERLOAD, call_expr) { @@ -130,7 +132,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // If any argument is a starred expression, we can't know how many positional arguments // we're receiving, so fall back to `type[Unknown]` to avoid false-positive errors. - if args.iter().any(ast::Expr::is_starred_expr) { + if arguments.args().any(ast::Expr::is_starred_expr) { return SubclassOfType::subclass_of_unknown(); } @@ -274,7 +276,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { report_instance_layout_conflict( &self.context, dynamic_class.header_range(db), - bases_arg.as_tuple_expr().map(|tuple| tuple.elts.as_slice()), + |index| { + bases_arg + .as_tuple_expr() + .and_then(|tuple| tuple.elts.get(index)) + }, &disjoint_bases, ); } @@ -324,7 +330,8 @@ impl<'db> TypeInferenceBuilder<'db, '_> { return; }; - let [_name_arg, bases_arg, _namespace_arg] = &*call.arguments.args else { + let Some([_name_arg, bases_arg, _namespace_arg]) = call.arguments.args().collect_array() + else { return; }; diff --git a/crates/ty_python_semantic/src/types/infer/builder/type_form.rs b/crates/ty_python_semantic/src/types/infer/builder/type_form.rs index 4359695fb8..33b1f2ffa4 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/type_form.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/type_form.rs @@ -138,8 +138,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ) -> Type<'db> { let arguments = &call_expression.arguments; - if let [argument] = &*arguments.args - && arguments.keywords.is_empty() + if let [ast::Argument::Positional(argument)] = arguments.items.as_slice() && !matches!(argument, ast::Expr::Starred(_)) { return TypeFormType::from_type_expression( @@ -148,10 +147,10 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ); } - for argument in &*arguments.args { + for argument in arguments.args() { self.infer_expression(argument, TypeContext::default()); } - for keyword in &*arguments.keywords { + for keyword in arguments.keywords() { self.infer_expression(&keyword.value, TypeContext::default()); } diff --git a/crates/ty_python_semantic/src/types/infer/builder/typed_dict.rs b/crates/ty_python_semantic/src/types/infer/builder/typed_dict.rs index 96549ac71e..23992783ec 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/typed_dict.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/typed_dict.rs @@ -75,9 +75,12 @@ enum TypedDictConstructorForm<'expr> { /// // Ex) `TD(other)` SinglePositional(&'expr ast::Expr), /// // Ex) `TD({"x": 1}, y=2)` - MixedLiteralAndKeywords(&'expr ast::ExprDict), + MixedLiteralAndKeywords { + argument: &'expr ast::Expr, + dict: &'expr ast::ExprDict, + }, /// // Ex) `TD(other, y=2)` - MixedPositionalAndKeywords, + MixedPositionalAndKeywords(&'expr ast::Expr), /// // Ex) `TD(*args)` or `TD(*args, y=2)` VariadicPositional, /// // Ex) `TD(arg1, arg2)` @@ -87,20 +90,22 @@ enum TypedDictConstructorForm<'expr> { impl<'expr> TypedDictConstructorForm<'expr> { /// Return the constructor form for `arguments`. fn from_arguments(arguments: &'expr ast::Arguments) -> Self { - let [argument] = &arguments.args[..] else { - return if arguments.args.is_empty() { - Self::KeywordOnly - } else { - Self::MultiplePositionalArguments - }; + let mut positional = arguments.args(); + let Some(argument) = positional.next() else { + return Self::KeywordOnly; }; - - match (argument, arguments.keywords.is_empty()) { + if positional.next().is_some() { + return Self::MultiplePositionalArguments; + } + match (argument, arguments.keywords().next().is_none()) { (argument, _) if argument.is_starred_expr() => Self::VariadicPositional, (ast::Expr::Dict(_), true) => Self::LiteralOnly(argument), - (ast::Expr::Dict(dict_expr), false) => Self::MixedLiteralAndKeywords(dict_expr), + (ast::Expr::Dict(dict_expr), false) => Self::MixedLiteralAndKeywords { + argument, + dict: dict_expr, + }, (_, true) => Self::SinglePositional(argument), - (_, false) => Self::MixedPositionalAndKeywords, + (_, false) => Self::MixedPositionalAndKeywords(argument), } } } @@ -118,17 +123,14 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ) -> Type<'db> { let env = self.program_environment(); let db = self.db(); - let ast::Arguments { - args, - keywords, - range: _, - node_index: _, - } = &call_expr.arguments; + let arguments = &call_expr.arguments; - let starred_arguments: SmallVec<[&ast::Expr; 1]> = - args.iter().filter(|arg| arg.is_starred_expr()).collect(); + let starred_arguments: SmallVec<[&ast::Expr; 1]> = arguments + .args() + .filter(|arg| arg.is_starred_expr()) + .collect(); let double_starred_arguments: SmallVec<[&ast::Keyword; 1]> = - keywords.iter().filter(|kw| kw.arg.is_none()).collect(); + arguments.keywords().filter(|kw| kw.arg.is_none()).collect(); // The fallback type reflects the fact that if the call were successful, // it would return a class that is a subclass of `Mapping[str, object]` @@ -191,7 +193,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { || typed_dict_module == TypingModule::TypingExtensions || self.program_environment().python_version(db) >= PythonVersion::PY315; - for kw in keywords { + for kw in arguments.keywords() { let Some(arg) = &kw.arg else { continue; }; @@ -207,10 +209,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { match &**arg { arg_name @ ("total" | "closed") => { - let kw_type = self.infer_expression(&kw.value, TypeContext::default()); + let kw_type = self.infer_expression(kw.value.as_ref(), TypeContext::default()); if !kw.value.is_boolean_literal_expr() - && let Some(builder) = - self.context.report_lint(&INVALID_ARGUMENT_TYPE, &kw.value) + && let Some(builder) = self + .context + .report_lint(&INVALID_ARGUMENT_TYPE, kw.value.as_ref()) { let mut diagnostic = builder.into_diagnostic(format_args!( "Invalid argument to parameter `{arg_name}` of `TypedDict()`" @@ -233,7 +236,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } "extra_items" => { if definition.is_none() { - let annotation = self.infer_extra_items_kwarg(&kw.value); + let annotation = self.infer_extra_items_kwarg(kw.value.as_ref()); extra_items = Some(TypedDictOpenness::extra( db, annotation.inner_type_or_unknown(), @@ -242,7 +245,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } } unknown_kwarg => { - self.infer_expression(&kw.value, TypeContext::default()); + self.infer_expression(kw.value.as_ref(), TypeContext::default()); if let Some(builder) = self.context.report_lint(&UNKNOWN_ARGUMENT, kw) { builder.into_diagnostic(format_args!( "Argument `{unknown_kwarg}` does not match any known parameter of function `TypedDict`", @@ -262,24 +265,24 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } if !starred_arguments.is_empty() || !double_starred_arguments.is_empty() { - for arg in args { + for arg in arguments.args() { self.infer_expression(arg, TypeContext::default()); } return fallback(); } - if args.len() > 2 + if let Some(extra_arg) = arguments.args().nth(2) && let Some(builder) = self .context - .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, &args[2]) + .report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, extra_arg) { builder.into_diagnostic(format_args!( "Too many positional arguments to function `TypedDict`: expected 2, got {}", - args.len() + arguments.args().count() )); } - let Some(name_arg) = args.first() else { + let Some(name_arg) = arguments.args().next() else { if let Some(builder) = self.context.report_lint(&MISSING_ARGUMENT, call_expr) { builder.into_diagnostic( "No arguments provided for required parameters `typename` \ @@ -292,7 +295,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let name_type = self.infer_expression(name_arg, TypeContext::default()); - let Some(fields_arg) = args.get(1) else { + let Some(fields_arg) = arguments.args().nth(1) else { if let Some(builder) = self.context.report_lint(&MISSING_ARGUMENT, call_expr) { builder.into_diagnostic( "No argument provided for required parameter `fields` of function `TypedDict`", @@ -301,7 +304,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { return fallback(); }; - for arg in args.iter().skip(2) { + for arg in arguments.args().skip(2) { self.infer_expression(arg, TypeContext::default()); } @@ -481,10 +484,10 @@ impl<'db> TypeInferenceBuilder<'db, '_> { callable_type, Type::ClassLiteral(class_literal) if class_literal.generic_context(db).is_some() ); - if is_generic && arguments.args.is_empty() { - for keyword in &arguments.keywords { + if is_generic && arguments.args().next().is_none() { + for keyword in arguments.keywords() { if keyword.arg.is_none() && !keyword.value.is_dict_expr() { - self.get_or_infer_expression(&keyword.value, TypeContext::default()); + self.get_or_infer_expression(keyword.value.as_ref(), TypeContext::default()); } } } @@ -529,17 +532,15 @@ impl<'db> TypeInferenceBuilder<'db, '_> { return_ty.unwrap_or_else(|CallError(_, bindings)| { self.context.mark_failed_call(call_expression); if can_infer - && arguments.keywords.iter().any(|keyword| { + && arguments.keywords().any(|keyword| { keyword .arg .as_ref() .and_then(|name| typed_dict.item(db, name.id.as_str())) .is_some_and(|field| { - !self.expression_type(&keyword.value).is_assignable_to( - db, - env, - field.declared_ty, - ) + !self + .expression_type(keyword.value.as_ref()) + .is_assignable_to(db, env, field.declared_ty) }) }) { @@ -598,9 +599,9 @@ impl<'db> TypeInferenceBuilder<'db, '_> { }); let typed_dict = TypedDictType::new(class_literal.identity_specialization(db)); - arguments.args.is_empty() + arguments.args().next().is_none() && !has_gradual_class_context - && arguments.keywords.iter().all(|keyword| { + && arguments.keywords().all(|keyword| { let permits_field_inference = |name: &str| { typed_dict.item(db, name).is_none_or(|field| { !any_over_type_expanding_aliases(db, env, field.declared_ty, |nested| { @@ -613,7 +614,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { return permits_field_inference(name.id.as_str()); } - self.try_expression_type(&keyword.value) + self.try_expression_type(keyword.value.as_ref()) .and_then(|ty| ty.resolve_type_alias(db).as_typed_dict()) .is_some_and(|unpacked| { unpacked.items(db).iter().all(|(name, field)| { @@ -648,7 +649,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let target_ty = Type::TypedDict(typed_dict); self.get_or_infer_expression(argument, TypeContext::preference(Some(target_ty))); } - TypedDictConstructorForm::MixedPositionalAndKeywords => { + TypedDictConstructorForm::MixedPositionalAndKeywords(argument) => { let unpacked_keyword_types = infer_unpacked_keyword_types(arguments, |expr, tcx| { self.get_or_infer_expression(expr, tcx) @@ -663,21 +664,18 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ); let positional_target = typed_dict_with_relaxed_keys(db, typed_dict, &keyword_keys); let target_ty = Type::TypedDict(positional_target); - self.get_or_infer_expression( - &arguments.args[0], - TypeContext::preference(Some(target_ty)), - ); + self.get_or_infer_expression(argument, TypeContext::preference(Some(target_ty))); } - TypedDictConstructorForm::MixedLiteralAndKeywords(dict_expr) => { - self.infer_typed_dict_constructor_dict_literal_values(typed_dict, dict_expr); - self.store_expression_type(&arguments.args[0], Type::unknown()); + TypedDictConstructorForm::MixedLiteralAndKeywords { argument, dict } => { + self.infer_typed_dict_constructor_dict_literal_values(typed_dict, dict); + self.store_expression_type(argument, Type::unknown()); } TypedDictConstructorForm::KeywordOnly | TypedDictConstructorForm::VariadicPositional | TypedDictConstructorForm::MultiplePositionalArguments => {} } - if !arguments.keywords.is_empty() { + if arguments.keywords().next().is_some() { self.infer_typed_dict_constructor_keyword_values( typed_dict, arguments, @@ -705,13 +703,13 @@ impl<'db> TypeInferenceBuilder<'db, '_> { arguments: &ast::Arguments, tcx: TypeContext<'db>, ) { - for keyword in &arguments.keywords { + for keyword in arguments.keywords() { let value_tcx = keyword .arg .as_ref() .and_then(|arg_name| typed_dict.item(self.db(), arg_name.id.as_str())) .map_or_default(|field| tcx.with_expected_type(Some(field.declared_ty))); - self.get_or_infer_expression(&keyword.value, value_tcx); + self.get_or_infer_expression(keyword.value.as_ref(), value_tcx); } } @@ -821,7 +819,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { /// definition is complete. This enables support for recursive `TypedDict`s where field types /// may reference the `TypedDict` being defined. pub(super) fn infer_functional_typeddict_deferred(&mut self, arguments: &ast::Arguments) { - if let Some(ast::Expr::Dict(dict_expr)) = arguments.args.get(1) { + if let Some(ast::Expr::Dict(dict_expr)) = arguments.args().nth(1) { for ast::DictItem { key, value } in dict_expr { if key.is_some() { self.infer_typeddict_field(value); diff --git a/crates/ty_python_semantic/src/types/infer/builder/typeguard.rs b/crates/ty_python_semantic/src/types/infer/builder/typeguard.rs index 15bed91ee7..588b4b7149 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/typeguard.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/typeguard.rs @@ -80,8 +80,8 @@ pub(super) fn bind_type_guard_return_type<'db>( // Preserve positional behavior when there isn't a unique callable binding whose // parameter mapping we can use. None => arguments - .args - .get(narrowed_argument_index()) + .args() + .nth(narrowed_argument_index()) .map(ast::ArgOrKeyword::from), }?; if argument.is_variadic() { diff --git a/crates/ty_python_semantic/src/types/infer/builder/typevar.rs b/crates/ty_python_semantic/src/types/infer/builder/typevar.rs index 4dc71b0e40..8bfa494bf6 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/typevar.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/typevar.rs @@ -147,9 +147,17 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if let Some(default_expr) = default.as_deref() { let default_ty = self.infer_type_expression(default_expr); if !self.check_default_for_outer_scope_typevars(default_ty, default_expr, &name.id) { - let bound_node = bound_node.map(|n| match n { - ast::Expr::Tuple(tuple) => BoundOrConstraintsNodes::Constraints(&tuple.elts), - _ => BoundOrConstraintsNodes::Bound(n), + let bound_node = bound_node.and_then(|node| match node { + ast::Expr::Tuple(tuple) => { + let [first, .., last] = tuple.elts.as_slice() else { + return None; + }; + Some(BoundOrConstraintsNodes::Constraints(TextRange::new( + first.start(), + last.end(), + ))) + } + _ => Some(BoundOrConstraintsNodes::Bound(node)), }); self.validate_typevar_default( Some(&name.id), @@ -219,12 +227,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { "TypeVar default is inconsistent \ with the TypeVar's constraints", ); - if let Some(BoundOrConstraintsNodes::Constraints([first, .., last])) = + if let Some(BoundOrConstraintsNodes::Constraints(range)) = bound_or_constraints_nodes { - let secondary = self - .context - .secondary(TextRange::new(first.start(), last.end())); + let secondary = self.context.secondary(range); let secondary = if let Some(name) = name { secondary.message(format_args!("Constraints of `{name}`")) } else { @@ -785,7 +791,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let mut name_param_ty = None; let mut name_param_node = None; - if arguments.args.len() > 1 { + if arguments.args().nth(1).is_some() { return error( &self.context, "`TypeVarTuple` can only have one positional argument", @@ -793,7 +799,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - if let Some(starred) = arguments.args.iter().find(|arg| arg.is_starred_expr()) { + if let Some(starred) = arguments.args().find(|arg| arg.is_starred_expr()) { return error( &self.context, "Starred arguments are not supported in `TypeVarTuple` creation", @@ -801,7 +807,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - for kwarg in &arguments.keywords { + for kwarg in arguments.keywords() { let Some(identifier) = kwarg.arg.as_ref() else { return error( &self.context, @@ -811,16 +817,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { }; match identifier.id().as_str() { "name" => { - if !arguments.args.is_empty() { + if arguments.args().next().is_some() { return error( &self.context, "The `name` parameter of `TypeVarTuple` can only be provided once", kwarg, ); } - name_param_node = Some(&kwarg.value); + name_param_node = Some(kwarg.value.as_ref()); name_param_ty = - Some(self.infer_expression(&kwarg.value, TypeContext::default())); + Some(self.infer_expression(kwarg.value.as_ref(), TypeContext::default())); } "default" => { if !assume_all_features @@ -861,7 +867,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => covariant = true, @@ -872,7 +878,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `covariant` parameter of `TypeVarTuple` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -888,7 +894,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => contravariant = true, @@ -899,7 +905,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `contravariant` parameter of `TypeVarTuple` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -915,7 +921,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => infer_variance = true, @@ -926,7 +932,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `infer_variance` parameter of `TypeVarTuple` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -939,7 +945,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ), kwarg, ); - self.infer_expression(&kwarg.value, TypeContext::default()); + self.infer_expression(kwarg.value.as_ref(), TypeContext::default()); } } } @@ -1065,7 +1071,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let mut name_param_ty = None; let mut name_param_node = None; - if arguments.args.len() > 1 { + if arguments.args().nth(1).is_some() { return error( &self.context, "`ParamSpec` can only have one positional argument", @@ -1073,7 +1079,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - if let Some(starred) = arguments.args.iter().find(|arg| arg.is_starred_expr()) { + if let Some(starred) = arguments.args().find(|arg| arg.is_starred_expr()) { return error( &self.context, "Starred arguments are not supported in `ParamSpec` creation", @@ -1081,7 +1087,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - for kwarg in &arguments.keywords { + for kwarg in arguments.keywords() { let Some(identifier) = kwarg.arg.as_ref() else { return error( &self.context, @@ -1093,16 +1099,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { "name" => { // Duplicate keyword argument is a syntax error, so we don't have to check if // `name_param_ty.is_some()` here. - if !arguments.args.is_empty() { + if arguments.args().next().is_some() { return error( &self.context, "The `name` parameter of `ParamSpec` can only be provided once", kwarg, ); } - name_param_node = Some(&kwarg.value); + name_param_node = Some(kwarg.value.as_ref()); name_param_ty = - Some(self.infer_expression(&kwarg.value, TypeContext::default())); + Some(self.infer_expression(kwarg.value.as_ref(), TypeContext::default())); } "bound" => { return error( @@ -1122,7 +1128,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => infer_variance = true, @@ -1133,14 +1139,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `infer_variance` parameter of `ParamSpec` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } } "covariant" => { match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => covariant = true, @@ -1151,14 +1157,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `covariant` parameter of `ParamSpec` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } } "contravariant" => { match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => contravariant = true, @@ -1169,7 +1175,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `contravariant` parameter of `ParamSpec` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -1198,7 +1204,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { format_args!("Unknown keyword argument `{name}` in `ParamSpec` creation"), kwarg, ); - self.infer_expression(&kwarg.value, TypeContext::default()); + self.infer_expression(kwarg.value.as_ref(), TypeContext::default()); } } } @@ -1325,7 +1331,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let mut name_param_ty = None; let mut name_param_node = None; - if let Some(starred) = arguments.args.iter().find(|arg| arg.is_starred_expr()) { + if let Some(starred) = arguments.args().find(|arg| arg.is_starred_expr()) { return error( &self.context, "Starred arguments are not supported in `TypeVar` creation", @@ -1333,7 +1339,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } - for kwarg in &arguments.keywords { + for kwarg in arguments.keywords() { let Some(identifier) = kwarg.arg.as_ref() else { return error( &self.context, @@ -1345,21 +1351,21 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { "name" => { // Duplicate keyword argument is a syntax error, so we don't have to check if // `name_param_ty.is_some()` here. - if !arguments.args.is_empty() { + if arguments.args().next().is_some() { return error( &self.context, "The `name` parameter of `TypeVar` can only be provided once.", kwarg, ); } - name_param_node = Some(&kwarg.value); + name_param_node = Some(kwarg.value.as_ref()); name_param_ty = - Some(self.infer_expression(&kwarg.value, TypeContext::default())); + Some(self.infer_expression(kwarg.value.as_ref(), TypeContext::default())); } "bound" => has_bound = true, "covariant" => { match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => covariant = true, @@ -1370,14 +1376,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `covariant` parameter of `TypeVar` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } } "contravariant" => { match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => contravariant = true, @@ -1388,7 +1394,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `contravariant` parameter of `TypeVar` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -1421,7 +1427,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); } match self - .infer_expression(&kwarg.value, TypeContext::default()) + .infer_expression(kwarg.value.as_ref(), TypeContext::default()) .bool(db, env) { Truthiness::AlwaysTrue => infer_variance = true, @@ -1432,7 +1438,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &self.context, "The `infer_variance` parameter of `TypeVar` \ cannot have an ambiguous truthiness", - &kwarg.value, + kwarg.value.as_ref(), ); } } @@ -1447,7 +1453,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { format_args!("Unknown keyword argument `{name}` in `TypeVar` creation"), kwarg, ); - self.infer_expression(&kwarg.value, TypeContext::default()); + self.infer_expression(kwarg.value.as_ref(), TypeContext::default()); } } } @@ -1602,19 +1608,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { // Inference of bounds, constraints, and defaults must be deferred, to avoid cycles. So we // only check presence/absence/number here. - let constraints = arguments.args.get(1..).unwrap_or_default(); - - let bound_or_constraints = match (has_bound, constraints) { - (false, []) => None, - (true, []) => Some(TypeVarBoundOrConstraintsEvaluation::LazyUpperBound), - (true, _) => { + let mut args = arguments.args(); + let first_constraint = args.nth(1); + let bound_or_constraints = match (has_bound, first_constraint) { + (false, None) => None, + (true, None) => Some(TypeVarBoundOrConstraintsEvaluation::LazyUpperBound), + (true, Some(_)) => { return error( &self.context, "A `TypeVar` cannot have both a bound and constraints", call_expr, ); } - (false, [constraint]) => { + (false, Some(constraint)) if args.next().is_none() => { if let Some(builder) = self .context .report_lint(&INVALID_TYPE_VARIABLE_CONSTRAINTS, constraint) diff --git a/crates/ty_python_semantic/src/types/infer/expression_truthiness.rs b/crates/ty_python_semantic/src/types/infer/expression_truthiness.rs index bb40451281..649871a9da 100644 --- a/crates/ty_python_semantic/src/types/infer/expression_truthiness.rs +++ b/crates/ty_python_semantic/src/types/infer/expression_truthiness.rs @@ -175,9 +175,12 @@ where self.can_complete(&call.func) && call .arguments - .args - .iter() - .chain(call.arguments.keywords.iter().map(|keyword| &keyword.value)) + .args() + .chain( + call.arguments + .keywords() + .map(|keyword| keyword.value.as_ref()), + ) .all(|argument| self.can_complete(argument)) } ast::Expr::Compare(compare) => { diff --git a/crates/ty_python_semantic/src/types/narrow.rs b/crates/ty_python_semantic/src/types/narrow.rs index 3dd831e5e7..ce5c6d1d46 100644 --- a/crates/ty_python_semantic/src/types/narrow.rs +++ b/crates/ty_python_semantic/src/types/narrow.rs @@ -4115,12 +4115,9 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { ) -> Option<&'a ast::Expr> { match expr.expression_value() { ast::Expr::Call(ast::ExprCall { - func, - arguments: ast::Arguments { args, keywords, .. }, - .. + func, arguments, .. }) => { - if keywords.is_empty() - && let [single_argument] = &**args + if let [ast::Argument::Positional(single_argument)] = arguments.items.as_slice() && let Type::ClassLiteral(called_class) = inference.expression_type(func) && called_class.is_known(db, KnownClass::Type) { @@ -4212,11 +4209,11 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { return; }; if function_type.known(db) != Some(KnownFunction::Len) - || !call.arguments.keywords.is_empty() + || call.arguments.keywords().next().is_some() { return; } - let [arg] = &*call.arguments.args else { + let Some([arg]) = call.arguments.args().collect_array() else { return; }; let Some(length) = length_type.resolve_type_alias(db).as_int_like_literal() @@ -4643,11 +4640,9 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { // `__bool__` and `__len__` are consistent (literals, tuples). Non-narrowable parts // (str, list, etc.) are kept unchanged. Type::FunctionLiteral(function_type) - if expr_call.arguments.args.len() == 1 - && expr_call.arguments.keywords.is_empty() + if let [ast::Argument::Positional(arg)] = expr_call.arguments.items.as_slice() && function_type.known(db) == Some(KnownFunction::Len) => { - let arg = &expr_call.arguments.args[0]; let arg_ty = inference.expression_type(arg); // Narrow only the parts of the type that are safe to narrow based on len(). @@ -4664,11 +4659,17 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { None } } - Type::FunctionLiteral(function_type) if expr_call.arguments.keywords.is_empty() => { - let [first_arg, second_arg] = &*expr_call.arguments.args else { + Type::FunctionLiteral(function_type) + if expr_call.arguments.keywords().next().is_none() => + { + let [ + ast::Argument::Positional(first_expr), + ast::Argument::Positional(second_arg), + ] = expr_call.arguments.items.as_slice() + else { return None; }; - let first_arg = PlaceExpr::try_from_expr(first_arg)?; + let first_arg = PlaceExpr::try_from_expr(first_expr)?; let function = function_type.known(db)?; let place = self.expect_place(&first_arg); @@ -4726,8 +4727,7 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { }; let mut constraints = NarrowingConstraints::from_iter([(place, constraint)]); - let argument = &expr_call.arguments.args[0]; - if let ast::Expr::Subscript(subscript) = argument.expression_value() + if let ast::Expr::Subscript(subscript) = first_expr.expression_value() && let Some((tuple_place, tuple_constraint)) = self .narrow_tuple_subscript_by_type( inference, @@ -4748,15 +4748,10 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { } // for the expression `bool(E)`, we further narrow the type based on `E` Type::ClassLiteral(class_type) - if expr_call.arguments.args.len() == 1 - && expr_call.arguments.keywords.is_empty() + if let [ast::Argument::Positional(arg)] = expr_call.arguments.items.as_slice() && class_type.is_known(db, KnownClass::Bool) => { - self.evaluate_expression_node_predicate( - &expr_call.arguments.args[0], - expression, - is_positive, - ) + self.evaluate_expression_node_predicate(arg, expression, is_positive) } _ => None, } @@ -4808,12 +4803,11 @@ impl<'db> NarrowingConstraintsBuilder<'db, '_> { NarrowingConstraint::intersection(constraint_type) }; let mut constraints = NarrowingConstraints::from_iter([(place, constraint)]); - for argument in expr_call.arguments.args.iter().chain( + for argument in expr_call.arguments.args().chain( expr_call .arguments - .keywords - .iter() - .map(|keyword| &keyword.value), + .keywords() + .map(|keyword| keyword.value.as_ref()), ) { if let ast::Expr::Subscript(subscript) = argument.expression_value() && let Some(argument_place) = PlaceExpr::try_from_expr(argument) diff --git a/crates/ty_python_semantic/src/types/newtype.rs b/crates/ty_python_semantic/src/types/newtype.rs index ab00e1d3f6..90e9e32bbf 100644 --- a/crates/ty_python_semantic/src/types/newtype.rs +++ b/crates/ty_python_semantic/src/types/newtype.rs @@ -77,7 +77,7 @@ impl<'db> NewType<'db> { let Some(call_expr) = assignment.value(&module).as_call_expr() else { return object_fallback; }; - let Some(second_arg) = call_expr.arguments.args.get(1) else { + let Some(second_arg) = call_expr.arguments.args().nth(1) else { return object_fallback; }; match definition_expression_type(db, definition, second_arg) { diff --git a/crates/ty_python_semantic/src/types/type_alias.rs b/crates/ty_python_semantic/src/types/type_alias.rs index 47fc00e934..c8731a762e 100644 --- a/crates/ty_python_semantic/src/types/type_alias.rs +++ b/crates/ty_python_semantic/src/types/type_alias.rs @@ -297,10 +297,10 @@ impl<'db> PEP695TypeAliasType<'db> { /// twice, use the positional argument for error recovery. pub(super) fn type_alias_arguments(arguments: &ast::Arguments) -> Option<(&ast::Expr, &ast::Expr)> { let name = factory_name_argument(arguments)?; - let value = arguments.args.get(1).or_else(|| { + let value = arguments.args().nth(1).or_else(|| { arguments .find_keyword("value") - .map(|keyword| &keyword.value) + .map(|keyword| keyword.value.as_ref()) })?; Some((name, value)) } diff --git a/crates/ty_python_semantic/src/types/typed_dict.rs b/crates/ty_python_semantic/src/types/typed_dict.rs index e99fa8ce8f..c077d410df 100644 --- a/crates/ty_python_semantic/src/types/typed_dict.rs +++ b/crates/ty_python_semantic/src/types/typed_dict.rs @@ -1467,7 +1467,7 @@ pub(super) fn deferred_functional_typed_dict_schema<'db>( let mut schema = TypedDictSchema::default(); - if let Some(fields_arg) = node.arguments.args.get(1) { + if let Some(fields_arg) = node.arguments.args().nth(1) { let ast::Expr::Dict(dict_expr) = fields_arg else { return schema; }; @@ -1551,10 +1551,10 @@ pub(super) fn typed_dict_params_from_class_def(class_stmt: &StmtClassDef) -> Typ // Note that it is fine to only check for Boolean literals here // (https://typing.python.org/en/latest/spec/typeddict.html#totality) if let Some(arguments) = &class_stmt.arguments { - for keyword in &arguments.keywords { + for keyword in arguments.keywords() { if keyword.arg.as_deref() == Some("total") && matches!( - &keyword.value, + keyword.value.as_ref(), ast::Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: false, .. }) ) { @@ -2143,13 +2143,12 @@ pub(super) fn infer_unpacked_keyword_types<'db>( mut expression_type_fn: impl FnMut(&ast::Expr, TypeContext<'db>) -> Type<'db>, ) -> Vec>> { arguments - .keywords - .iter() + .keywords() .map(|keyword| { keyword .arg .is_none() - .then(|| expression_type_fn(&keyword.value, TypeContext::default())) + .then(|| expression_type_fn(keyword.value.as_ref(), TypeContext::default())) }) .collect() } @@ -2178,17 +2177,15 @@ pub(super) fn collect_guaranteed_keyword_keys<'db>( unpacked_keyword_types: &[Option>], expression_type_fn: &mut impl FnMut(&ast::Expr, TypeContext<'db>) -> Type<'db>, ) -> OrderSet { - debug_assert_eq!(arguments.keywords.len(), unpacked_keyword_types.len()); + debug_assert_eq!(arguments.keywords().count(), unpacked_keyword_types.len()); let mut provided_keys: OrderSet = arguments - .keywords - .iter() + .keywords() .filter_map(|keyword| keyword.arg.as_ref().map(|arg| arg.id.clone())) .collect(); for (keyword, unpacked_type) in arguments - .keywords - .iter() + .keywords() .zip(unpacked_keyword_types.iter().copied()) { if keyword.arg.is_some() { @@ -2207,7 +2204,7 @@ pub(super) fn collect_guaranteed_keyword_keys<'db>( db, env, typed_dict, - &keyword.value, + keyword.value.as_ref(), unpacked_type, &mut provided_keys, expression_type_fn, @@ -2587,14 +2584,14 @@ pub(super) fn validate_typed_dict_constructor<'db, 'ast>( let typed_dict_ty = Type::TypedDict(typed_dict); let env = context.program_environment(); - if arguments.args.len() > 1 { - if let Some(builder) = - context.report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, &arguments.args[1]) - { + let mut positional = arguments.args(); + let positional_arg = positional.next(); + if let Some(extra) = positional.next() { + if let Some(builder) = context.report_lint(&TOO_MANY_POSITIONAL_ARGUMENTS, extra) { builder.into_diagnostic(format_args!( "Too many positional arguments to TypedDict `{}` constructor: expected 1, got {}", typed_dict_ty.display(db, env), - arguments.args.len(), + arguments.args().count(), )); } // TODO: Consider validating the first positional argument too, without producing @@ -2603,12 +2600,13 @@ pub(super) fn validate_typed_dict_constructor<'db, 'ast>( } // Check for a single positional argument, and whether it's a dict literal. - let has_single_positional_arg = arguments.args.len() == 1; - let positional_dict_literal = arguments.args.first().and_then(ast::Expr::as_dict_expr); + let positional_dict_literal = positional_arg.and_then(ast::Expr::as_dict_expr); let unpacked_keyword_types = infer_unpacked_keyword_types(arguments, &mut expression_type_fn); - if has_single_positional_arg && !arguments.keywords.is_empty() { + if let Some(arg) = positional_arg + && arguments.keywords().next().is_some() + { // Mixed positional-and-keyword construction: guaranteed keyword-provided keys override the // positional mapping, so validate the positional argument against the remaining schema. let keyword_keys = validate_from_keywords( @@ -2629,7 +2627,6 @@ pub(super) fn validate_typed_dict_constructor<'db, 'ast>( &keyword_keys, ) } else { - let arg = &arguments.args[0]; let positional_inference_target = typed_dict_with_relaxed_keys(db, typed_dict, &keyword_keys); let positional_target = typed_dict_without_keys(db, typed_dict, &keyword_keys); @@ -2686,12 +2683,11 @@ pub(super) fn validate_typed_dict_constructor<'db, 'ast>( &OrderSet::new(), ); validate_typed_dict_required_keys(context, typed_dict, &provided_keys, error_node); - } else if has_single_positional_arg { + } else if let Some(arg) = positional_arg { // Single positional argument: check if assignable to the target TypedDict. // This handles TypedDict, intersections, unions, and type aliases correctly. // Assignability already checks for required keys and type compatibility, // so we don't need separate validation. - let arg = &arguments.args[0]; let arg_ty = expression_type_fn(arg, TypeContext::preference(Some(typed_dict_ty))); if !arg_ty.is_assignable_to(db, env, typed_dict_ty) { @@ -2761,14 +2757,13 @@ fn validate_from_keywords<'db, 'ast>( expression_type_fn: &mut impl FnMut(&ast::Expr, TypeContext<'db>) -> Type<'db>, ) -> OrderSet { let db = context.db(); - debug_assert_eq!(arguments.keywords.len(), unpacked_keyword_types.len()); + debug_assert_eq!(arguments.keywords().count(), unpacked_keyword_types.len()); let mut guaranteed_keys = BTreeMap::new(); // Validate that each key is assigned a type that is compatible with the key's value type for (keyword, unpacked_type) in arguments - .keywords - .iter() + .keywords() .zip(unpacked_keyword_types.iter().copied()) { let keyword_node: AnyNodeRef<'ast> = keyword.into(); @@ -2786,7 +2781,7 @@ fn validate_from_keywords<'db, 'ast>( let value_tcx = typed_dict .item(db, arg_name.id.as_str()) .map_or_default(|field| TypeContext::preference(Some(field.declared_ty))); - let value_ty = expression_type_fn(&keyword.value, value_tcx); + let value_ty = expression_type_fn(keyword.value.as_ref(), value_tcx); TypedDictKeyAssignment { context, typed_dict, @@ -2795,7 +2790,7 @@ fn validate_from_keywords<'db, 'ast>( value_ty, typed_dict_node, key_node: keyword_node, - value_node: (&keyword.value).into(), + value_node: keyword.value.as_ref().into(), assignment_kind: TypedDictAssignmentKind::Constructor, emit_diagnostic: true, } @@ -2815,12 +2810,12 @@ fn validate_from_keywords<'db, 'ast>( validate_merged_unpacked_keyword_argument( context, typed_dict, - &keyword.value, + keyword.value.as_ref(), unpacked_type, TypedDictAssignmentNodes { typed_dict: typed_dict_node, key: keyword_node, - value: (&keyword.value).into(), + value: keyword.value.as_ref().into(), }, &mut unpacked_guaranteed_keys, &mut shadowed_keys, diff --git a/crates/ty_python_semantic/src/types/typevar.rs b/crates/ty_python_semantic/src/types/typevar.rs index 801b7e0413..4fbe0d6c9f 100644 --- a/crates/ty_python_semantic/src/types/typevar.rs +++ b/crates/ty_python_semantic/src/types/typevar.rs @@ -724,8 +724,7 @@ impl<'db> TypeVarInstance<'db> { db, call_expr .arguments - .args - .iter() + .args() .skip(1) .map(|arg| definition_expression_type(db, definition, arg)) .collect::>(),