Skip to content

Commit

Permalink
fix: parse error on Python3.10 match case 'True'|'False' (#19)
Browse files Browse the repository at this point in the history
Fixes #19.
  • Loading branch information
wookayin committed Nov 29, 2023
1 parent 96b5f05 commit 482b300
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rplugin/python3/semshi/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _iter_node(self, node):
self.visit(item)
# We would want to use isinstance(value, AST) here. Not sure how
# much more expensive that is, though.
elif value_type not in (str, int, bytes):
elif value_type not in (str, int, bytes, bool):
self.visit(value)


Expand Down
18 changes: 18 additions & 0 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,24 @@ def _find_annotations_for_method():
assert annos[7].name == 'D' and annos[7].hl_group == LOCAL


@pytest.mark.skipif('sys.version_info < (3, 10)')
def test_match_case():
"""Tests match/case syntax. see wookayin/semshi#19."""
parse('''
#!/usr/bin/env python3
import sys
arg = False
match arg:
case True: print('boolean')
case False: print('boolean')
case 42: print('integer')
case 3.14: print('float')
case "string": print('string')
case b"123": print('bytearray')
case sys.version: print('expr')
''')


class TestNode:

def test_node(self):
Expand Down

0 comments on commit 482b300

Please sign in to comment.