Apply some pyupgrade suggestions
io.open() is an alias for for the builtin open() function: https://docs.python.org/3/library/io.html#io.open If open() cannot open a file, an OSError is raised: https://docs.python.org/3/library/functions.html#open EnvironmentError is kept for compatibility with previous versions; starting from Python 3.3, it is an alias of OSError: https://docs.python.org/3/library/exceptions.html#EnvironmentError Directly yield from an iterable instead of iterating to yield items.
This commit is contained in:
committed by
Adrien Vergé
parent
5b21a3d9ea
commit
5ac3ed4490
@@ -13,7 +13,6 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from io import open
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from tests.common import RuleTestCase
|
from tests.common import RuleTestCase
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -213,9 +212,9 @@ def run(argv=None):
|
|||||||
for file in find_files_recursively(args.files, conf):
|
for file in find_files_recursively(args.files, conf):
|
||||||
filepath = file[2:] if file.startswith('./') else file
|
filepath = file[2:] if file.startswith('./') else file
|
||||||
try:
|
try:
|
||||||
with io.open(file, newline='') as f:
|
with open(file, newline='') as f:
|
||||||
problems = linter.run(f, conf, filepath)
|
problems = linter.run(f, conf, filepath)
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
prob_level = show_problems(problems, file, args_format=args.format,
|
prob_level = show_problems(problems, file, args_format=args.format,
|
||||||
@@ -226,7 +225,7 @@ def run(argv=None):
|
|||||||
if args.stdin:
|
if args.stdin:
|
||||||
try:
|
try:
|
||||||
problems = linter.run(sys.stdin, conf, '')
|
problems = linter.run(sys.stdin, conf, '')
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
prob_level = show_problems(problems, 'stdin', args_format=args.format,
|
prob_level = show_problems(problems, 'stdin', args_format=args.format,
|
||||||
|
|||||||
@@ -132,8 +132,7 @@ def token_or_comment_generator(buffer):
|
|||||||
|
|
||||||
yield Token(curr.start_mark.line + 1, curr, prev, next, nextnext)
|
yield Token(curr.start_mark.line + 1, curr, prev, next, nextnext)
|
||||||
|
|
||||||
for comment in comments_between_tokens(curr, next):
|
yield from comments_between_tokens(curr, next)
|
||||||
yield comment
|
|
||||||
|
|
||||||
prev = curr
|
prev = curr
|
||||||
curr = next
|
curr = next
|
||||||
|
|||||||
@@ -352,8 +352,7 @@ def _check(conf, token, prev, next, nextnext, context):
|
|||||||
|
|
||||||
if (isinstance(token, yaml.ScalarToken) and
|
if (isinstance(token, yaml.ScalarToken) and
|
||||||
conf['check-multi-line-strings']):
|
conf['check-multi-line-strings']):
|
||||||
for problem in check_scalar_indentation(conf, token, context):
|
yield from check_scalar_indentation(conf, token, context)
|
||||||
yield problem
|
|
||||||
|
|
||||||
# Step 2.a:
|
# Step 2.a:
|
||||||
|
|
||||||
@@ -581,8 +580,7 @@ def _check(conf, token, prev, next, nextnext, context):
|
|||||||
|
|
||||||
def check(conf, token, prev, next, nextnext, context):
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
try:
|
try:
|
||||||
for problem in _check(conf, token, prev, next, nextnext, context):
|
yield from _check(conf, token, prev, next, nextnext, context)
|
||||||
yield problem
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
yield LintProblem(token.start_mark.line + 1,
|
yield LintProblem(token.start_mark.line + 1,
|
||||||
token.start_mark.column + 1,
|
token.start_mark.column + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user