matchify 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {matchify-0.2.0 → matchify-0.3.0}/.copier-answers.yml +2 -3
- matchify-0.3.0/.gitattributes +1 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/workflows/ci.yml +18 -8
- matchify-0.3.0/.github/workflows/deploy_development_docs.yml +30 -0
- matchify-0.3.0/.github/workflows/docs.yml +32 -0
- matchify-0.3.0/.github/workflows/test_docs.yml +16 -0
- {matchify-0.2.0 → matchify-0.3.0}/.pre-commit-config.yaml +18 -14
- {matchify-0.2.0 → matchify-0.3.0}/.pre-commit-hooks.yaml +1 -1
- {matchify-0.2.0 → matchify-0.3.0}/AGENTS.md +16 -5
- {matchify-0.2.0 → matchify-0.3.0}/CHANGELOG.md +27 -0
- {matchify-0.2.0 → matchify-0.3.0}/PKG-INFO +63 -166
- {matchify-0.2.0 → matchify-0.3.0}/README.md +59 -162
- matchify-0.3.0/code_sample_format.py +118 -0
- matchify-0.3.0/code_sample_runtime.py +27 -0
- matchify-0.3.0/code_sample_writer.py +39 -0
- {matchify-0.2.0 → matchify-0.3.0}/design.md +1 -1
- matchify-0.3.0/docs/assumptions.md +181 -0
- matchify-0.3.0/docs/contributing.md +1 -0
- matchify-0.3.0/docs/index.md +34 -0
- matchify-0.3.0/docs/selective-conversion.md +560 -0
- matchify-0.2.0/find_new_issue_2.py → matchify-0.3.0/find_pattern_coverage_issue.py +50 -119
- matchify-0.2.0/find_new_issue.py → matchify-0.3.0/find_random_trace_issue.py +39 -106
- matchify-0.3.0/mkdocs.yml +18 -0
- {matchify-0.2.0 → matchify-0.3.0}/pyproject.toml +23 -11
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/access_path.py +3 -3
- matchify-0.3.0/src/matchify/assumptions.py +77 -0
- matchify-0.3.0/src/matchify/cli.py +623 -0
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/compiler.py +42 -24
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/conditions.py +43 -20
- matchify-0.3.0/src/matchify/conversion_filter.py +328 -0
- matchify-0.3.0/src/matchify/diff.py +200 -0
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/facts.py +18 -7
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/lookup_tables.py +36 -10
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/pattern_builder.py +60 -13
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/patterns.py +7 -3
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/safety.py +3 -1
- matchify-0.3.0/src/matchify/transform.py +313 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_can_select_using_all_source_and_result_metrics_rejected.py +29 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_can_select_using_all_source_and_result_metrics_selected.py +30 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_maximum_generated_pattern_depth_rejected.py +33 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_maximum_generated_pattern_depth_selected.py +34 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_names_once_across_or_pattern_alternatives.py +22 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_class_rejected.py +53 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_class_selected.py +54 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_guard_rejected.py +51 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_guard_selected.py +52 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_inside_composite_patterns.py +52 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_literal_rejected.py +35 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_literal_selected.py +36 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_membership_rejected.py +53 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_membership_selected.py +54 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_self_attribute_rejected.py +45 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_self_attribute_selected.py +46 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_singleton_rejected.py +35 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_qualified_value_patterns_singleton_selected.py +36 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_counts_sequence_checks_guards_and_captures.py +24 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_class_rejected.py +47 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_class_selected.py +48 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_guard_rejected.py +51 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_guard_selected.py +52 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_membership_rejected.py +49 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_membership_selected.py +50 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_nested_other_self_rejected.py +47 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_nested_other_self_selected.py +48 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_nested_self_attribute_rejected.py +45 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_nested_self_attribute_selected.py +46 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_other_attribute_rejected.py +47 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_other_attribute_selected.py +48 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_self_attribute_rejected.py +45 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_self_attribute_selected.py +46 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_similar_name_rejected.py +45 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_distinguishes_self_value_patterns_similar_name_selected.py +46 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_does_not_apply_to_lookup_conversions.py +21 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_and_short_circuit.py +18 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_and_value.py +19 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_comparison_short_circuit.py +18 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_or_branches.py +19 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_or_fallback.py +19 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_or_rejected.py +18 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_preserves_python_boolean_semantics_or_short_circuit.py +19 -0
- matchify-0.3.0/tests/code_samples/conversion_filter_runs_after_assumption_resolution.py +24 -0
- matchify-0.3.0/tests/code_samples/edge_cases_chained_comparison_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/edge_cases_comment_preservation_before_elif_and_else.py +43 -0
- matchify-0.3.0/tests/code_samples/edge_cases_comment_preservation_before_if.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_different_dynamic_subscript_subjects_are_not_converted.py +27 -0
- matchify-0.3.0/tests/code_samples/edge_cases_dynamic_and_slice_subscript_subjects_are_not_conflated.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_boolean_attribute.py +25 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_global_variable.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_ignored_type_check_on_other_subject.py +31 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_independent_condition.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_isinstance_check.py +27 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_multiple_classes.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_multiple_conditions.py +31 -0
- matchify-0.3.0/tests/code_samples/edge_cases_guard_pattern_with_nested_boolean_attribute.py +31 -0
- matchify-0.3.0/tests/code_samples/edge_cases_inconsistent_tuple_subject_order_is_not_converted.py +28 -0
- matchify-0.3.0/tests/code_samples/edge_cases_is_not_operator_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/edge_cases_is_operator_with_non_singleton_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_proper_type_with_second_isinstance_becomes_guard.py +53 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_tuple_with_attribute_checks.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_tuple_with_attributes_converted.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_attribute_guard_converted.py +57 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_boolean_attribute_guard_real_world.py +65 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_deeply_nested_isinstance_on_attributes.py +41 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_empty_tuple_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_ignored_class_alias_in_tuple_enabled.py +49 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_len_check_on_attribute_not_converted.py +46 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_class_sequence_attribute.py +54 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_isinstance_and_attr_checks.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_isinstance_and_multiple_attr_checks.py +56 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_isinstance_on_attributes.py +33 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_isinstance_tuple.py +53 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_nested_or_attribute_check.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_non_literal_attribute_becomes_guard.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_qualified_ignored_type_ignored.py +36 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_starred_element_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_type_variable_ignored_enabled.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_type_variable_ignored_ignored.py +35 -0
- matchify-0.3.0/tests/code_samples/edge_cases_isinstance_with_type_variable_in_tuple_ignored_ignored.py +49 -0
- matchify-0.3.0/tests/code_samples/edge_cases_len_attribute_with_unsupported_operator_stays_guard.py +27 -0
- matchify-0.3.0/tests/code_samples/edge_cases_len_attribute_with_variable_length_stays_guard.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_malformed_isinstance_on_other_value_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_mixed_sequence_patterns_in_chain.py +23 -0
- matchify-0.3.0/tests/code_samples/edge_cases_multiple_subjects_preserve_short_circuiting_in_guards.py +28 -0
- matchify-0.3.0/tests/code_samples/edge_cases_nested_isinstance_tuple_with_sequence_attribute_checks.py +43 -0
- matchify-0.3.0/tests/code_samples/edge_cases_nested_isinstance_with_walrus_converted_to_pattern_and_guard.py +71 -0
- matchify-0.3.0/tests/code_samples/edge_cases_non_equality_condition_after_pattern_becomes_guard.py +25 -0
- matchify-0.3.0/tests/code_samples/edge_cases_or_pattern_with_guard_condition.py +21 -0
- matchify-0.3.0/tests/code_samples/edge_cases_parenthesized_or_condition_after_pattern_becomes_guard.py +31 -0
- matchify-0.3.0/tests/code_samples/edge_cases_path_bearing_guard_can_anchor_sequence_subject.py +27 -0
- matchify-0.3.0/tests/code_samples/edge_cases_problematic_empty_isinstance_tuple_inside_and_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/edge_cases_problematic_ignored_isinstance_tuple_element_inside_and_not_converted.py +21 -0
- matchify-0.3.0/tests/code_samples/edge_cases_problematic_isinstance_inside_and_not_converted.py +21 -0
- matchify-0.3.0/tests/code_samples/edge_cases_problematic_starred_isinstance_tuple_inside_and_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_redundant_hasattr_removed_when_attribute_is_pattern_checked.py +27 -0
- matchify-0.3.0/tests/code_samples/edge_cases_sequence_with_non_integer_subscript_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/edge_cases_starred_isinstance_on_other_value_stays_guard.py +23 -0
- matchify-0.3.0/tests/code_samples/edge_cases_starred_isinstance_on_subject_attribute_stays_guard.py +29 -0
- matchify-0.3.0/tests/code_samples/edge_cases_typed_predicate_outside_subject_remains_guard.py +39 -0
- matchify-0.3.0/tests/code_samples/edge_cases_value_pattern_with_guard_condition.py +21 -0
- matchify-0.3.0/tests/code_samples/edge_cases_walrus_operator_in_isinstance_converted_to_guard.py +37 -0
- matchify-0.3.0/tests/code_samples/edge_cases_walrus_operator_in_isinstance_subject_not_converted.py +22 -0
- matchify-0.3.0/tests/code_samples/example.py +37 -0
- matchify-0.3.0/tests/code_samples/guard_multiline_match_case_guard_is_parenthesized.py +31 -0
- matchify-0.3.0/tests/code_samples/lookup_chained_subscription.py +16 -0
- matchify-0.3.0/tests/code_samples/lookup_function_local_lookup_assignment_is_removed.py +21 -0
- matchify-0.3.0/tests/code_samples/lookup_inline_lookup_in_arbitrary_statement.py +23 -0
- matchify-0.3.0/tests/code_samples/lookup_invalid_slice.py +22 -0
- matchify-0.3.0/tests/code_samples/lookup_lookup_comments_remain_before_the_generated_match.py +20 -0
- matchify-0.3.0/tests/code_samples/lookup_lookup_values_can_be_arbitrary_expressions.py +40 -0
- matchify-0.3.0/tests/code_samples/lookup_module_source_unchanged.py +16 -0
- matchify-0.3.0/tests/code_samples/lookup_one_line_functions_are_ignored.py +12 -0
- matchify-0.3.0/tests/code_samples/lookup_only_the_chained_lookup_is_excluded.py +26 -0
- matchify-0.3.0/tests/code_samples/lookup_reused_source_unchanged.py +20 -0
- matchify-0.3.0/tests/code_samples/lookup_source.py +18 -0
- matchify-0.3.0/tests/code_samples/lookup_subject_is_evaluated_once_and_missing_key_is_preserved.py +36 -0
- matchify-0.3.0/tests/code_samples/lookup_table.py +20 -0
- matchify-0.3.0/tests/code_samples/lookup_tuple_and_nested_tuple_keys_become_sequence_patterns.py +29 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_01.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_02.py +26 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_03.py +26 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_04.py +26 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_05.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_06.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_07.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_08.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_09.py +26 -0
- matchify-0.3.0/tests/code_samples/lookup_unsafe_10.py +28 -0
- matchify-0.3.0/tests/code_samples/lookup_use_before_assignment.py +22 -0
- matchify-0.3.0/tests/code_samples/planning_missing_parent_assumptions_do_not_block_children_enabled_after_safe.py +51 -0
- matchify-0.3.0/tests/code_samples/planning_missing_parent_assumptions_do_not_block_children_risky.py +50 -0
- matchify-0.3.0/tests/code_samples/planning_missing_parent_assumptions_do_not_block_children_safe.py +49 -0
- matchify-0.3.0/tests/code_samples/public_accepts_deeply_qualified_class_patterns.py +39 -0
- matchify-0.3.0/tests/code_samples/public_capture_stays_in_body_for_an_incompatible_attribute_parent.py +29 -0
- matchify-0.3.0/tests/code_samples/public_capture_stays_in_body_when_class_attribute_is_not_patterned.py +31 -0
- matchify-0.3.0/tests/code_samples/public_capture_stays_in_body_when_only_one_or_alternative_can_bind.py +25 -0
- matchify-0.3.0/tests/code_samples/public_conflicting_value_facts_fall_back_to_a_guard.py +24 -0
- matchify-0.3.0/tests/code_samples/public_deep_capture_stays_in_body_when_intermediate_element_is_missing.py +25 -0
- matchify-0.3.0/tests/code_samples/public_duplicate_capture_with_multiple_remaining_statements.py +24 -0
- matchify-0.3.0/tests/code_samples/public_incompatible_class_and_subscript_facts_are_rejected.py +26 -0
- matchify-0.3.0/tests/code_samples/public_list_and_tuple_type_guards_are_kept_for_sequence_patterns.py +23 -0
- matchify-0.3.0/tests/code_samples/public_nested_capture_stays_in_body_when_the_child_is_not_a_sequence.py +33 -0
- matchify-0.3.0/tests/code_samples/public_nested_or_fact_with_a_shared_guard_is_rendered.py +25 -0
- matchify-0.3.0/tests/code_samples/public_nested_subscription_without_sequence_anchor_stays_in_guard.py +35 -0
- matchify-0.3.0/tests/code_samples/public_or_alternatives_with_different_guards_fall_back_to_a_guard.py +27 -0
- matchify-0.3.0/tests/code_samples/public_qualified_sequence_type_checks_remain_guards.py +31 -0
- matchify-0.3.0/tests/code_samples/public_rejects_dynamic_and_non_string_hasattr_names.py +22 -0
- matchify-0.3.0/tests/code_samples/public_rejects_non_literal_and_starred_membership_containers.py +35 -0
- matchify-0.3.0/tests/code_samples/public_rejects_unsafe_equality_on_a_selected_subject.py +22 -0
- matchify-0.3.0/tests/code_samples/public_rejects_unsafe_identity_on_a_selected_subject.py +22 -0
- matchify-0.3.0/tests/code_samples/public_sequence_type_guard_preserves_runtime_for_other_sequence_types.py +23 -0
- matchify-0.3.0/tests/code_samples/public_sequence_type_guards_can_be_assumed_for_or_patterns.py +23 -0
- matchify-0.3.0/tests/code_samples/public_single_literal_membership_becomes_a_value_pattern.py +21 -0
- matchify-0.3.0/tests/code_samples/public_subscript_or_expression_does_not_hide_a_later_value_subject.py +25 -0
- matchify-0.3.0/tests/code_samples/sequence_list_assumption_does_not_apply_to_tuple_checks_list_assumed.py +22 -0
- matchify-0.3.0/tests/code_samples/sequence_list_check_requires_list_sequence_pattern_assumption_assumed.py +23 -0
- matchify-0.3.0/tests/code_samples/sequence_list_check_requires_list_sequence_pattern_assumption_safe.py +22 -0
- matchify-0.3.0/tests/code_samples/sequence_sequence_assumptions_do_not_apply_to_qualified_class_checks_both_assumed.py +31 -0
- matchify-0.3.0/tests/code_samples/sequence_tuple_check_requires_tuple_sequence_pattern_assumption_assumed.py +23 -0
- matchify-0.3.0/tests/code_samples/sequence_tuple_check_requires_tuple_sequence_pattern_assumption_safe.py +22 -0
- matchify-0.3.0/tests/code_samples/transform_all_negated_isinstance_chain_is_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_and_subjects_use_a_composite_match_subject_pure_subjects.py +32 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_and_subjects_use_a_composite_match_subject_safe.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_and_subjects_use_a_composite_match_subject_use_object.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_attribute_subject_uses_object_patterns_pure_subjects.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_attribute_subject_uses_object_patterns_safe.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_attribute_subject_uses_object_patterns_use_object.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_attributes_with_one_root_share_one_object_pattern.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_nested_attributes_get_recursive_object_patterns.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_assumed_pure_subject_used_by_a_majority_joins_match_subject_pure_subjects.py +40 -0
- matchify-0.3.0/tests/code_samples/transform_attribute_access_variable.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_bare_constants_are_not_value_patterns.py +22 -0
- matchify-0.3.0/tests/code_samples/transform_capture_does_not_replace_an_existing_value_pattern.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_capture_only_body_becomes_pass.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_class_union.py +36 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_direct_sequence_subject.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_direct_sequence_subject_or_pattern.py +21 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_direct_star_sequence_subject.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_from_assignment.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_multi_attribute.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_multi_attribute_multiple_captures.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_multiple_values.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_nested_attribute.py +36 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_nested_class_union_sequence_attribute.py +44 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_non_consecutive_indices.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_non_consecutive_multi_gap.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_not_starting_from_zero.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_sequence_attribute_or_pattern.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_sequence_element_class_attribute.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_sequence_element_class_union_nested_attribute.py +36 -0
- matchify-0.3.0/tests/code_samples/transform_capture_pattern_three_values.py +30 -0
- matchify-0.3.0/tests/code_samples/transform_common_subject_is_built_from_branch_path_prefixes.py +41 -0
- matchify-0.3.0/tests/code_samples/transform_comparison_with_variable_not_converted.py +26 -0
- matchify-0.3.0/tests/code_samples/transform_complex_real_world_example.py +45 -0
- matchify-0.3.0/tests/code_samples/transform_convertible_chain_after_non_convertible_chain.py +83 -0
- matchify-0.3.0/tests/code_samples/transform_different_subjects_not_converted.py +26 -0
- matchify-0.3.0/tests/code_samples/transform_different_variables_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_duplicate_capture_index_uses_alias_assignment.py +30 -0
- matchify-0.3.0/tests/code_samples/transform_duplicate_capture_only_body_keeps_alias_without_pass.py +30 -0
- matchify-0.3.0/tests/code_samples/transform_f_string_attribute_check_becomes_guard.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_f_string_sequence_element_check_becomes_guard.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_f_string_value_pattern_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_function_call_converted.py +21 -0
- matchify-0.3.0/tests/code_samples/transform_guard_branch_with_else_is_not_converted.py +22 -0
- matchify-0.3.0/tests/code_samples/transform_if_elif_without_else.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_invalid_capture_assignments_stay_in_body.py +88 -0
- matchify-0.3.0/tests/code_samples/transform_is_none_converted.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_converted.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_none_type_becomes_singleton_pattern.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_subscript_subject.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_tuple_converted.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_tuple_with_none_type_becomes_or_pattern.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_and_converted.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_is_none_attribute.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_is_true_false.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_multiple_and_converted.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_nested_sequence_attributes.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_nested_sequence_in_sequence_attribute.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_or_attribute.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_sequence_and_nested_class_attributes.py +39 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_sequence_and_scalar_attributes.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_sequence_attribute_converted.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_isinstance_with_sequence_attribute_mixed_types.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_leading_guard_branch_is_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_list_tuple_sequence_checks_require_both_assumptions_list_sequence_pattern.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_list_tuple_sequence_checks_require_both_assumptions_list_sequence_pattern_tuple_sequence_pattern.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_list_tuple_sequence_checks_require_both_assumptions_safe.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_list_tuple_sequence_checks_require_both_assumptions_tuple_sequence_pattern.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_literal_membership_becomes_or_pattern.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_literal_set_membership_requires_hashable_subjects_assumption_hashable_subjects.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_literal_set_membership_requires_hashable_subjects_assumption_safe.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_many_branches_no_limit.py +59 -0
- matchify-0.3.0/tests/code_samples/transform_many_sibling_attributes_no_limit.py +43 -0
- matchify-0.3.0/tests/code_samples/transform_mixed_is_none_and_isinstance.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_mixed_operators_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_mixed_pattern_types_in_chain.py +41 -0
- matchify-0.3.0/tests/code_samples/transform_multiple_independent_if_chains.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_multiple_sibling_attributes_with_literals.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_multiple_statements_in_body.py +32 -0
- matchify-0.3.0/tests/code_samples/transform_negated_isinstance_chain_is_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_negative_numbers_in_attributes.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_negative_numbers_in_comparisons.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_nested_attribute_non_literal_check_preserved_as_guard.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_nested_if_not_affected.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_nested_literal_membership_becomes_or_pattern.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_nested_sequence_attribute_relational_check_preserved_as_guard.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_non_equality_comparisons_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_non_integer_sequence_subscripts_fall_back_to_guards.py +37 -0
- matchify-0.3.0/tests/code_samples/transform_numeric_comparisons.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_or_class_pattern_with_common_attribute_check.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_different_subjects_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_in_mixed_chain.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_mixed_types.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_simple.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_three_values.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_class_attribute_alternative.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_common_call_guard_stays_guard.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_common_simple_guard_is_lifted.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_deep_nested_class_redundant_hasattr.py +43 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_guarded_alternative_stays_guard.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_is_none.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_isinstance_classes.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_mixed_value_and_class_attribute_alternative.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_mixed_value_and_isinstance.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_negative_numbers.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_nested_class_redundant_hasattr.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_redundant_hasattr_class_attribute_alternative.py +33 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_safe_sequence_alternative_list_sequence_pattern_tuple_sequence_pattern.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_safe_sequence_alternative_safe.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_safe_sequence_attribute_alternative_list_sequence_pattern_tuple_sequence_pattern.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_safe_sequence_attribute_alternative_safe.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_sequence_alternative.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_sequence_attribute_alternative.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_sequence_element_redundant_hasattr.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_strings.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_or_pattern_with_variable_not_converted.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_other_isinstance_classinfo_call_becomes_guard.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_parenthesized_isinstance_class_converted.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_plain_list_tuple_isinstance_becomes_class_pattern.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_qualified_constants_become_value_patterns.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_qualified_identity_requires_identity_equality_assumption_identity_equality.py +32 -0
- matchify-0.3.0/tests/code_samples/transform_qualified_identity_requires_identity_equality_assumption_safe.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_attribute_element_non_literal_check_preserved_as_guard.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_attribute_type_guard_preserves_len_check.py +28 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_element_beyond_checked_length_falls_back_to_guard.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_element_class_union_nested_attribute_redundant_hasattr.py +45 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_nested_element_non_literal_check_preserved_as_guard.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_many_elements_no_limit.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_missing_index_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_simple.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_star_with_isinstance.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_star_with_wildcard_gap.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_three_elements.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_class_attribute_or_element.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_class_element_attributes.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_class_or_element.py +31 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_guard_condition.py +21 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_isinstance_and_is_none.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_isinstance_element.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_isinstance_tuple.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_isinstance_tuple_and_attribute.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_mixed_isinstance_and_literals.py +27 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_mixed_or_element.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_nested_class_attribute_or_element.py +41 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_nested_class_element_attributes.py +35 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_or_element.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_safe_nested_class_attribute_or_element.py +41 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_star.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_strings.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_subject_guard_condition.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_with_variable_element_guard.py +20 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_pattern_without_len_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_deeply_nested_sequence.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_multiple_nested_sequences.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_nested_class_in_element.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_nested_sequence_and_isinstance.py +25 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_nested_sequence_simple.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_nested_sequence_strings.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_sequence_with_nested_star_sequence.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_simple_if_elif_else_chain.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_simple_if_only_not_converted.py +14 -0
- matchify-0.3.0/tests/code_samples/transform_singleton_membership_is_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_tuple_comparisons_are_not_converted.py +30 -0
- matchify-0.3.0/tests/code_samples/transform_unary_plus_numbers_are_normalized_in_patterns.py +29 -0
- matchify-0.3.0/tests/code_samples/transform_unsafe_set_membership_is_not_converted_hashable_subjects.py +68 -0
- matchify-0.3.0/tests/code_samples/transform_walrus_guard_is_preserved.py +37 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_at_end.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_at_start.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_multiple_groups.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_not_used_for_mixed.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_simple.py +23 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_three_consecutive_not_converted.py +18 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_two_consecutive.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_with_is_none.py +19 -0
- matchify-0.3.0/tests/code_samples/transform_wildcard_pattern_with_isinstance.py +23 -0
- matchify-0.3.0/tests/test_assumptions.py +50 -0
- matchify-0.3.0/tests/test_cli.py +1956 -0
- matchify-0.3.0/tests/test_code_samples.py +195 -0
- matchify-0.3.0/tests/test_conversion_filter.py +172 -0
- matchify-0.3.0/tests/test_documentation.py +129 -0
- matchify-0.2.0/tests/test_find_new_issue_2.py → matchify-0.3.0/tests/test_find_pattern_coverage_issue.py +1 -1
- matchify-0.3.0/tests/test_internal_coverage.py +107 -0
- matchify-0.3.0/tests/test_issue_code_samples.py +173 -0
- matchify-0.3.0/tests/test_lookup_tables.py +20 -0
- matchify-0.3.0/tests/test_planning.py +263 -0
- {matchify-0.2.0 → matchify-0.3.0}/uv.lock +21 -96
- matchify-0.2.0/src/matchify/assumptions.py +0 -93
- matchify-0.2.0/src/matchify/cli.py +0 -209
- matchify-0.2.0/src/matchify/transform.py +0 -175
- matchify-0.2.0/tests/helpers.py +0 -64
- matchify-0.2.0/tests/samples/.gitkeep +0 -0
- matchify-0.2.0/tests/test_cli.py +0 -867
- matchify-0.2.0/tests/test_edge_cases.py +0 -1913
- matchify-0.2.0/tests/test_generated_roundtrip.py +0 -114
- matchify-0.2.0/tests/test_guard_rendering.py +0 -33
- matchify-0.2.0/tests/test_lookup_tables.py +0 -284
- matchify-0.2.0/tests/test_public_coverage.py +0 -359
- matchify-0.2.0/tests/test_readme.py +0 -81
- matchify-0.2.0/tests/test_sequence_assumptions.py +0 -101
- matchify-0.2.0/tests/test_transform.py +0 -5388
- {matchify-0.2.0 → matchify-0.3.0}/.copier-enforce.json +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/FUNDING.yml +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/actions/setup/action.yml +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/pull_request_template.md +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/workflows/release-pr.yml +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.github/workflows/weekly.yml +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/.gitignore +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/CONTRIBUTING.md +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/COPIER_TEMPLATE_CHANGES.md +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/LICENSE +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/changelog.d/.gitignore +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/limitations.md +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/__init__.py +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/__main__.py +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/src/matchify/capture_patterns.py +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/test-repos.json +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/test-repos.py +0 -0
- {matchify-0.2.0 → matchify-0.3.0}/tests/test_access_path.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Changes here will be overwritten by Copier
|
|
2
|
-
_commit: v0.
|
|
2
|
+
_commit: v0.4.1
|
|
3
3
|
_src_path: https://github.com/15r10nk/project-template.git
|
|
4
4
|
author_email: 15r10nk@polarbit.de
|
|
5
5
|
author_name: Frank Hoffmann
|
|
@@ -15,10 +15,9 @@ project_name: matchify
|
|
|
15
15
|
pypy_versions:
|
|
16
16
|
- pypy3.11
|
|
17
17
|
python_versions:
|
|
18
|
-
- '3.10'
|
|
19
18
|
- '3.11'
|
|
20
19
|
- '3.12'
|
|
21
20
|
- '3.13'
|
|
22
21
|
- '3.14'
|
|
23
22
|
show_project_logo: false
|
|
24
|
-
use_mkdocs:
|
|
23
|
+
use_mkdocs: true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tests/code_samples/*.py text eol=lf
|
|
@@ -45,7 +45,7 @@ jobs:
|
|
|
45
45
|
|
|
46
46
|
strategy:
|
|
47
47
|
matrix:
|
|
48
|
-
python-version: ['3.
|
|
48
|
+
python-version: ['3.11', '3.12', '3.13', '3.14', pypy3.11]
|
|
49
49
|
|
|
50
50
|
os: [ubuntu-latest, windows-latest, macos-15]
|
|
51
51
|
lowest_resolution: [false]
|
|
@@ -59,11 +59,6 @@ jobs:
|
|
|
59
59
|
os: macos-15
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
- os: macos-15
|
|
63
|
-
python-version: '3.11'
|
|
64
|
-
- os: windows-latest
|
|
65
|
-
python-version: '3.11'
|
|
66
|
-
|
|
67
62
|
- os: macos-15
|
|
68
63
|
python-version: '3.12'
|
|
69
64
|
- os: windows-latest
|
|
@@ -81,7 +76,7 @@ jobs:
|
|
|
81
76
|
|
|
82
77
|
include:
|
|
83
78
|
- os: ubuntu-latest
|
|
84
|
-
python-version: '3.
|
|
79
|
+
python-version: '3.11'
|
|
85
80
|
lowest_resolution: true
|
|
86
81
|
- os: ubuntu-latest
|
|
87
82
|
python-version: '3.14'
|
|
@@ -126,6 +121,21 @@ jobs:
|
|
|
126
121
|
include-hidden-files: true
|
|
127
122
|
if-no-files-found: ignore
|
|
128
123
|
|
|
124
|
+
mypy:
|
|
125
|
+
name: Type check (${{matrix.python-version}})
|
|
126
|
+
runs-on: ubuntu-latest
|
|
127
|
+
strategy:
|
|
128
|
+
matrix:
|
|
129
|
+
python-version: ['3.11', '3.12', '3.13', '3.14']
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
steps:
|
|
133
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
134
|
+
- uses: ./.github/actions/setup
|
|
135
|
+
with:
|
|
136
|
+
python-version: ${{matrix.python-version}}
|
|
137
|
+
- run: uv run --locked --with mypy mypy src tests
|
|
138
|
+
|
|
129
139
|
coverage:
|
|
130
140
|
name: Combine & check coverage
|
|
131
141
|
env:
|
|
@@ -165,7 +175,7 @@ jobs:
|
|
|
165
175
|
|
|
166
176
|
publish:
|
|
167
177
|
name: Publish new release
|
|
168
|
-
needs: [detect_release, test, coverage]
|
|
178
|
+
needs: [detect_release, test, mypy, coverage]
|
|
169
179
|
if: needs.detect_release.outputs.is_release == 'true' && !contains(github.repository, '-insiders/')
|
|
170
180
|
runs-on: ubuntu-latest
|
|
171
181
|
environment: pypi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: deploy development docs
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Deploy development docs
|
|
9
|
+
if: "!contains(github.repository, '-insiders/')"
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout main
|
|
15
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
16
|
+
|
|
17
|
+
- name: Set up documentation mutex
|
|
18
|
+
uses: ben-z/gh-action-mutex@v1.0.0-alpha.10
|
|
19
|
+
with:
|
|
20
|
+
branch: docs-mutex
|
|
21
|
+
|
|
22
|
+
- run: pip install hatch
|
|
23
|
+
- name: publish docs
|
|
24
|
+
env:
|
|
25
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
26
|
+
run: |
|
|
27
|
+
git config user.name "Frank Hoffmann"
|
|
28
|
+
git config user.email "15r10nk@users.noreply.github.com"
|
|
29
|
+
git fetch origin '+refs/heads/*:refs/remotes/origin/*' --depth=1
|
|
30
|
+
hatch run docs:deploy deploy --push development
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Publish docs via GitHub Pages
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags:
|
|
5
|
+
- v[0-9]+.[0-9]+.[0-9]+
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
name: Deploy docs for new version
|
|
10
|
+
if: "!contains(github.repository, '-insiders/')"
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: write
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout main
|
|
16
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
17
|
+
|
|
18
|
+
- name: Set up documentation mutex
|
|
19
|
+
uses: ben-z/gh-action-mutex@v1.0.0-alpha.10
|
|
20
|
+
with:
|
|
21
|
+
branch: docs-mutex
|
|
22
|
+
|
|
23
|
+
- run: pip install hatch
|
|
24
|
+
- run: hatch version | sed -rne "s:([0-9]*)\.([0-9]*)\..*:PROJECT_VERSION=\1.\2:p" >> "${GITHUB_ENV}"
|
|
25
|
+
- name: publish docs
|
|
26
|
+
env:
|
|
27
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
28
|
+
run: |
|
|
29
|
+
git config user.name "Frank Hoffmann"
|
|
30
|
+
git config user.email "15r10nk@users.noreply.github.com"
|
|
31
|
+
git fetch origin '+refs/heads/*:refs/remotes/origin/*' --depth=1
|
|
32
|
+
hatch run docs:deploy deploy -u --push "${PROJECT_VERSION}" latest
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: test docs
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
name: Deploy development docs
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- name: Checkout main
|
|
11
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
12
|
+
|
|
13
|
+
- run: pip install hatch
|
|
14
|
+
- name: test docs
|
|
15
|
+
run: |
|
|
16
|
+
hatch run docs:build --strict
|
|
@@ -7,7 +7,7 @@ ci:
|
|
|
7
7
|
repos:
|
|
8
8
|
|
|
9
9
|
- repo: https://github.com/15r10nk/project-template
|
|
10
|
-
rev: v0.
|
|
10
|
+
rev: v0.4.1
|
|
11
11
|
hooks:
|
|
12
12
|
- id: copier-enforce
|
|
13
13
|
|
|
@@ -22,48 +22,52 @@ repos:
|
|
|
22
22
|
- id: check-json
|
|
23
23
|
- id: end-of-file-fixer
|
|
24
24
|
repo: https://github.com/pre-commit/pre-commit-hooks
|
|
25
|
-
rev:
|
|
25
|
+
rev: v6.0.0
|
|
26
26
|
- hooks:
|
|
27
27
|
- args:
|
|
28
28
|
- --in-place
|
|
29
29
|
- --expand-star-imports
|
|
30
30
|
- --remove-all-unused-imports
|
|
31
31
|
- --ignore-init-module-imports
|
|
32
|
+
exclude: ^tests/code_samples/
|
|
32
33
|
id: autoflake
|
|
33
34
|
repo: https://github.com/myint/autoflake
|
|
34
|
-
rev: v2.
|
|
35
|
+
rev: v2.4.0
|
|
35
36
|
|
|
36
37
|
- repo: https://github.com/asottile/setup-cfg-fmt
|
|
37
|
-
rev:
|
|
38
|
+
rev: v3.2.0
|
|
38
39
|
hooks:
|
|
39
40
|
- id: setup-cfg-fmt
|
|
40
41
|
|
|
41
42
|
- repo: https://github.com/pycqa/isort
|
|
42
|
-
rev:
|
|
43
|
+
rev: 9.0.1
|
|
43
44
|
hooks:
|
|
44
45
|
- id: isort
|
|
46
|
+
exclude: ^tests/code_samples/
|
|
45
47
|
name: isort (python)
|
|
46
48
|
|
|
47
49
|
- hooks:
|
|
48
50
|
- args:
|
|
49
51
|
- --py310-plus
|
|
52
|
+
exclude: ^tests/code_samples/
|
|
50
53
|
id: pyupgrade
|
|
51
54
|
language_version: python3.13
|
|
52
55
|
repo: https://github.com/asottile/pyupgrade
|
|
53
|
-
rev: v3.
|
|
56
|
+
rev: v3.21.2
|
|
54
57
|
- hooks:
|
|
55
58
|
- id: black
|
|
59
|
+
exclude: ^tests/code_samples/
|
|
56
60
|
repo: https://github.com/psf/black
|
|
57
|
-
rev:
|
|
61
|
+
rev: 26.5.1
|
|
58
62
|
- hooks:
|
|
59
63
|
- id: blacken-docs
|
|
60
64
|
args: [-l80]
|
|
61
65
|
repo: https://github.com/adamchainz/blacken-docs
|
|
62
|
-
rev: 1.
|
|
66
|
+
rev: 1.20.0
|
|
63
67
|
|
|
64
68
|
|
|
65
69
|
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
|
66
|
-
rev: v2.
|
|
70
|
+
rev: v2.16.0
|
|
67
71
|
hooks:
|
|
68
72
|
- id: pretty-format-yaml
|
|
69
73
|
args: [--autofix, --indent, '2']
|
|
@@ -73,26 +77,26 @@ repos:
|
|
|
73
77
|
stages:
|
|
74
78
|
- commit-msg
|
|
75
79
|
repo: https://github.com/commitizen-tools/commitizen
|
|
76
|
-
rev: v4.
|
|
80
|
+
rev: v4.19.0
|
|
77
81
|
|
|
78
82
|
- repo: https://github.com/abravalheri/validate-pyproject
|
|
79
|
-
rev:
|
|
83
|
+
rev: '0.26'
|
|
80
84
|
hooks:
|
|
81
85
|
- id: validate-pyproject
|
|
82
86
|
|
|
83
87
|
- repo: https://github.com/henryiii/validate-pyproject-schema-store
|
|
84
|
-
rev:
|
|
88
|
+
rev: 2026.09.19
|
|
85
89
|
hooks:
|
|
86
90
|
- id: validate-pyproject
|
|
87
91
|
|
|
88
92
|
|
|
89
93
|
- repo: https://github.com/rhysd/actionlint
|
|
90
|
-
rev: v1.7.
|
|
94
|
+
rev: v1.7.12
|
|
91
95
|
hooks:
|
|
92
96
|
- id: actionlint
|
|
93
97
|
|
|
94
98
|
- repo: https://github.com/crate-ci/typos
|
|
95
|
-
rev: v1.
|
|
99
|
+
rev: v1.50.2
|
|
96
100
|
hooks:
|
|
97
101
|
- id: typos
|
|
98
102
|
exclude: ^COPIER_TEMPLATE_CHANGES\.md$
|
|
@@ -20,6 +20,7 @@ Matchify converts eligible `if`/`elif`/`else` chains into Python 3.10+
|
|
|
20
20
|
patterns.
|
|
21
21
|
- `src/matchify/cli.py` implements file processing and the CLI;
|
|
22
22
|
`src/matchify/__main__.py` is the `python -m matchify` entry point.
|
|
23
|
+
- `src/matchify/diff.py` renders conversion diffs for `--show`.
|
|
23
24
|
|
|
24
25
|
## Transformation principles
|
|
25
26
|
|
|
@@ -54,17 +55,27 @@ Matchify converts eligible `if`/`elif`/`else` chains into Python 3.10+
|
|
|
54
55
|
4. Run the focused test, then the full suite:
|
|
55
56
|
|
|
56
57
|
```bash
|
|
57
|
-
uv run pytest tests/
|
|
58
|
+
uv run pytest tests/test_code_samples.py -k <case>
|
|
58
59
|
uv run pytest
|
|
59
60
|
```
|
|
60
61
|
|
|
61
62
|
The test suite is organized as follows:
|
|
62
63
|
|
|
63
|
-
- `tests/
|
|
64
|
-
|
|
64
|
+
- `tests/code_samples/`: source-to-source behavior and rejection cases, including
|
|
65
|
+
assumption and conversion-filter variants. The generic `tests/test_code_samples.py`
|
|
66
|
+
test checks expected output, runtime traces, and idempotence.
|
|
65
67
|
- `tests/test_cli.py`: file processing and CLI behavior.
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
+
- The remaining API and internal tests cover diagnostics, previews, planning,
|
|
69
|
+
data structures, documentation, and the code-sample infrastructure.
|
|
70
|
+
|
|
71
|
+
Code samples contain `# before:`, `# after:`, `# assume:`, and `# trace:` sections.
|
|
72
|
+
Use optional `# ignore-types:` and `# convert-if:` lines for transformation options.
|
|
73
|
+
Generated samples may also contain a `# reference:` code section between `# after:`
|
|
74
|
+
and `# assume:`. The generic test compares its runtime trace with the original
|
|
75
|
+
program, preserving the independent oracle for generator failures.
|
|
76
|
+
Supply executable setup and print observed results; use separate samples for
|
|
77
|
+
different option combinations. Keep API assertions that cannot be expressed by
|
|
78
|
+
source snapshots and runtime traces in ordinary tests.
|
|
68
79
|
|
|
69
80
|
Use `textwrap.dedent()` for multiline source fixtures and temporary directories
|
|
70
81
|
for filesystem tests. Test both successful conversions and nearby cases that
|
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- scriv-insert-here -->
|
|
4
4
|
|
|
5
|
+
<a id='changelog-0.3.0'></a>
|
|
6
|
+
# 0.3.0 — 2026-09-23
|
|
7
|
+
|
|
8
|
+
## Added
|
|
9
|
+
|
|
10
|
+
- Added `--show` and `--show-all` to print one diff per conversion, including
|
|
11
|
+
dictionary lookup rewrites. `--show-all` also previews conversions that need a
|
|
12
|
+
missing `--assume` value.
|
|
13
|
+
|
|
14
|
+
- Added `--convert-if EXPRESSION` to select eligible `if`/`elif` conversions
|
|
15
|
+
using source and generated-pattern metrics, for example
|
|
16
|
+
`--convert-if "branches >= 4 and guard_conditions == 0"`. The default is
|
|
17
|
+
`True`, which selects every eligible chain. Dictionary lookup conversions
|
|
18
|
+
are unaffected by this filter.
|
|
19
|
+
- Conversion previews now display metrics for use in `--convert-if`
|
|
20
|
+
expressions, including branch, pattern, guard, capture, and qualified-value
|
|
21
|
+
counts.
|
|
22
|
+
|
|
23
|
+
## Changed
|
|
24
|
+
|
|
25
|
+
- **Breaking:** `--write` is now required to modify files. `--check` is a dry
|
|
26
|
+
run that implies `--show` and exits with 1 if any file would change. Explicit
|
|
27
|
+
`--show` / `--show-all` without `--write` are preview-only and still exit 0
|
|
28
|
+
when conversions are available. In a TTY, omitting `--write`, `--check`, and
|
|
29
|
+
the show flags still previews diffs and asks before writing. In a
|
|
30
|
+
non-interactive shell, pass `--write`, `--check`, or `--show` explicitly.
|
|
31
|
+
|
|
5
32
|
<a id='changelog-0.2.0'></a>
|
|
6
33
|
# 0.2.0 — 2026-08-08
|
|
7
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: matchify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: converts if-else code to match statements
|
|
5
5
|
Project-URL: Documentation, https://github.com/15r10nk/matchify#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/15r10nk/matchify/issues
|
|
@@ -10,21 +10,22 @@ License-Expression: MIT
|
|
|
10
10
|
License-File: LICENSE
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
17
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
18
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
-
Requires-Python: >=3.
|
|
19
|
+
Requires-Python: >=3.11
|
|
21
20
|
Requires-Dist: libcst>=1.8.6
|
|
21
|
+
Requires-Dist: rich>=13.0
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
|
|
24
|
+
<!-- --8<-- [start:Header] -->
|
|
24
25
|
# Matchify
|
|
25
26
|
|
|
26
27
|

|
|
27
|
-
|
|
28
|
+
[](https://15r10nk.github.io/matchify/latest/)
|
|
28
29
|
[](https://pypi.org/project/matchify/)
|
|
29
30
|

|
|
30
31
|
[](https://pypacktrends.com/?packages=matchify&time_range=2years)
|
|
@@ -33,6 +34,15 @@ Description-Content-Type: text/markdown
|
|
|
33
34
|
Matchify automatically converts eligible `if`/`elif`/`else` chains into
|
|
34
35
|
Python 3.10+ `match` statements while preserving runtime behavior and source
|
|
35
36
|
formatting.
|
|
37
|
+
<!-- --8<-- [end:Header] -->
|
|
38
|
+
|
|
39
|
+
<!-- --8<-- [start:Feedback] -->
|
|
40
|
+
> [!NOTE]
|
|
41
|
+
> Matchify was built with assistance from AI tools. Its implementation and
|
|
42
|
+
> generated transformations may contain mistakes, so review changes and run
|
|
43
|
+
> your project's tests before relying on them. Feedback and bug reports are
|
|
44
|
+
> very welcome.
|
|
45
|
+
<!-- --8<-- [end:Feedback] -->
|
|
36
46
|
|
|
37
47
|
## Examples
|
|
38
48
|
|
|
@@ -208,30 +218,47 @@ uvx matchify path/to/project/
|
|
|
208
218
|
|
|
209
219
|
```bash
|
|
210
220
|
# Convert a single file
|
|
211
|
-
matchify path/to/file.py
|
|
221
|
+
matchify --write path/to/file.py
|
|
212
222
|
|
|
213
223
|
# Convert all Python files in a directory
|
|
214
|
-
matchify path/to/project/
|
|
224
|
+
matchify --write path/to/project/
|
|
215
225
|
|
|
216
226
|
# Convert with verbose output
|
|
217
|
-
matchify path/to/project/ -v
|
|
227
|
+
matchify --write path/to/project/ -v
|
|
218
228
|
|
|
219
|
-
#
|
|
229
|
+
# Review diffs without writing changes
|
|
220
230
|
matchify path/to/project/ --check
|
|
221
231
|
|
|
232
|
+
# Show eligible conversions as diffs while converting
|
|
233
|
+
matchify path/to/project/ --show --write
|
|
234
|
+
|
|
235
|
+
# Also preview conversions that need a missing --assume value
|
|
236
|
+
matchify path/to/project/ --show-all --check
|
|
237
|
+
|
|
222
238
|
# Use parallel processing (default: number of CPUs)
|
|
223
|
-
matchify path/to/project/ -j 8
|
|
239
|
+
matchify path/to/project/ --write -j 8
|
|
224
240
|
|
|
225
241
|
# Enable one risky assumption explicitly
|
|
226
|
-
matchify path/to/project/ --assume pure-subjects
|
|
242
|
+
matchify path/to/project/ --write --assume pure-subjects
|
|
227
243
|
|
|
228
244
|
# Disable all risky assumptions
|
|
229
|
-
matchify path/to/project/ --safe
|
|
245
|
+
matchify path/to/project/ --write --safe
|
|
230
246
|
|
|
231
247
|
# Enable all risky assumptions
|
|
232
|
-
matchify path/to/project/ --risky
|
|
248
|
+
matchify path/to/project/ --write --risky
|
|
249
|
+
|
|
250
|
+
# Convert only chains that meet a stylistic threshold
|
|
251
|
+
matchify path/to/project/ --convert-if "isinstance_checks >= 2 or branches >= 4"
|
|
233
252
|
```
|
|
234
253
|
|
|
254
|
+
`--write` writes conversions and `--check` only reports them as diffs; the two
|
|
255
|
+
options cannot be combined. `--check` implies `--show` and exits with 1 if any
|
|
256
|
+
file would change. Explicit `--show` or `--show-all` without `--write` is a
|
|
257
|
+
preview-only dry run that still exits 0 when conversions are available. In an
|
|
258
|
+
interactive terminal, omitting `--write`, `--check`, and the show flags shows a
|
|
259
|
+
diff and asks for confirmation before writing. In a non-interactive shell,
|
|
260
|
+
choose `--write`, `--check`, or `--show` explicitly.
|
|
261
|
+
|
|
235
262
|
## pre-commit
|
|
236
263
|
|
|
237
264
|
Matchify provides two pre-commit hooks.
|
|
@@ -260,168 +287,38 @@ repos:
|
|
|
260
287
|
|
|
261
288
|
## Risky assumptions
|
|
262
289
|
|
|
263
|
-
By default, Matchify enables no risky assumptions. `--safe` makes that explicit
|
|
264
|
-
`--risky` enables all available
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
that chain.
|
|
268
|
-
|
|
269
|
-
### `--assume=pure-subjects`
|
|
270
|
-
|
|
271
|
-
Permits transformations such as `a.x == 1 and b.y == 2` into a match on
|
|
272
|
-
`(a.x, b.y)`. This evaluates every subject eagerly, so enable it only when those
|
|
273
|
-
name, attribute, and subscript reads cannot raise exceptions or produce
|
|
274
|
-
observable side effects. Without the option, later `and` operands remain guards
|
|
275
|
-
and preserve short-circuiting.
|
|
276
|
-
|
|
277
|
-
```python
|
|
278
|
-
# Before
|
|
279
|
-
if a.x == 1 and b.y == 2:
|
|
280
|
-
handle_first()
|
|
281
|
-
elif a.x == 3 and b.y == 4:
|
|
282
|
-
handle_second()
|
|
283
|
-
|
|
284
|
-
# After
|
|
285
|
-
match (a.x, b.y):
|
|
286
|
-
case 1, 2:
|
|
287
|
-
handle_first()
|
|
288
|
-
case 3, 4:
|
|
289
|
-
handle_second()
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### `--assume=use-object`
|
|
293
|
-
|
|
294
|
-
Permits generic attribute patterns such as `object(x=1)` when different
|
|
295
|
-
branches inspect attributes of a common object without an explicit `isinstance`
|
|
296
|
-
check. This performs pattern-time attribute lookups, so enable it only when
|
|
297
|
-
those lookups cannot raise exceptions or produce observable side effects.
|
|
298
|
-
|
|
299
|
-
```python
|
|
300
|
-
# Before
|
|
301
|
-
if value.x == 1:
|
|
302
|
-
handle_x()
|
|
303
|
-
elif value.y == 2:
|
|
304
|
-
handle_y()
|
|
305
|
-
|
|
306
|
-
# After
|
|
307
|
-
match value:
|
|
308
|
-
case object(x=1):
|
|
309
|
-
handle_x()
|
|
310
|
-
case object(y=2):
|
|
311
|
-
handle_y()
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### `--assume=identity-equality`
|
|
315
|
-
|
|
316
|
-
Permits conversions from qualified identity comparisons such as
|
|
317
|
-
`op is Op.ADD` to value patterns such as `case Op.ADD`. Match value patterns
|
|
318
|
-
compare with equality, not identity, so enable it only when identity and
|
|
319
|
-
equality are equivalent for those values.
|
|
320
|
-
|
|
321
|
-
```python
|
|
322
|
-
# Before
|
|
323
|
-
if op is Op.ADD:
|
|
324
|
-
add()
|
|
325
|
-
elif op is Op.SUB:
|
|
326
|
-
subtract()
|
|
327
|
-
|
|
328
|
-
# After
|
|
329
|
-
match op:
|
|
330
|
-
case Op.ADD:
|
|
331
|
-
add()
|
|
332
|
-
case Op.SUB:
|
|
333
|
-
subtract()
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
### `--assume=hashable-subjects`
|
|
337
|
-
|
|
338
|
-
Permits membership tests against literal sets to become OR patterns. Set
|
|
339
|
-
membership hashes the subject and can raise `TypeError` for an unhashable value,
|
|
340
|
-
while a pattern only performs equality comparisons. Enable it only when match
|
|
341
|
-
subjects are hashable. Custom `__hash__` and `__eq__` implementations may still
|
|
342
|
-
make lookup behavior or side effects differ from pattern matching.
|
|
343
|
-
|
|
344
|
-
```python
|
|
345
|
-
# Before
|
|
346
|
-
if value in {1, 2}:
|
|
347
|
-
handle_small()
|
|
348
|
-
elif value == 3:
|
|
349
|
-
handle_three()
|
|
350
|
-
|
|
351
|
-
# After
|
|
352
|
-
match value:
|
|
353
|
-
case 1 | 2:
|
|
354
|
-
handle_small()
|
|
355
|
-
case 3:
|
|
356
|
-
handle_three()
|
|
357
|
-
```
|
|
290
|
+
By default, Matchify enables no risky assumptions. `--safe` makes that explicit,
|
|
291
|
+
while `--risky` enables all available assumptions. See the
|
|
292
|
+
[risky assumptions documentation](https://15r10nk.github.io/matchify/latest/assumptions/)
|
|
293
|
+
for the semantic tradeoffs and individual `--assume` names.
|
|
358
294
|
|
|
359
|
-
|
|
295
|
+
`--check` and `--show` review the currently eligible conversions as diffs.
|
|
296
|
+
`--show --write` prints the same diffs while converting. Both report how many
|
|
297
|
+
conversions were not shown because they need a missing `--assume` value and
|
|
298
|
+
point you to `--show-all` to preview them. `--show-all` additionally prints the
|
|
299
|
+
required `--assume` value and a separate diff for each group of conversions
|
|
300
|
+
unlocked by that assumption. For `if`/`elif` previews, both commands also print
|
|
301
|
+
the computed `--convert-if` metric variables for that conversion.
|
|
360
302
|
|
|
361
|
-
|
|
362
|
-
check. Python sequence patterns can also match other sequence types, so enable
|
|
363
|
-
it only when that broader match is acceptable.
|
|
303
|
+
## Selective conversion with `--convert-if`
|
|
364
304
|
|
|
365
|
-
|
|
366
|
-
# Before
|
|
367
|
-
if isinstance(value, list) and len(value) == 1 and value[0] == 1:
|
|
368
|
-
handle_one()
|
|
369
|
-
elif value is None:
|
|
370
|
-
handle_none()
|
|
305
|
+
By default, Matchify converts every eligible chain. This is equivalent to:
|
|
371
306
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
case 1,:
|
|
375
|
-
handle_one()
|
|
376
|
-
case None:
|
|
377
|
-
handle_none()
|
|
307
|
+
```text
|
|
308
|
+
--convert-if True
|
|
378
309
|
```
|
|
379
310
|
|
|
380
|
-
|
|
311
|
+
Use `--convert-if` to choose a different threshold based on source and generated
|
|
312
|
+
metrics:
|
|
381
313
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
it only when that broader match is acceptable. Checks against `(list, tuple)`
|
|
385
|
-
require both sequence assumptions.
|
|
386
|
-
|
|
387
|
-
```python
|
|
388
|
-
# Before
|
|
389
|
-
if isinstance(value, tuple) and len(value) == 1 and value[0] == 1:
|
|
390
|
-
handle_one()
|
|
391
|
-
elif value is None:
|
|
392
|
-
handle_none()
|
|
393
|
-
|
|
394
|
-
# After
|
|
395
|
-
match value:
|
|
396
|
-
case 1,:
|
|
397
|
-
handle_one()
|
|
398
|
-
case None:
|
|
399
|
-
handle_none()
|
|
314
|
+
```bash
|
|
315
|
+
matchify path/to/project/ --convert-if "branches >= 4 and guard_conditions == 0"
|
|
400
316
|
```
|
|
401
317
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
dictionary values are evaluated only in the selected case instead of eagerly
|
|
407
|
-
when constructing the dictionary. Enable it only when those equality and
|
|
408
|
-
evaluation-order differences are acceptable. Tuple keys, including nested
|
|
409
|
-
tuples, become sequence patterns and can therefore also match equivalent
|
|
410
|
-
non-tuple sequences.
|
|
411
|
-
|
|
412
|
-
```python
|
|
413
|
-
# Before
|
|
414
|
-
result = {"create": "POST", "read": "GET"}[operation]
|
|
415
|
-
|
|
416
|
-
# After
|
|
417
|
-
match operation:
|
|
418
|
-
case "create":
|
|
419
|
-
result = "POST"
|
|
420
|
-
case "read":
|
|
421
|
-
result = "GET"
|
|
422
|
-
case _matchify_key:
|
|
423
|
-
raise KeyError(_matchify_key)
|
|
424
|
-
```
|
|
318
|
+
Use `--convert-if True` if you want that default spelled out explicitly in
|
|
319
|
+
scripts or examples. See the
|
|
320
|
+
[selective conversion documentation](https://15r10nk.github.io/matchify/latest/selective-conversion/)
|
|
321
|
+
for the expression syntax and complete metric reference.
|
|
425
322
|
|
|
426
323
|
## Development
|
|
427
324
|
|