Merge "Run pyupgrade to clean up Python 2 syntaxes"

This commit is contained in:
Zuul 2024-12-16 12:47:11 +00:00 committed by Gerrit Code Review
commit 95fab98d39
10 changed files with 13 additions and 26 deletions

View File

@ -23,3 +23,8 @@ repos:
hooks: hooks:
- id: hacking - id: hacking
additional_dependencies: [] additional_dependencies: []
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
args: [--py3-only]

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation # Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
# #
@ -16,7 +14,6 @@
# under the License. # under the License.
import argparse import argparse
import io
import logging import logging
import sys import sys
@ -188,12 +185,12 @@ def main():
ruleset = rules.RuleSet() ruleset = rules.RuleSet()
log.debug('reading redirects from {}'.format(args.htaccess_file)) 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): for linenum, params in parser.parse_rules(f):
ruleset.add(linenum, *params) ruleset.add(linenum, *params)
log.debug('reading tests from {}'.format(args.htaccess_file)) 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 = [ tests = [
(linenum,) + tuple(params) (linenum,) + tuple(params)
for linenum, params in parser.parse_tests(f) for linenum, params in parser.parse_tests(f)

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation # Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
# #

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation # Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
# #
@ -23,7 +21,7 @@ import re
LOG = logging.getLogger() LOG = logging.getLogger()
class Rule(object): class Rule:
"Base class for rules." "Base class for rules."
def __init__(self, linenum, *params): def __init__(self, linenum, *params):
@ -74,7 +72,7 @@ class RedirectMatch(Rule):
_group_subst = re.compile(r'(?<!\\)\$([0-9])') _group_subst = re.compile(r'(?<!\\)\$([0-9])')
def __init__(self, linenum, *params): def __init__(self, linenum, *params):
super(RedirectMatch, self).__init__(linenum, *params) super().__init__(linenum, *params)
self.regex = pcre.compile(self.pattern) self.regex = pcre.compile(self.pattern)
if self.target: if self.target:
self.target_repl = self._get_target_repl() self.target_repl = self._get_target_repl()
@ -96,7 +94,7 @@ class RedirectMatch(Rule):
return None return None
class RuleSet(object): class RuleSet:
"An ordered collection of rules." "An ordered collection of rules."
_factories = { _factories = {

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation # Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
# #

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
@ -20,7 +18,7 @@ from whereto.tests import base
class TestProcessTests(base.TestCase): class TestProcessTests(base.TestCase):
def setUp(self): def setUp(self):
super(TestProcessTests, self).setUp() super().setUp()
self.ruleset = rules.RuleSet() self.ruleset = rules.RuleSet()
def test_zero_matches(self): def test_zero_matches(self):

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
@ -19,7 +17,7 @@ from whereto.tests import base
class TestRedirect(base.TestCase): class TestRedirect(base.TestCase):
def setUp(self): def setUp(self):
super(TestRedirect, self).setUp() super().setUp()
self.rule = rules.Redirect( self.rule = rules.Redirect(
1, 1,
'redirect', '301', '/path', '/new/path', 'redirect', '301', '/path', '/new/path',
@ -210,7 +208,7 @@ class TestRedirectMatch(base.TestCase):
class TestRuleSet(base.TestCase): class TestRuleSet(base.TestCase):
def setUp(self): def setUp(self):
super(TestRuleSet, self).setUp() super().setUp()
self.ruleset = rules.RuleSet() self.ruleset = rules.RuleSet()
def test_add_redirect(self): def test_add_redirect(self):