-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
WIP: Use assign expr for match/group #8097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
||
|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the original author was already doing
if: then_stuff
else: else_stuff
to keep it from taking up too much white space. Your rewrite is actually a line longer, but only because you've gone back to the standard "suite indented on the next line" format. So that suggests this is relieving a real problem.