Remove use of Python walrus (:=) operator to enable running on Python 3.7

should fix #6
This commit is contained in:
Janne Hellsten 2021-10-13 13:09:27 +03:00
parent 583f2bdd13
commit b1a62b91b1
3 changed files with 8 additions and 4 deletions

View File

@ -41,7 +41,8 @@ def parse_tuple(s: str) -> Tuple[int, int]:
'4x2' returns (4,2)
'0,1' returns (0,1)
'''
if m := re.match(r'^(\d+)[x,](\d+)$', s):
m = re.match(r'^(\d+)[x,](\d+)$', s)
if m:
return (int(m.group(1)), int(m.group(2)))
raise ValueError(f'cannot parse tuple {s}')

View File

@ -31,7 +31,8 @@ def parse_range(s: Union[str, List]) -> List[int]:
ranges = []
range_re = re.compile(r'^(\d+)-(\d+)$')
for p in s.split(','):
if m := range_re.match(p):
m = range_re.match(p)
if m:
ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
else:
ranges.append(int(p))

View File

@ -100,7 +100,8 @@ def parse_range(s: Union[str, List[int]]) -> List[int]:
ranges = []
range_re = re.compile(r'^(\d+)-(\d+)$')
for p in s.split(','):
if m := range_re.match(p):
m = range_re.match(p)
if m:
ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
else:
ranges.append(int(p))
@ -116,7 +117,8 @@ def parse_tuple(s: Union[str, Tuple[int,int]]) -> Tuple[int, int]:
'0,1' returns (0,1)
'''
if isinstance(s, tuple): return s
if m := re.match(r'^(\d+)[x,](\d+)$', s):
m = re.match(r'^(\d+)[x,](\d+)$', s)
if m:
return (int(m.group(1)), int(m.group(2)))
raise ValueError(f'cannot parse tuple {s}')