From 6bda7308644a65860f8e834a6be7fa3e267d9d8d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 2 Dec 2019 19:48:45 -0500 Subject: Polishing from a lightning talk --- coverage/misc.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/coverage/misc.py b/coverage/misc.py index fc2a5c98..2f3bcac6 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -273,10 +273,10 @@ def substitute_variables(text, variables): dollar_pattern = r"""(?x) # Use extended regex syntax \$ # A dollar sign, (?: # then - (?P\w+) | # a plain word, - (?P\$) | # or a dollar sign. - { # or a {-wrapped - (?P\w+) # word, + (?P\$) | # a dollar sign, or + (?P\w+) | # a plain word, or + { # a {-wrapped + (?P\w+) # word, (?: (?P\?) | # with a strict marker -(?P[^}]*) # or a default value @@ -285,19 +285,19 @@ def substitute_variables(text, variables): ) """ - def dollar_replace(m): + def dollar_replace(match): """Called for each $replacement.""" # Only one of the groups will have matched, just get its text. - word = next(w for w in m.group('w1', 'w2', 'dollar') if w) + word = next(g for g in match.group('dollar', 'word1', 'word2') if g) if word == "$": return "$" elif word in variables: return variables[word] - elif m.group('strict'): + elif match.group('strict'): msg = "Variable {} is undefined: {!r}".format(word, text) raise CoverageException(msg) else: - return m.group('defval') + return match.group('defval') text = re.sub(dollar_pattern, dollar_replace, text) return text -- cgit v1.2.1