Skip to content

Commit 97274d0

Browse files
committed
Removed Match Statements
Apparently, they are incompatible with pre Python 3.10
1 parent 10ac458 commit 97274d0

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

src/inline/plugin.py

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -554,23 +554,42 @@ class ConstrArgs(enum.Enum):
554554

555555
if corr_val_type and corr_arg_type:
556556
# Accounts for additional checks for REPEATED and TAG_STR arguments
557-
match arg_idx:
558-
case ConstrArgs.REPEATED:
559-
if arg.value <= 0:
560-
raise MalformedException(f"inline test: {self.arg_repeated_str} must be greater than 0")
561-
self.cur_inline_test.repeated = getattr(arg, value_prop_name)
562-
case ConstrArgs.TAG_STR:
563-
tags = []
564-
for elt in arg.elts:
565-
if not (isinstance(elt, ast.Constant) and isinstance(elt.value, str)):
566-
raise MalformedException(f"tag can only be List of string")
567-
tags.append(getattr(elt, value_prop_name))
568-
self.cur_inline_test.tag = tags
569-
# For non-special cases, set the attribute defined by the dictionary
570-
case _:
571-
setattr(self.cur_inline_test,
572-
property_names[arg_idx],
573-
getattr(arg, value_prop_name))
557+
if arg_idx == ConstrArgs.REPEATED:
558+
if arg.value <= 0:
559+
raise MalformedException(f"inline test: {self.arg_repeated_str} must be greater than 0")
560+
self.cur_inline_test.repeated = getattr(arg, value_prop_name)
561+
elif arg_idx == ConstrArgs.TAG_STR:
562+
tags = []
563+
for elt in arg.elts:
564+
if not (isinstance(elt, ast.Constant) and isinstance(elt.value, str)):
565+
raise MalformedException(f"tag can only be List of string")
566+
tags.append(getattr(elt, value_prop_name))
567+
self.cur_inline_test.tag = tags
568+
# For non-special cases, set the attribute defined by the dictionary
569+
else:
570+
setattr(self.cur_inline_test,
571+
property_names[arg_idx],
572+
getattr(arg, value_prop_name))
573+
574+
575+
576+
# match arg_idx:
577+
# case ConstrArgs.REPEATED:
578+
# if arg.value <= 0:
579+
# raise MalformedException(f"inline test: {self.arg_repeated_str} must be greater than 0")
580+
# self.cur_inline_test.repeated = getattr(arg, value_prop_name)
581+
# case ConstrArgs.TAG_STR:
582+
# tags = []
583+
# for elt in arg.elts:
584+
# if not (isinstance(elt, ast.Constant) and isinstance(elt.value, str)):
585+
# raise MalformedException(f"tag can only be List of string")
586+
# tags.append(getattr(elt, value_prop_name))
587+
# self.cur_inline_test.tag = tags
588+
# # For non-special cases, set the attribute defined by the dictionary
589+
# case _:
590+
# setattr(self.cur_inline_test,
591+
# property_names[arg_idx],
592+
# getattr(arg, value_prop_name))
574593
else:
575594
raise MalformedException(
576595
f"inline test: {self.class_name_str}() accepts {NUM_OF_ARGUMENTS} arguments. 'test_name' must be a string constant, 'parameterized' must be a boolean constant, 'repeated' must be a positive integer, 'tag' must be a list of string, 'timeout' must be a positive float"
@@ -1243,15 +1262,22 @@ def parse_inline_test(self, node):
12431262

12441263
for call in inline_test_calls[inline_test_call_index:]:
12451264
if isinstance(call.func, ast.Attribute):
1246-
match call.func.attr:
1247-
# "given(a, 1)"
1248-
case self.given_str:
1249-
self.parse_given(call)
1250-
inline_test_call_index += 1
1251-
# "diff_given(devices, ["cpu", "cuda"])"
1252-
case self.diff_given_str:
1253-
self.parse_diff_given(call)
1254-
inline_test_call_index += 1
1265+
if call.func.attr == self.given_str:
1266+
self.parse_given(call)
1267+
inline_test_call_index += 1
1268+
elif call.func.attr == self.diff_given_str:
1269+
self.parse_diff_given(call)
1270+
inline_test_call_index += 1
1271+
1272+
# match call.func.attr:
1273+
# # "given(a, 1)"
1274+
# case self.given_str:
1275+
# self.parse_given(call)
1276+
# inline_test_call_index += 1
1277+
# # "diff_given(devices, ["cpu", "cuda"])"
1278+
# case self.diff_given_str:
1279+
# self.parse_diff_given(call)
1280+
# inline_test_call_index += 1
12551281
else:
12561282
break
12571283

0 commit comments

Comments
 (0)