Skip to content

Commit

Permalink
octal values: simpler test for match objects
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
DimitriPapadopoulos authored and adrienverge committed Aug 6, 2022
1 parent 6b6fdba commit e319a17
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions yamllint/rules/octal_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"' %
Expand All @@ -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"' %
Expand Down

0 comments on commit e319a17

Please sign in to comment.