Skip to content

Conversation

@SoulSniper1212
Copy link

Overview

This PR adds a new check for simplifiable match statements that use simple sequences or mappings (like lists or dicts with literal values). The check identifies when a match statement can be replaced with a simpler if statement using equality comparison.

Checklist

  • Code changes implemented
  • Tests added and passing
  • Documentation updated in violation docstring

Proof

The new visitor SimplifiableMatchWithSequenceOrMappingVisitor checks for match statements that:

  • Have exactly two cases
  • The first case uses a simple sequence or mapping pattern (with literals, no variable bindings)
  • The second case is a wildcard (case _:)
  • No guards or starred patterns are present

When these conditions are met, it raises SimplifiableMatchWithSequenceOrMappingViolation with code 366. The test file test_simplified_match_with_sequence_or_mapping.py validates both simplifiable and non-simplifiable patterns.

Closes #3527

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer if over match simple sequences and mappings

1 participant