From e319a173442c9946537db712e749258b642833cc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 5 Aug 2022 22:02:07 +0200 Subject: [PATCH] octal values: simpler test for match objects From the Python 3 documentation: Match objects always have a boolean value of True. Since match() and search() return None when there is no match, you can test whether there was a match with a simple if statement: match = re.search(pattern, string) if match: process(match) --- yamllint/rules/octal_values.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yamllint/rules/octal_values.py b/yamllint/rules/octal_values.py index d531a895..7796e505 100644 --- a/yamllint/rules/octal_values.py +++ b/yamllint/rules/octal_values.py @@ -96,7 +96,7 @@ def check(conf, token, prev, next, nextnext, context): if not token.style: val = token.value if (val.isdigit() and len(val) > 1 and val[0] == '0' and - IS_OCTAL_NUMBER_PATTERN.match(val[1:]) is not None): + IS_OCTAL_NUMBER_PATTERN.match(val[1:])): yield LintProblem( token.start_mark.line + 1, token.end_mark.column + 1, 'forbidden implicit octal value "%s"' % @@ -107,7 +107,7 @@ def check(conf, token, prev, next, nextnext, context): if not token.style: val = token.value if (len(val) > 2 and val[:2] == '0o' and - IS_OCTAL_NUMBER_PATTERN.match(val[2:]) is not None): + IS_OCTAL_NUMBER_PATTERN.match(val[2:])): yield LintProblem( token.start_mark.line + 1, token.end_mark.column + 1, 'forbidden explicit octal value "%s"' %