WIP: Use assign expr for match/group by vstinner · Pull Request #8097 · python/cpython

Expand Up @@ -224,8 +224,7 @@ def _parse_makefile(filename, vars=None): for line in lines: if line.startswith('#') or line.strip() == '': continue m = _variable_rx.match(line) if m: if (m := _variable_rx.match(line)): n, v = m.group(1, 2) v = v.strip() # `$$' is a literal `$' in make Expand Down Expand Up @@ -449,18 +448,15 @@ def parse_config_h(fp, vars=None): line = fp.readline() if not line: break m = define_rx.match(line) if m: if (m := define_rx.match(line)): n, v = m.group(1, 2) try: v = int(v) except ValueError: pass vars[n] = v else: m = undef_rx.match(line) if m: vars[m.group(1)] = 0 elif (m := undef_rx.match(line)): vars[m.group(1)] = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like an improvement to me, because otherwise I smell a bug ... what if it went down the else case, but then the 2nd if wasn't true? Is that case handled?

Now I still smell the potential bug, but with an elif, it is a lot easier to explain what I'm worried about, as a simple "What if neither pattern matches?"

return vars

Expand Down Expand Up @@ -659,8 +655,7 @@ def get_platform(): osname = "cygwin" import re rel_re = re.compile(r'[\d.]+') m = rel_re.match(release) if m: if (m := rel_re.match(release)): release = m.group() elif osname[:6] == "darwin": import _osx_support Expand Down