Skip to content

Commit e319a17

Browse files
DimitriPapadopoulosadrienverge
authored andcommitted
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)
1 parent 6b6fdba commit e319a17

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

yamllint/rules/octal_values.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def check(conf, token, prev, next, nextnext, context):
9696
if not token.style:
9797
val = token.value
9898
if (val.isdigit() and len(val) > 1 and val[0] == '0' and
99-
IS_OCTAL_NUMBER_PATTERN.match(val[1:]) is not None):
99+
IS_OCTAL_NUMBER_PATTERN.match(val[1:])):
100100
yield LintProblem(
101101
token.start_mark.line + 1, token.end_mark.column + 1,
102102
'forbidden implicit octal value "%s"' %
@@ -107,7 +107,7 @@ def check(conf, token, prev, next, nextnext, context):
107107
if not token.style:
108108
val = token.value
109109
if (len(val) > 2 and val[:2] == '0o' and
110-
IS_OCTAL_NUMBER_PATTERN.match(val[2:]) is not None):
110+
IS_OCTAL_NUMBER_PATTERN.match(val[2:])):
111111
yield LintProblem(
112112
token.start_mark.line + 1, token.end_mark.column + 1,
113113
'forbidden explicit octal value "%s"' %

0 commit comments

Comments
 (0)