diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e5d893..0ef1664 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace # Replaces or checks mixed line ending @@ -19,7 +19,7 @@ repos: - id: check-yaml files: .*\.(yaml|yml)$ - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.7.10 hooks: - id: bandit args: ['-x', 'tests'] @@ -34,7 +34,7 @@ repos: files: '^.*\.py$' exclude: '^(doc|releasenotes|tools)/.*$' - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.12.1 hooks: - id: mypy exclude: | @@ -43,3 +43,8 @@ repos: | doc/.* | releasenotes/.* ) + - 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 ed4be64..cc95df1 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2020 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/oslo_context/context.py b/oslo_context/context.py index 1f5add6..92f9b59 100644 --- a/oslo_context/context.py +++ b/oslo_context/context.py @@ -170,7 +170,7 @@ _renamed_kwarg = functools.partial(renames.renamed_kwarg, replace=True) -class RequestContext(object): +class RequestContext: """Helper class to represent useful information about a request context. diff --git a/oslo_context/fixture.py b/oslo_context/fixture.py index 715f43a..b5d61a9 100644 --- a/oslo_context/fixture.py +++ b/oslo_context/fixture.py @@ -25,7 +25,7 @@ class ClearRequestContext(fixtures.Fixture): """ def setUp(self) -> None: - super(ClearRequestContext, self).setUp() + super().setUp() # we need to clear both when we start, and when we finish, # because there might be other tests running that don't handle # this correctly. diff --git a/oslo_context/tests/test_context.py b/oslo_context/tests/test_context.py index 795f282..c837b3f 100644 --- a/oslo_context/tests/test_context.py +++ b/oslo_context/tests/test_context.py @@ -1,4 +1,3 @@ -# -*- encoding: utf-8 -*- # Copyright 2011 OpenStack Foundation. # All Rights Reserved. # @@ -32,12 +31,12 @@ def generate_id(name): class WarningsFixture(fixtures.Fixture): def __init__(self, action="always", category=DeprecationWarning): - super(WarningsFixture, self).__init__() + super().__init__() self.action = action self.category = category def setUp(self): - super(WarningsFixture, self).setUp() + super().setUp() self._w = warnings.catch_warnings(record=True) self.log = self._w.__enter__() self.addCleanup(self._w.__exit__) @@ -50,7 +49,7 @@ class WarningsFixture(fixtures.Fixture): return self.log[item] -class Object(object): +class Object: pass @@ -63,11 +62,11 @@ class TestContext(context.RequestContext): FROM_DICT_EXTRA_KEYS = ['auth_token_info'] def __init__(self, auth_token_info=None, **kwargs): - super(TestContext, self).__init__(**kwargs) + super().__init__(**kwargs) self.auth_token_info = auth_token_info def to_dict(self): - d = super(TestContext, self).to_dict() + d = super().to_dict() d['auth_token_info'] = self.auth_token_info return d @@ -75,7 +74,7 @@ class TestContext(context.RequestContext): class ContextTest(test_base.BaseTestCase): def setUp(self): - super(ContextTest, self).setUp() + super().setUp() self.warnings = self.useFixture(WarningsFixture()) self.useFixture(fixture.ClearRequestContext()) @@ -404,7 +403,7 @@ class ContextTest(test_base.BaseTestCase): def test_values(self): auth_token = "token1" # test unicode support - user_name = u"John Gāo" + user_name = "John Gāo" user_id = generate_id(user_name) project_name = 'tenant1' project_id = generate_id(project_name) @@ -485,8 +484,8 @@ class ContextTest(test_base.BaseTestCase): self.assertEqual(show_deleted, d['show_deleted']) self.assertEqual(request_id, d['request_id']) self.assertEqual(resource_uuid, d['resource_uuid']) - user_identity = "%s %s %s %s %s" % (user_id, project_id, domain_id, - user_domain_id, project_domain_id) + user_identity = "{} {} {} {} {}".format( + user_id, project_id, domain_id, user_domain_id, project_domain_id) self.assertEqual(user_identity, d['user_identity']) self.assertEqual([], d['roles']) diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index da43afa..570ddf1 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2020 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License");