diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-02 19:48:45 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-02 19:48:45 -0500 |
commit | 6bda7308644a65860f8e834a6be7fa3e267d9d8d (patch) | |
tree | 28a555d097a12a7c17c8b0be67ece3989bda1e69 | |
parent | 7f68a21d4ba330cac84afadfbadb4f1ab750637e (diff) | |
download | python-coveragepy-git-6bda7308644a65860f8e834a6be7fa3e267d9d8d.tar.gz |
Polishing from a lightning talk
-rw-r--r-- | coverage/misc.py | 16 |
1 files 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<w1>\w+) | # a plain word, - (?P<dollar>\$) | # or a dollar sign. - { # or a {-wrapped - (?P<w2>\w+) # word, + (?P<dollar>\$) | # a dollar sign, or + (?P<word1>\w+) | # a plain word, or + { # a {-wrapped + (?P<word2>\w+) # word, (?: (?P<strict>\?) | # with a strict marker -(?P<defval>[^}]*) # 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 |