From f6592d2e421ff9256746fd35439cc2d64309b9d5 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 24 Oct 2024 23:08:20 +0900 Subject: [PATCH] Run pyupgrade to clean up Python 2 syntaxes Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I03025adae5df96058ad3364c9ac17e899a600f7b --- .pre-commit-config.yaml | 5 +++++ doc/source/conf.py | 1 - whereto/__init__.py | 2 -- whereto/app.py | 7 ++----- whereto/parser.py | 2 -- whereto/rules.py | 8 +++----- whereto/tests/base.py | 2 -- whereto/tests/test_app.py | 4 +--- whereto/tests/test_parser.py | 2 -- whereto/tests/test_rules.py | 6 ++---- 10 files changed, 13 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d174849..31d9d64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,3 +23,8 @@ repos: hooks: - id: hacking additional_dependencies: [] + - repo: https://github.com/asottile/pyupgrade + rev: v3.18.0 + hooks: + - id: pyupgrade + args: [--py3-only] diff --git a/doc/source/conf.py b/doc/source/conf.py index d49c70d..a8a4de6 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/whereto/__init__.py b/whereto/__init__.py index 134dc68..fd0f7b8 100644 --- a/whereto/__init__.py +++ b/whereto/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at diff --git a/whereto/app.py b/whereto/app.py index 387e602..dd76a68 100644 --- a/whereto/app.py +++ b/whereto/app.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright 2010-2011 OpenStack Foundation # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # @@ -16,7 +14,6 @@ # under the License. import argparse -import io import logging import sys @@ -188,12 +185,12 @@ def main(): ruleset = rules.RuleSet() log.debug('reading redirects from {}'.format(args.htaccess_file)) - with io.open(args.htaccess_file, 'r', encoding='utf-8') as f: + with open(args.htaccess_file, encoding='utf-8') as f: for linenum, params in parser.parse_rules(f): ruleset.add(linenum, *params) log.debug('reading tests from {}'.format(args.htaccess_file)) - with io.open(args.test_file, 'r', encoding='utf-8') as f: + with open(args.test_file, encoding='utf-8') as f: tests = [ (linenum,) + tuple(params) for linenum, params in parser.parse_tests(f) diff --git a/whereto/parser.py b/whereto/parser.py index 6ce9ab0..0600cc0 100644 --- a/whereto/parser.py +++ b/whereto/parser.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright 2010-2011 OpenStack Foundation # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # diff --git a/whereto/rules.py b/whereto/rules.py index d70e671..0d09002 100644 --- a/whereto/rules.py +++ b/whereto/rules.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright 2010-2011 OpenStack Foundation # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # @@ -23,7 +21,7 @@ import re LOG = logging.getLogger() -class Rule(object): +class Rule: "Base class for rules." def __init__(self, linenum, *params): @@ -74,7 +72,7 @@ class RedirectMatch(Rule): _group_subst = re.compile(r'(?