-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-42128: Structural Pattern Matching (PEP 634) #22917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
260 commits
Select commit
Hold shift + click to select a range
1d39be6
Tentative (incomplete) grammar for match statements
gvanrossum 67354ad
Add tests for or-patterns
brandtbucher 5d609c7
Add support for or-patterns
brandtbucher a222351
Merge branch 'patma' of https://github.com/brandtbucher/cpython into …
brandtbucher 1f8bcbd
Clean up pattern matching compiler
brandtbucher eb704d4
Add attribute/name support
brandtbucher 5a361bf
Validate name context
brandtbucher 9c2e61c
Clean up pattern compiler
brandtbucher dddcca8
Don't bind _
brandtbucher af70c74
Add sequence tests
brandtbucher 4191858
Add basic sequence support
brandtbucher 33633c1
Add support for starred sub-patterns in sequences
brandtbucher a36542e
Format tests
brandtbucher d62a426
Merge branch 'master' of https://github.com/python/cpython into patma
brandtbucher 76d108c
Simplify control-flow
brandtbucher 34c54a0
Rename blocks
brandtbucher 8bc9ae5
Add GET_MATCH_ITER opcode
brandtbucher 2586ee6
Add string tests
brandtbucher adb04fd
Rename and add patma tests
brandtbucher 6eb6783
Cleanup
brandtbucher f3c513d
Use Mapping/Sequence _collections_abc
brandtbucher fc472c7
Add missing error handling
brandtbucher 26dd4fd
Add GET_MATCH_MAP
brandtbucher 6ce6c34
Simplify new opcodes
brandtbucher ea0de16
Bump MAGIC_NUMBER
brandtbucher 880a7c2
Add mapping support
brandtbucher 297ceb2
Add a bunch of mapping tests, plus cleanup
brandtbucher 1902b21
Reorganize pattern compiler
brandtbucher 09e8fdc
Handle errors when creating new blocks
brandtbucher f612a27
Break out _collections_abc stuff in ceval
brandtbucher 21ac879
Clean up new opcode docs
brandtbucher c103ab4
Simplify string checks
brandtbucher 14409e0
Add basic AST optimization
brandtbucher e91c400
Fix asserts
brandtbucher 7fb4d11
Implement default object.__match__
brandtbucher 17356fb
Fix sequence matching bug
brandtbucher 9d7bd07
BinOp -> BoolOp
brandtbucher 77fc89d
Fix failing tests
brandtbucher bad2fe2
Add MATCH_TYPE opcode
brandtbucher 2924d2f
Fix parsing/unparsing of name contexts
brandtbucher 66852e9
Clean up grammar
brandtbucher f1a1eb9
Fix calls and error messages
brandtbucher de7c3f0
Miscellaneous cleanup
brandtbucher 89974f0
Convert AST tests to native syntax
brandtbucher ac87fcb
Allow literal negative numbers
brandtbucher e3d07ab
Add checks for name bindings
brandtbucher 9da2729
Cleanup
brandtbucher 546b6c4
Add support for complex literals
brandtbucher 1eddf27
Fix AST validation
brandtbucher 04bad8e
MATCH_TYPE -> DESTRUCTURE
brandtbucher e4be187
Fix attribute parsing
brandtbucher 9a06fe3
Clean up and add tests
brandtbucher bb0ed11
Support destructuring type matches
brandtbucher 03212ea
Simplify final (or only) case
brandtbucher ccf8374
Tell the peepholer about all of the jumping we do
brandtbucher c7f121b
Reject f-strings, addition, and subtraction
brandtbucher 8d61da2
__match_args__ must contain strings
brandtbucher 0c15e70
Better error messages for tuples
8000
brandtbucher 28bf07b
Add length-checking opcodes
brandtbucher 009ca7e
Start phasing in new opcodes
brandtbucher 32b396f
Refactor sequence-matching opcodes
brandtbucher a7e0488
OLD_MATCH_MAP_STAR -> OLD_MATCH_MAP
brandtbucher eb0fe26
Support None/missing __match_args__
brandtbucher 6da649b
Catch up with master
brandtbucher 90422e4
Clean up map matches
brandtbucher 73d4a2b
Get rid of LIST_POP
brandtbucher 2c5226a
Validate missing attributes with __match_args__
brandtbucher f4644aa
Incomplete __match_args_required__ support
brandtbucher ce7b021
Finish __match_args_required__ support
brandtbucher 99d805c
Catch up with master
brandtbucher 6cc4128
Trivial grammar clean-ups
brandtbucher 4973548
Add back type annotations.
brandtbucher b50e403
Simplify or-pattern parsing
brandtbucher 1e0e35a
Refactor MATCH opcode.
brandtbucher f5974ed
Catch up with master
brandtbucher 3130114
Tuples!
brandtbucher de78bc5
Fix line numbers
brandtbucher 1aecf5f
Catch up with master
brandtbucher 07b1474
Improve compilation of wildcards.
brandtbucher 18ef577
Better error message for bad types.
brandtbucher 4106b66
Fix duplicate test
brandtbucher 5ef4df0
Progress on performance improvements
brandtbucher ff0c902
Fix segfault on missing attribute
brandtbucher 38000fa
Cleanup
brandtbucher 15e8824
Support for __match_args__ in dataclasses.
viridia 59c7a2f
Performance tweaks and __match__ protocol updates
brandtbucher db054a6
Match support for namedtuple.
viridia db4a9b0
Lose __match_args_required__, speed up MATCH_SEQ
brandtbucher 48f18eb
Remove a bunch of new opcodes
brandtbucher 0c82655
Don't raise if no __match_args__
brandtbucher 0ddf11c
Catch up with master
brandtbucher ef35201
Add ImpossibleMatchError
brandtbucher 276c2b0
Clean up opcodes and fix pickle tests
brandtbucher 14be5cf
Clean up ceval
brandtbucher 23dc88b
Add typing.sealed
brandtbucher 6fa3eb3
Allow unparenthesized tuples as targets
brandtbucher 67146a3
Fix handling of copied mappings
brandtbucher d7bb7ee
Add tests
brandtbucher 574593c
Fix match target parsing
brandtbucher 340d66f
Add more mapping tests and a performance utility
brandtbucher ca58086
More cleanup
brandtbucher 3ec5802
Rough revision of __match__ protocol
brandtbucher 0d99af4
Remove old AST tests and add "simple" match tests
brandtbucher 018e6ab
Cleanup
brandtbucher 7a6d897
Add pattern_context
brandtbucher 7953dee
Keep bound names in pattern context
brandtbucher 214101e
Address recent __match__ protocol changes
brandtbucher 9e170bc
Ditch __match__!
brandtbucher d696de7
Fix whitespace diff
brandtbucher 5e621f6
Catch up with master
brandtbucher bb8fb1b
Clean up tests and fix refleak in mapping patterns
brandtbucher 36398b1
Minor improvements for class matches
brandtbucher 82055e2
Mapping destructuring improvements
brandtbucher c9b3b4e
Use tuple for dataclass __match_args__
brandtbucher 793add3
Add tests for new match grammar
brandtbucher 4efdb9a
Clean up compile.c and add SyntaxWarning
brandtbucher 46f3350
Clean up compiler
brandtbucher 9b343b7
Progress on reducing the number of blocks
brandtbucher a4fd8a3
Simplify emitted bytecode
brandtbucher c9ad4b4
Catch up with master
brandtbucher b642e08
Implement __match_args__ for AST classes
pablogsal e39b3e2
No more leading dots
brandtbucher 123e15b
Only use nonnegative integer indices
brandtbucher 2f03ae0
Remove leading dot rules from unparsing logic
brandtbucher ef881fa
Use MATCH_ITEM for mapping and class patterns
brandtbucher eb86fa7
Reduce unnecessary EXTENDED_ARG instructions
brandtbucher f3d3d83
Documentation and cleanup
brandtbucher b0a02f5
Generalize conditional jump peepholing
brandtbucher da6ee98
MATCH_ITEM* -> GET_INDEX*
brandtbucher 3eda95e
Revert old unparse hack
brandtbucher b3840be
Improve performance for wildcards
brandtbucher 14e4eaa
Add/fix tests
brandtbucher 4789bff
Fix refleaks when tracking names
brandtbucher 1260139
Regenerate keyword module
brandtbucher 34f8111
Add a ton of tests
brandtbucher 3eadc53
Add more tests
brandtbucher b09e822
Catch up with master
brandtbucher 7d23259
Update test
brandtbucher bed2e68
target -> subject
brandtbucher 1a70d2c
Add tests
brandtbucher f83302f
Refactor loads
brandtbucher 1ba56a0
Cleanup and better performance for default cases
brandtbucher 3fd91d9
More cleanup
brandtbucher 1de2a1c
Ditch unhelpful warning and add OPTIM note
brandtbucher 7864718
Preserve TOS when compiling patterns
brandtbucher 6fdc00c
Clean up some duplicate tests
brandtbucher ee2beb2
Improve test coverage for errors and warnings
brandtbucher b4b8416
Add more tests for runtime errors
brandtbucher f819084
Clean up comments
brandtbucher 6228a57
Fix bugs in peephole optimizer changes
brandtbucher ce7aab4
Apparently the compiler's been rewritten for 3.10... :(
brandtbucher 92f6c53
Disable unfinished validation
brandtbucher 466becd
Skip performance benchmarking for some tests
brandtbucher a8d0a86
Fix typo
brandtbucher 66d614b
Unify shared SyntaxError test logic
brandtbucher 3f76403
Add two more tests for soft keywords
brandtbucher a527f66
Refactor MATCH_CLASS
brandtbucher 2cc4fee
Catch up with master
brandtbucher 19af7d5
Literal False/True/None compares by identity
brandtbucher 601645b
Remove sealed
brandtbucher eed6806
Revert whitespace change
brandtbucher 3c4796c
Assorted cleanup
brandtbucher 45b1429
Add three more identity tests
brandtbucher 99c5296
Catch up with master
brandtbucher 5505fc3
Fixes for grammar changes
brandtbucher 587ba87
Use sets to track map keys and attribute names.
brandtbucher a1e88fe
Add a few notes.
brandtbucher 3a124db
Catch up with master
brandtbucher bd2bffb
Catch up with master
brandtbucher 91661eb
"n := p" -> "p as n"
brandtbucher 28ba072
Use new MatchAs node for named patterns
brandtbucher 462796e
Add version check
brandtbucher ebd95c6
Raise for unreachable patterns
brandtbucher de1b020
Clean up error messages
brandtbucher f5c2482
Minor cleanup
brandtbucher 4de619a
Reorganize some sequence/mapping logic
brandtbucher 9f1c91d
More ceval cleanup
brandtbucher 88bd791
Don't mark _ as local in patterns
brandtbucher 12b6575
More cleanup
brandtbucher d394aa4
Add some tests for non-dict Mappings
brandtbucher 2028445
Remove half-finished PyAST_Validate implementation
brandtbucher 20b59b2
Remove some questionable fast paths
brandtbucher b42a3ac
Add test_patma to PGO
brandtbucher ccb5d90
Clean up SyntaxErroring
brandtbucher 7a97a1f
Unsafe caching strikes again
brandtbucher ff011e0
Fix comment
brandtbucher 99ae758
Remove unused get_len member
brandtbucher ad84403
Rename simple match flag
brandtbucher 1b0602f
BoolOp -> MatchOr and fix constant folding
brandtbucher e212ceb
Minor cleanup
brandtbucher 94b19ee
Unify grammar with PEP 634 (mostly)
brandtbucher 77515ec
Clean up open_sequence_pattern usage
brandtbucher c0a06d1
More cleanup
brandtbucher 26d35e5
Raise remaining SyntaxErrors in compiler
brandtbucher d43bb0b
Finish compiler cleanup
brandtbucher 008f4ec
Catch up with master
brandtbucher d5f32da
Add NEWS entry
brandtbucher 949822c
Improve precedence logic in ast.unparse
brandtbucher a31f2ef
Some VM cleanup
brandtbucher fe35b08
alternate -> alternative
brandtbucher e688005
Remove dict copy fast-path, add comments
brandtbucher 5589f77
Finish ceval cleanup
brandtbucher a0f659a
Catch up with master
brandtbucher 243f3d2
Regenerate the keyword module
brandtbucher a1ba3a7
Add regen-keyword to regen-all
brandtbucher 812abd0
Catch up wih master
brandtbucher 8b093eb
Remove iterator checks from sequence patterns
brandtbucher b85fde5
Catch up with master
brandtbucher 130ec39
Catch up with master
brandtbucher e21d33a
Re-bump magic number
brandtbucher 418c69d
Catch up with master
brandtbucher 8bab3ed
Catch up with master
brandtbucher 7bf4ee4
Catch up with master
brandtbucher 16e218a
Fix compiler warning
brandtbucher fbd299b
Catch up with master
brandtbucher 3279c57
Catch up with master
brandtbucher ff03e6b
Catch up with master
brandtbucher 6f09968
Catch up with master
brandtbucher d9def0b
Catch up with master
brandtbucher ef87100
Catch up with master
brandtbucher 7eee880
Catch up with master
brandtbucher f97b2eb
Catch up with master
brandtbucher 165d491
Catch up with master
brandtbucher c732376
Catch up with master
brandtbucher c5729ec
Catch up with master
brandtbucher e149ab5
Catch up with master
brandtbucher d105180
Catch up with master
brandtbucher 47c9218
CHECK -> RETURN_IF_FASLE
brandtbucher 193f037
Cleanup
brandtbucher 0618706
Catch up with master
brandtbucher b748e41
pattern_helper_load_constant -> ADDOP_LOAD_CONST
brandtbucher cc3357c
!x -> x == NULL
brandtbucher 72b623c
pattern_helper_load_attr -> compiler_visit_expr
brandtbucher 93cefc1
GET_INDEX/GET_INDEX_END -> BINARY_SUBSCR
brandtbucher 62372c2
MATCH_KEYS -> MATCH_KEYS/COPY_DICT_WITHOUT_KEYS
brandtbucher 2a5d0dd
Clean up MATCH_KEYS
brandtbucher fa97ee3
Refactor sequence matches to use existing ops
brandtbucher 0de83a2
Clean up compiler_pattern_sequence
brandtbucher 162f9b6
Clean up comment
brandtbucher 49b2823
Factor out get_match_args
brandtbucher 3f8fdaf
Replace TOS instead of pushing onto it
brandtbucher 632a645
Catch up with master
brandtbucher 0d56285
Catch up with master
brandtbucher 69fa421
Fix NULL pointer error
brandtbucher 1711207
Don't keep uninitialized tuples hanging around
brandtbucher f7c833e
Catch up with master
brandtbucher 7762099
Fix new refleaks ("-R 3:3" is clean again)
brandtbucher 5e269fb
Use PySet_CheckExact (thanks Pablo!)
brandtbucher ca6e332
Move some comments
brandtbucher 61616fc
Catch up with master
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clean up ceval
- Loading branch information
commit 14be5cf8c752dcf4e79bcd952b45c3ffba7704bd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.