Skip to content
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

Support for python 3.10 match statement #10191

Merged
merged 84 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
3847124
Add Nodes needed for match statement support
freundTech Mar 9, 2021
f9e9277
Added match statement support to StrConv visitor
freundTech Mar 9, 2021
6c4109f
Added match statement support to TraverserVisitor
freundTech Mar 9, 2021
289d014
Move MatchAs and MatchOr to patterns and add literal patterns
freundTech Mar 10, 2021
1973a88
Added nodes for capture and wildcard patterns
freundTech Mar 10, 2021
cc92db4
Added nodes for value, sequence and mapping patterns
freundTech Mar 10, 2021
057716c
Added nodes for class patterns
freundTech Mar 10, 2021
6bfb098
Added parser tests for pattern matching and tweaks to pattern classes
freundTech Mar 10, 2021
a74b0e6
Added patterns to NodeVisitor and TraverserVisitor
freundTech Mar 10, 2021
fc3c1d2
Add missing parse test and prevent tests from running on < 3.10
freundTech Mar 10, 2021
db04186
Add parse tests for open sequence patterns
freundTech Mar 10, 2021
eeca25b
Added match statement support to SemanticAnalyzerPreAnalysis
freundTech Mar 12, 2021
cc76f59
Also consider pattern in SemanticAnalyzerPreAnalysis
freundTech Mar 12, 2021
36a45b3
Use common base classes instead of unions for patterns
freundTech Mar 12, 2021
7facb0d
Added match statement support for variable renaming (allow-redefinition)
freundTech Mar 12, 2021
1bc8a4b
Added match statement support for SemanticAnalyzer
freundTech Mar 13, 2021
d26d81c
Moved int from types to builtin stubs in order to extend int
freundTech Apr 5, 2021
3effadc
Added initial version of match statement type checking
freundTech Apr 6, 2021
3aab780
Use double quotes in error messages
freundTech Apr 6, 2021
3a71c32
Add support for match statement self matching class patterns
freundTech Apr 6, 2021
b7468d9
Replace more single quotes in tests with double quotes
freundTech Apr 7, 2021
943f2ff
Add support for __match_args__ to dataclass
freundTech Apr 7, 2021
b41fa30
Minor code cleanup
freundTech Apr 7, 2021
037a140
Add support __match_args__ to namedtuple
freundTech Apr 7, 2021
fb9ae47
Add support for match statement as pattern and change type_stack to Type
freundTech Apr 7, 2021
99c1bbf
Make PatternChecker infer unions for patterns with the same name
freundTech Apr 8, 2021
0e47d6f
Implemented match_args parameter for dataclasses (bpo-43764)
freundTech Apr 12, 2021
77b997b
Refactor PatternChecker
freundTech Apr 14, 2021
5228bc7
Add match statement support for or pattern
freundTech Apr 20, 2021
bba61fa
Fix make_simplified_union for instances with last_known_value
freundTech Apr 26, 2021
39478fd
Infer literals from literal patterns in match statements
freundTech Apr 27, 2021
a865882
Infer the rest pattern for mapping patterns
freundTech Apr 27, 2021
c35d921
Adjust ASTConverter to use dedicated pattern nodes
freundTech Apr 30, 2021
1aae2c1
Improve type inference for tuples checked against sequence patterns
freundTech May 1, 2021
1364a67
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech May 1, 2021
32a7b71
Fix linter errors
freundTech May 3, 2021
25fe496
Sync typeshed
freundTech May 10, 2021
86a6ce9
Fix sequence pattern outer type check to be in line with PEP 634
freundTech May 10, 2021
9445c10
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech May 10, 2021
74c7040
Remove accidentally commited changes
freundTech May 10, 2021
c964027
Fix failing TypeExport tests
freundTech May 10, 2021
f6b1752
Improve type inference for mapping pattern rest
freundTech May 11, 2021
d2b7d1e
Improve class pattern subpattern type inference
freundTech May 11, 2021
5c47852
Fix selftest failing
freundTech May 18, 2021
0ac21d0
Fix mypyc build failing
freundTech May 18, 2021
7db936b
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech May 18, 2021
5f98cdd
Fix another mypyc build error
freundTech May 18, 2021
423b04c
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech Sep 27, 2021
f2e12f8
Fix failing tests after merge (Caused by #8578)
freundTech Sep 27, 2021
a5eb480
Fixed more failing tests after merge (Caused by #10685)
freundTech Sep 27, 2021
9d5d600
Adjust some tests and add new ones
freundTech Sep 28, 2021
a68ea59
Fixed types staying narrowed after match statement
freundTech Sep 29, 2021
43fd6e5
Run com2ann and fix errors
freundTech Sep 29, 2021
d7baadf
Split conditional_type_maps into two functions
freundTech Sep 29, 2021
8a3ba8e
Readd removed workaround as the problem is still present
freundTech Sep 29, 2021
90aa1a7
Disable Exhaustiveness test for now
freundTech Oct 4, 2021
de723e1
Fixed checking of nested list statements failing
freundTech Oct 6, 2021
3fb2cf2
Fixed mypy crashing when list statement can't match
freundTech Oct 6, 2021
ab7a2e3
Moved test to correct category
freundTech Oct 6, 2021
45e2abe
Simplify conditional_types
freundTech Sep 30, 2021
44ca265
Generate intersection types in match statements and add guard tests
freundTech Oct 11, 2021
21f7b59
Fixed broken tests
freundTech Oct 11, 2021
bfb578d
Fix mypy_primer differences
freundTech Oct 12, 2021
909fc55
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech Oct 12, 2021
c0a43e8
Fix type errors
freundTech Oct 12, 2021
f768993
Fixed copy-paste error causing mypyc crash
freundTech Oct 12, 2021
7b60596
Added semanal tests for undefined value and class patterns
freundTech Oct 20, 2021
6cf9f58
Removed redundant bool from lib-stubs
freundTech Oct 20, 2021
268e181
Removed tuple from lib-stub
freundTech Oct 20, 2021
dbcd886
Fix typo in test
freundTech Oct 20, 2021
bd7e777
Fixed testcase and marked it as skip
freundTech Oct 20, 2021
f51c83f
Moved messages to message_registry
freundTech Oct 20, 2021
4d87ca1
Removed outdated comment
freundTech Oct 20, 2021
9f9efcc
Removed full stop from error message
freundTech Oct 20, 2021
68bd2ba
Change test case to new error message
freundTech Oct 20, 2021
ff5123c
Report error for non-existing keywords on class patterns
freundTech Oct 20, 2021
13b675b
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech Oct 20, 2021
e437323
Fixed dataclasses plugin after merging master.
freundTech Oct 20, 2021
68a09ee
Added more comments and asserts to pattern classes
freundTech Oct 21, 2021
a5baf60
Readd tuple missing tests
freundTech Oct 21, 2021
4add6b7
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech Dec 18, 2021
eabeb89
Merge remote-tracking branch 'upstream/master' into feature-match-stmt
freundTech Dec 18, 2021
53d40f8
Added missing Final annotations
freundTech Dec 19, 2021
52dc066
Add comments and clarify some names
freundTech Dec 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 216 additions & 69 deletions mypy/checker.py

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,11 @@ def nonliteral_tuple_index_helper(self, left_type: TupleType, index: Expression)
else:
return union

def visit_typeddict_index_expr(self, td_type: TypedDictType, index: Expression) -> Type:
def visit_typeddict_index_expr(self, td_type: TypedDictType,
index: Expression,
local_errors: Optional[MessageBuilder] = None
) -> Type:
local_errors = local_errors or self.msg
if isinstance(index, (StrExpr, UnicodeExpr)):
key_names = [index.value]
else:
Expand All @@ -3096,14 +3100,14 @@ def visit_typeddict_index_expr(self, td_type: TypedDictType, index: Expression)
and key_type.fallback.type.fullname != 'builtins.bytes'):
key_names.append(key_type.value)
else:
self.msg.typeddict_key_must_be_string_literal(td_type, index)
local_errors.typeddict_key_must_be_string_literal(td_type, index)
return AnyType(TypeOfAny.from_error)

value_types = []
for key_name in key_names:
value_type = td_type.items.get(key_name)
if value_type is None:
self.msg.typeddict_key_not_found(td_type, key_name, index)
local_errors.typeddict_key_not_found(td_type, key_name, index)
return AnyType(TypeOfAny.from_error)
else:
value_types.append(value_type)
Expand Down
Loading