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. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place os_api_ref Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I482aa3eb40d7c8cefaba9ea9df5b9d1dcd3827c1
This commit is contained in:
@@ -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]
|
||||||
|
@@ -86,7 +86,7 @@ def ordered_load(
|
|||||||
# numbers) as strings. So that microversion specification of 2.20
|
# numbers) as strings. So that microversion specification of 2.20
|
||||||
# and 2.2 don't get confused.
|
# and 2.2 don't get confused.
|
||||||
OrderedLoader.add_constructor(
|
OrderedLoader.add_constructor(
|
||||||
u'tag:yaml.org,2002:float',
|
'tag:yaml.org,2002:float',
|
||||||
yaml.constructor.SafeConstructor.construct_yaml_str)
|
yaml.constructor.SafeConstructor.construct_yaml_str)
|
||||||
|
|
||||||
return yaml.load(stream, OrderedLoader)
|
return yaml.load(stream, OrderedLoader)
|
||||||
@@ -198,7 +198,7 @@ class RestMethodDirective(rst.Directive):
|
|||||||
# they are still unlikely to occurr and it is way shorter
|
# they are still unlikely to occurr and it is way shorter
|
||||||
# than stronger SHAs.
|
# than stronger SHAs.
|
||||||
node_hash = hashlib.sha1(str(node).encode('utf-8')).hexdigest()
|
node_hash = hashlib.sha1(str(node).encode('utf-8')).hexdigest()
|
||||||
temp_target = "%s-%s-selector" % (node['target'], node_hash)
|
temp_target = "{}-{}-selector".format(node['target'], node_hash)
|
||||||
target = nodes.target(ids=[temp_target])
|
target = nodes.target(ids=[temp_target])
|
||||||
self.state.add_target(temp_target, '', target, lineno)
|
self.state.add_target(temp_target, '', target, lineno)
|
||||||
section += node
|
section += node
|
||||||
@@ -222,9 +222,9 @@ class RestParametersDirective(Table):
|
|||||||
|
|
||||||
lookup = {}
|
lookup = {}
|
||||||
try:
|
try:
|
||||||
with open(fpath, 'r') as stream:
|
with open(fpath) as stream:
|
||||||
lookup = ordered_load(stream)
|
lookup = ordered_load(stream)
|
||||||
except IOError:
|
except OSError:
|
||||||
LOG.warning("Parameters file not found, %s", fpath,
|
LOG.warning("Parameters file not found, %s", fpath,
|
||||||
location=(self.env.docname, None))
|
location=(self.env.docname, None))
|
||||||
return
|
return
|
||||||
@@ -595,10 +595,10 @@ Microversions
|
|||||||
def build_mv_item(major, micro, releases):
|
def build_mv_item(major, micro, releases):
|
||||||
version = "%d.%d" % (major, micro)
|
version = "%d.%d" % (major, micro)
|
||||||
if version in releases:
|
if version in releases:
|
||||||
return '<option value="%s">%s - %s</option>' % (
|
return '<option value="{}">{} - {}</option>'.format(
|
||||||
version, version, releases[version].capitalize())
|
version, version, releases[version].capitalize())
|
||||||
else:
|
else:
|
||||||
return '<option value="%s">%s</option>' % (version, version)
|
return '<option value="{}">{}</option>'.format(version, version)
|
||||||
|
|
||||||
|
|
||||||
def resolve_rest_references(app, doctree):
|
def resolve_rest_references(app, doctree):
|
||||||
|
@@ -41,7 +41,7 @@ class HTTPResponseCodeDirective(Table):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.CODES.update(responses)
|
self.CODES.update(responses)
|
||||||
super(HTTPResponseCodeDirective, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def _load_status_file(self, fpath):
|
def _load_status_file(self, fpath):
|
||||||
global HTTP_YAML_CACHE
|
global HTTP_YAML_CACHE
|
||||||
@@ -50,9 +50,9 @@ class HTTPResponseCodeDirective(Table):
|
|||||||
|
|
||||||
# LOG.info("Fpath: %s" % fpath)
|
# LOG.info("Fpath: %s" % fpath)
|
||||||
try:
|
try:
|
||||||
with open(fpath, 'r') as stream:
|
with open(fpath) as stream:
|
||||||
lookup = yaml.safe_load(stream)
|
lookup = yaml.safe_load(stream)
|
||||||
except IOError:
|
except OSError:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
"Parameters file %s not found" % fpath,
|
"Parameters file %s not found" % fpath,
|
||||||
(self.env.docname, None))
|
(self.env.docname, None))
|
||||||
@@ -92,7 +92,8 @@ class HTTPResponseCodeDirective(Table):
|
|||||||
|
|
||||||
if status_type not in self.status_types:
|
if status_type not in self.status_types:
|
||||||
error = self.state_machine.reporter.error(
|
error = self.state_machine.reporter.error(
|
||||||
'Type %s is not one of %s' % (status_type, self.status_types),
|
'Type {} is not one of {}'.format(
|
||||||
|
status_type, self.status_types),
|
||||||
nodes.literal_block(self.block_text, self.block_text),
|
nodes.literal_block(self.block_text, self.block_text),
|
||||||
line=self.lineno)
|
line=self.lineno)
|
||||||
return [error]
|
return [error]
|
||||||
@@ -142,7 +143,7 @@ class HTTPResponseCodeDirective(Table):
|
|||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
"Could not find %s for code %s" % (reason, code))
|
"Could not find {} for code {}".format(reason, code))
|
||||||
new_content.append(
|
new_content.append(
|
||||||
(code, self.status_defs[code]['default']))
|
(code, self.status_defs[code]['default']))
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ class OutputStreamCapture(fixtures.Fixture):
|
|||||||
tests.
|
tests.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(OutputStreamCapture, self).setUp()
|
super().setUp()
|
||||||
if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
|
if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
|
||||||
self.out = self.useFixture(fixtures.StringStream('stdout'))
|
self.out = self.useFixture(fixtures.StringStream('stdout'))
|
||||||
self.useFixture(
|
self.useFixture(
|
||||||
@@ -93,7 +93,7 @@ class Timeout(fixtures.Fixture):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, timeout, scaling=1):
|
def __init__(self, timeout, scaling=1):
|
||||||
super(Timeout, self).__init__()
|
super().__init__()
|
||||||
try:
|
try:
|
||||||
self.test_timeout = int(timeout)
|
self.test_timeout = int(timeout)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -105,7 +105,7 @@ class Timeout(fixtures.Fixture):
|
|||||||
raise ValueError('scaling value must be >= 1')
|
raise ValueError('scaling value must be >= 1')
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(Timeout, self).setUp()
|
super().setUp()
|
||||||
if self.test_timeout > 0:
|
if self.test_timeout > 0:
|
||||||
self.useFixture(fixtures.Timeout(self.test_timeout, gentle=True))
|
self.useFixture(fixtures.Timeout(self.test_timeout, gentle=True))
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ class TestCase(testtools.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Run before each test method to initialize test environment."""
|
"""Run before each test method to initialize test environment."""
|
||||||
super(TestCase, self).setUp()
|
super().setUp()
|
||||||
self.useFixture(Timeout(
|
self.useFixture(Timeout(
|
||||||
os.environ.get('OS_TEST_TIMEOUT', 0)))
|
os.environ.get('OS_TEST_TIMEOUT', 0)))
|
||||||
self.useFixture(OutputStreamCapture())
|
self.useFixture(OutputStreamCapture())
|
||||||
|
@@ -31,7 +31,7 @@ class TestBasicExample(base.TestCase):
|
|||||||
|
|
||||||
@base.with_app(buildername='html', srcdir=base.example_dir('basic'))
|
@base.with_app(buildername='html', srcdir=base.example_dir('basic'))
|
||||||
def setUp(self, app, status, warning):
|
def setUp(self, app, status, warning):
|
||||||
super(TestBasicExample, self).setUp()
|
super().setUp()
|
||||||
self.app = app
|
self.app = app
|
||||||
self.status = status
|
self.status = status
|
||||||
self.warning = warning
|
self.warning = warning
|
||||||
|
@@ -32,7 +32,7 @@ class TestMicroversions(base.TestCase):
|
|||||||
@base.with_app(buildername='html',
|
@base.with_app(buildername='html',
|
||||||
srcdir=base.example_dir('microversions'))
|
srcdir=base.example_dir('microversions'))
|
||||||
def setUp(self, app, status, warning):
|
def setUp(self, app, status, warning):
|
||||||
super(TestMicroversions, self).setUp()
|
super().setUp()
|
||||||
self.app = app
|
self.app = app
|
||||||
self.app.build()
|
self.app.build()
|
||||||
self.status = status.getvalue()
|
self.status = status.getvalue()
|
||||||
|
@@ -33,7 +33,7 @@ class TestWarnings(base.TestCase):
|
|||||||
|
|
||||||
@base.with_app(buildername='html', srcdir=base.example_dir('warnings'))
|
@base.with_app(buildername='html', srcdir=base.example_dir('warnings'))
|
||||||
def setUp(self, app, status, warning):
|
def setUp(self, app, status, warning):
|
||||||
super(TestWarnings, self).setUp()
|
super().setUp()
|
||||||
self.app = app
|
self.app = app
|
||||||
self.app.build()
|
self.app.build()
|
||||||
self.status = status.getvalue()
|
self.status = status.getvalue()
|
||||||
|
Reference in New Issue
Block a user