Skip to content

Commit

Permalink
Do not match keywords named 'match' (#1111)
Browse files Browse the repository at this point in the history
Closes #1110 , do not match variable names named 'match'.

---------

Signed-off-by: Kyle Gottfried <[email protected]>
Co-authored-by: Charles <[email protected]>
Co-authored-by: Bill Wendling <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2023
1 parent cc9ae94 commit 77c29ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
by removing the "verify" parameter.
- Changed FORCE_MULTILINE_DICT to override SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES.
- Adopt pyproject.toml (PEP 517) for build system
- Do not treat variables named `match` as the match keyword

## [0.40.1] 2023-06-20
### Fixed
Expand Down
20 changes: 16 additions & 4 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

from yapf.pytree import split_penalty
from yapf.pytree.pytree_utils import NodeName
from yapf.yapflib import logical_line
from yapf.yapflib import object_state
from yapf.yapflib import style
Expand Down Expand Up @@ -1101,15 +1102,26 @@ def _ContainerFitsOnStartLine(self, opening):


_COMPOUND_STMTS = frozenset({
'for', 'while', 'if', 'elif', 'with', 'except', 'def', 'class', 'match',
'case'
'for',
'while',
'if',
'elif',
'with',
'except',
'def',
'class',
})


def _IsCompoundStatement(token):
if token.value == 'async':
value = token.value
if value == 'async':
token = token.next_token
return token.value in _COMPOUND_STMTS
if token.value in _COMPOUND_STMTS:
return True
parent_name = NodeName(token.node.parent)
return value == 'match' and parent_name == 'match_stmt' or \
value == 'case' and parent_name == 'case_stmt'


def _IsFunctionDef(token):
Expand Down

0 comments on commit 77c29ef

Please sign in to comment.