From 0827580347174b2a72fad03ffa80bb7ee98d7c30 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 10 Feb 2025 22:15:53 +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. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place osprofiler Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: Id5028ca9fbb04d6dad9729bc13fe71ab8b391138 --- .pre-commit-config.yaml | 5 +++++ doc/source/conf.py | 1 - osprofiler/_utils.py | 5 +++-- osprofiler/cmd/commands.py | 8 ++++---- osprofiler/cmd/shell.py | 2 +- osprofiler/drivers/base.py | 10 +++++----- osprofiler/drivers/elasticsearch_driver.py | 12 ++++++------ osprofiler/drivers/jaeger.py | 6 +++--- osprofiler/drivers/loginsight.py | 17 +++++++++-------- osprofiler/drivers/messaging.py | 6 +++--- osprofiler/drivers/mongodb.py | 4 ++-- osprofiler/drivers/otlp.py | 6 +++--- osprofiler/drivers/redis_driver.py | 15 +++++++-------- osprofiler/drivers/sqlalchemy_driver.py | 4 ++-- osprofiler/profiler.py | 6 +++--- osprofiler/tests/functional/test_driver.py | 4 ++-- osprofiler/tests/test.py | 2 +- osprofiler/tests/unit/cmd/test_shell.py | 6 +++--- osprofiler/tests/unit/doc/test_specs.py | 4 ++-- .../tests/unit/drivers/test_elasticsearch.py | 2 +- osprofiler/tests/unit/drivers/test_jaeger.py | 2 +- .../tests/unit/drivers/test_loginsight.py | 4 ++-- osprofiler/tests/unit/drivers/test_mongodb.py | 2 +- osprofiler/tests/unit/drivers/test_otlp.py | 2 +- .../tests/unit/drivers/test_redis_driver.py | 2 +- osprofiler/tests/unit/test_notifier.py | 2 +- osprofiler/tests/unit/test_opts.py | 2 +- osprofiler/tests/unit/test_profiler.py | 4 ++-- osprofiler/tests/unit/test_utils.py | 2 +- osprofiler/tests/unit/test_web.py | 6 +++--- osprofiler/web.py | 2 +- releasenotes/source/conf.py | 1 - tools/patch_tox_venv.py | 2 +- 33 files changed, 81 insertions(+), 77 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d85331c..fdf61cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,8 @@ repos: rev: 1.7.10 hooks: - id: bandit + - 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 a3e62f1..869242a 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"); you may diff --git a/osprofiler/_utils.py b/osprofiler/_utils.py index 644829c..b4b282b 100644 --- a/osprofiler/_utils.py +++ b/osprofiler/_utils.py @@ -31,7 +31,8 @@ def split(text, strip=True): if isinstance(text, (tuple, list)): return text if not isinstance(text, str): - raise TypeError("Unknown how to split '%s': %s" % (text, type(text))) + raise TypeError( + "Unknown how to split '{}': {}".format(text, type(text))) if strip: return [t.strip() for t in text.split(",") if t.strip()] else: @@ -145,7 +146,7 @@ def import_modules_from_package(package): if filename.startswith("__") or not filename.endswith(".py"): continue new_package = ".".join(root.split(os.sep)).split("....")[1] - module_name = "%s.%s" % (new_package, filename[:-3]) + module_name = "{}.{}".format(new_package, filename[:-3]) __import__(module_name) diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py index ab80c9e..8ee0bbc 100644 --- a/osprofiler/cmd/commands.py +++ b/osprofiler/cmd/commands.py @@ -25,7 +25,7 @@ from osprofiler.drivers import base from osprofiler import exc -class BaseCommand(object): +class BaseCommand: group_name = None @@ -136,12 +136,12 @@ class TraceCommands(BaseCommand): if name == "wsgi": req = info["meta.raw_payload.wsgi-start"]["info"]["request"] - label = "%s\\n%s %s.." % (label, req["method"], - req["path"][:30]) + label = "{}\\n{} {}..".format(label, req["method"], + req["path"][:30]) elif name == "rpc" or name == "driver": raw = info["meta.raw_payload.%s-start" % name] fn_name = raw["info"]["function"]["name"] - label = "%s\\n%s" % (label, fn_name.split(".")[-1]) + label = "{}\\n{}".format(label, fn_name.split(".")[-1]) node_id = str(next_id[0]) next_id[0] += 1 diff --git a/osprofiler/cmd/shell.py b/osprofiler/cmd/shell.py index 6288659..11605e1 100644 --- a/osprofiler/cmd/shell.py +++ b/osprofiler/cmd/shell.py @@ -30,7 +30,7 @@ from osprofiler import exc from osprofiler import opts -class OSProfilerShell(object): +class OSProfilerShell: def __init__(self, argv): args = self._get_base_parser().parse_args(argv) diff --git a/osprofiler/drivers/base.py b/osprofiler/drivers/base.py index f717d69..0f28f88 100644 --- a/osprofiler/drivers/base.py +++ b/osprofiler/drivers/base.py @@ -49,7 +49,7 @@ def get_driver(connection_string, *args, **kwargs): "%s" % connection_string) -class Driver(object): +class Driver: """Base Driver class. This class provides protected common methods that @@ -94,7 +94,7 @@ class Driver(object): With parent_id and trace_id it's quite simple to build tree of trace elements, which simplify analyze of trace. """ - raise NotImplementedError("{0}: This method is either not supported " + raise NotImplementedError("{}: This method is either not supported " "or has to be overridden".format( self.get_name())) @@ -103,7 +103,7 @@ class Driver(object): :param base_id: Base id of trace elements. """ - raise NotImplementedError("{0}: This method is either not supported " + raise NotImplementedError("{}: This method is either not supported " "or has to be overridden".format( self.get_name())) @@ -120,7 +120,7 @@ class Driver(object): :returns: List of traces, where each trace is a dictionary containing at least `base_id` and `timestamp`. """ - raise NotImplementedError("{0}: This method is either not supported " + raise NotImplementedError("{}: This method is either not supported " "or has to be overridden".format( self.get_name())) @@ -130,7 +130,7 @@ class Driver(object): :return List of traces, where each trace is a dictionary containing `base_id` and `timestamp`. """ - raise NotImplementedError("{0}: This method is either not supported " + raise NotImplementedError("{}: This method is either not supported " "or has to be overridden".format( self.get_name())) diff --git a/osprofiler/drivers/elasticsearch_driver.py b/osprofiler/drivers/elasticsearch_driver.py index da9be17..3b38409 100644 --- a/osprofiler/drivers/elasticsearch_driver.py +++ b/osprofiler/drivers/elasticsearch_driver.py @@ -27,12 +27,12 @@ class ElasticsearchDriver(base.Driver): **kwargs): """Elasticsearch driver for OSProfiler.""" - super(ElasticsearchDriver, self).__init__(connection_str, - project=project, - service=service, - host=host, - conf=conf, - **kwargs) + super().__init__(connection_str, + project=project, + service=service, + host=host, + conf=conf, + **kwargs) try: from elasticsearch import Elasticsearch except ImportError: diff --git a/osprofiler/drivers/jaeger.py b/osprofiler/drivers/jaeger.py index 67e75c3..29e7a61 100644 --- a/osprofiler/drivers/jaeger.py +++ b/osprofiler/drivers/jaeger.py @@ -31,9 +31,9 @@ class Jaeger(base.Driver): conf=cfg.CONF, **kwargs): """Jaeger driver for OSProfiler.""" - super(Jaeger, self).__init__(connection_str, project=project, - service=service, host=host, - conf=conf, **kwargs) + super().__init__(connection_str, project=project, + service=service, host=host, + conf=conf, **kwargs) try: import jaeger_client self.jaeger_client = jaeger_client diff --git a/osprofiler/drivers/loginsight.py b/osprofiler/drivers/loginsight.py index 31fe1ee..1114d36 100644 --- a/osprofiler/drivers/loginsight.py +++ b/osprofiler/drivers/loginsight.py @@ -49,10 +49,10 @@ class LogInsightDriver(base.Driver): def __init__( self, connection_str, project=None, service=None, host=None, **kwargs): - super(LogInsightDriver, self).__init__(connection_str, - project=project, - service=service, - host=host) + super().__init__(connection_str, + project=project, + service=service, + host=host) parsed_connection = urlparse.urlparse(connection_str) try: @@ -126,7 +126,7 @@ class LogInsightDriver(base.Driver): return self._parse_results() -class LogInsightClient(object): +class LogInsightClient: """A minimal Log Insight client.""" LI_OSPROFILER_AGENT_ID = "F52D775B-6017-4787-8C8A-F21AE0AEC057" @@ -174,7 +174,7 @@ class LogInsightClient(object): def _send_request( self, method, scheme, path, headers=None, body=None, params=None): - url = "%s/%s" % (self._build_base_url(scheme), path) + url = "{}/{}".format(self._build_base_url(scheme), path) headers = headers or {} headers["content-type"] = "application/json" @@ -239,10 +239,11 @@ class LogInsightClient(object): # the operator is "CONTAINS". constraints = [] for field, value in params.items(): - constraints.append("%s/CONTAINS+%s" % (field, value)) + constraints.append("{}/CONTAINS+{}".format(field, value)) constraints.append("timestamp/GT+0") - path = "%s/%s" % (self.QUERY_EVENTS_BASE_PATH, "/".join(constraints)) + path = "{}/{}".format(self.QUERY_EVENTS_BASE_PATH, + "/".join(constraints)) def _query_events(): return self._send_request("get", diff --git a/osprofiler/drivers/messaging.py b/osprofiler/drivers/messaging.py index c7fbd12..f67bd19 100644 --- a/osprofiler/drivers/messaging.py +++ b/osprofiler/drivers/messaging.py @@ -49,8 +49,8 @@ class Messaging(base.Driver): raise ValueError("Oslo.messaging library is required for " "messaging driver") - super(Messaging, self).__init__(connection_str, project=project, - service=service, host=host) + super().__init__(connection_str, project=project, + service=service, host=host) self.context = context @@ -167,7 +167,7 @@ class Messaging(base.Driver): return self._parse_results() -class NotifyEndpoint(object): +class NotifyEndpoint: def __init__(self, oslo_messaging, base_id): self.received_messages = [] diff --git a/osprofiler/drivers/mongodb.py b/osprofiler/drivers/mongodb.py index fdd4a46..88aae89 100644 --- a/osprofiler/drivers/mongodb.py +++ b/osprofiler/drivers/mongodb.py @@ -22,8 +22,8 @@ class MongoDB(base.Driver): service=None, host=None, **kwargs): """MongoDB driver for OSProfiler.""" - super(MongoDB, self).__init__(connection_str, project=project, - service=service, host=host, **kwargs) + super().__init__(connection_str, project=project, + service=service, host=host, **kwargs) try: from pymongo import MongoClient except ImportError: diff --git a/osprofiler/drivers/otlp.py b/osprofiler/drivers/otlp.py index 37be020..ef7f954 100644 --- a/osprofiler/drivers/otlp.py +++ b/osprofiler/drivers/otlp.py @@ -28,9 +28,9 @@ class OTLP(base.Driver): conf=cfg.CONF, **kwargs): """OTLP driver using OTLP exporters.""" - super(OTLP, self).__init__(connection_str, project=project, - service=service, host=host, - conf=conf, **kwargs) + super().__init__(connection_str, project=project, + service=service, host=host, + conf=conf, **kwargs) try: from opentelemetry import trace as trace_api diff --git a/osprofiler/drivers/redis_driver.py b/osprofiler/drivers/redis_driver.py index db861f6..cbf856a 100644 --- a/osprofiler/drivers/redis_driver.py +++ b/osprofiler/drivers/redis_driver.py @@ -33,9 +33,9 @@ class Redis(base.Driver): service=None, host=None, conf=cfg.CONF, **kwargs): """Redis driver for OSProfiler.""" - super(Redis, self).__init__(connection_str, project=project, - service=service, host=host, - conf=conf, **kwargs) + super().__init__(connection_str, project=project, + service=service, host=host, + conf=conf, **kwargs) try: from redis import Redis as _Redis except ImportError: @@ -149,8 +149,7 @@ class Redis(base.Driver): match=self.namespace + base_id + "*"): # legacy yield self.db.get(key) - for event in self.db.lrange(self.namespace_opt + base_id, 0, -1): - yield event + yield from self.db.lrange(self.namespace_opt + base_id, 0, -1) for data in iterate_events(): n = jsonutils.loads(data) @@ -177,9 +176,9 @@ class RedisSentinel(Redis, base.Driver): service=None, host=None, conf=cfg.CONF, **kwargs): """Redis driver for OSProfiler.""" - super(RedisSentinel, self).__init__(connection_str, project=project, - service=service, host=host, - conf=conf, **kwargs) + super().__init__(connection_str, project=project, + service=service, host=host, + conf=conf, **kwargs) try: from redis.sentinel import Sentinel except ImportError: diff --git a/osprofiler/drivers/sqlalchemy_driver.py b/osprofiler/drivers/sqlalchemy_driver.py index daab1d0..93772c3 100644 --- a/osprofiler/drivers/sqlalchemy_driver.py +++ b/osprofiler/drivers/sqlalchemy_driver.py @@ -26,8 +26,8 @@ LOG = logging.getLogger(__name__) class SQLAlchemyDriver(base.Driver): def __init__(self, connection_str, project=None, service=None, host=None, **kwargs): - super(SQLAlchemyDriver, self).__init__(connection_str, project=project, - service=service, host=host) + super().__init__(connection_str, project=project, + service=service, host=host) try: from sqlalchemy import create_engine diff --git a/osprofiler/profiler.py b/osprofiler/profiler.py index 5406b39..af97134 100644 --- a/osprofiler/profiler.py +++ b/osprofiler/profiler.py @@ -292,7 +292,7 @@ class TracedMeta(type): traced - E.g. wsgi, rpc, db, etc... """ def __init__(cls, cls_name, bases, attrs): - super(TracedMeta, cls).__init__(cls_name, bases, attrs) + super().__init__(cls_name, bases, attrs) trace_args = dict(getattr(cls, "__trace_args__", {})) trace_private = trace_args.pop("trace_private", False) @@ -321,7 +321,7 @@ class TracedMeta(type): attr_name))) -class Trace(object): +class Trace: def __init__(self, name, info=None): """With statement way to use profiler start()/stop(). @@ -355,7 +355,7 @@ class Trace(object): stop() -class _Profiler(object): +class _Profiler: def __init__(self, hmac_key, base_id=None, parent_id=None): self.hmac_key = hmac_key diff --git a/osprofiler/tests/functional/test_driver.py b/osprofiler/tests/functional/test_driver.py index c29064a..d4eb1b3 100644 --- a/osprofiler/tests/functional/test_driver.py +++ b/osprofiler/tests/functional/test_driver.py @@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__) @profiler.trace_cls("rpc", hide_args=True) -class Foo(object): +class Foo: def bar(self, x): return self.baz(x, x) @@ -44,7 +44,7 @@ class DriverTestCase(test.FunctionalTestCase): PROJECT = "project" def setUp(self): - super(DriverTestCase, self).setUp() + super().setUp() CONF(["--config-file", os.path.dirname(__file__) + "/config.cfg"]) opts.set_defaults(CONF, enabled=True, diff --git a/osprofiler/tests/test.py b/osprofiler/tests/test.py index 3e86542..a0087e2 100644 --- a/osprofiler/tests/test.py +++ b/osprofiler/tests/test.py @@ -28,6 +28,6 @@ class FunctionalTestCase(TestCase): """Base for functional tests""" def setUp(self): - super(FunctionalTestCase, self).setUp() + super().setUp() logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) diff --git a/osprofiler/tests/unit/cmd/test_shell.py b/osprofiler/tests/unit/cmd/test_shell.py index 26be88e..760b7e2 100644 --- a/osprofiler/tests/unit/cmd/test_shell.py +++ b/osprofiler/tests/unit/cmd/test_shell.py @@ -32,16 +32,16 @@ class ShellTestCase(test.TestCase): TRACE_ID = "c598094d-bbee-40b6-b317-d76003b679d3" def setUp(self): - super(ShellTestCase, self).setUp() + super().setUp() self.old_environment = os.environ.copy() def tearDown(self): - super(ShellTestCase, self).tearDown() + super().tearDown() os.environ = self.old_environment def _trace_show_cmd(self, format_=None): cmd = "trace show --connection-string redis:// %s" % self.TRACE_ID - return cmd if format_ is None else "%s --%s" % (cmd, format_) + return cmd if format_ is None else "{} --{}".format(cmd, format_) @mock.patch("sys.stdout", io.StringIO()) @mock.patch("osprofiler.cmd.shell.OSProfilerShell") diff --git a/osprofiler/tests/unit/doc/test_specs.py b/osprofiler/tests/unit/doc/test_specs.py index e875227..36f4d47 100644 --- a/osprofiler/tests/unit/doc/test_specs.py +++ b/osprofiler/tests/unit/doc/test_specs.py @@ -88,7 +88,7 @@ class TitlesTestCase(test.TestCase): trailing_spaces = re.findall(" +$", line) self.assertEqual( len(trailing_spaces), 0, - "Found trailing spaces on line %s of %s" % (i + 1, tpl)) + "Found trailing spaces on line {} of {}".format(i + 1, tpl)) def test_template(self): with open(os.path.join(self.specs_path, "template.rst")) as f: @@ -98,7 +98,7 @@ class TitlesTestCase(test.TestCase): template_titles = self._get_titles(spec) for d in ["implemented", "in-progress"]: - spec_dir = "%s/%s" % (self.specs_path, d) + spec_dir = "{}/{}".format(self.specs_path, d) self.assertTrue(os.path.isdir(spec_dir), "%s is not a directory" % spec_dir) diff --git a/osprofiler/tests/unit/drivers/test_elasticsearch.py b/osprofiler/tests/unit/drivers/test_elasticsearch.py index 985fa30..44192be 100644 --- a/osprofiler/tests/unit/drivers/test_elasticsearch.py +++ b/osprofiler/tests/unit/drivers/test_elasticsearch.py @@ -22,7 +22,7 @@ from osprofiler.tests import test class ElasticsearchTestCase(test.TestCase): def setUp(self): - super(ElasticsearchTestCase, self).setUp() + super().setUp() self.elasticsearch = ElasticsearchDriver( "elasticsearch://localhost:9001/") self.elasticsearch.project = "project" diff --git a/osprofiler/tests/unit/drivers/test_jaeger.py b/osprofiler/tests/unit/drivers/test_jaeger.py index 128d8aa..e159f6e 100644 --- a/osprofiler/tests/unit/drivers/test_jaeger.py +++ b/osprofiler/tests/unit/drivers/test_jaeger.py @@ -27,7 +27,7 @@ from jaeger_client import Config class JaegerTestCase(test.TestCase): def setUp(self): - super(JaegerTestCase, self).setUp() + super().setUp() opts.set_defaults(cfg.CONF) cfg.CONF.set_default( diff --git a/osprofiler/tests/unit/drivers/test_loginsight.py b/osprofiler/tests/unit/drivers/test_loginsight.py index 3066d24..1294ce1 100644 --- a/osprofiler/tests/unit/drivers/test_loginsight.py +++ b/osprofiler/tests/unit/drivers/test_loginsight.py @@ -29,7 +29,7 @@ class LogInsightDriverTestCase(test.TestCase): BASE_ID = "8d28af1e-acc0-498c-9890-6908e33eff5f" def setUp(self): - super(LogInsightDriverTestCase, self).setUp() + super().setUp() self._client = mock.Mock(spec=loginsight.LogInsightClient) self._project = "cinder" self._service = "osapi_volume" @@ -160,7 +160,7 @@ class LogInsightDriverTestCase(test.TestCase): class LogInsightClientTestCase(test.TestCase): def setUp(self): - super(LogInsightClientTestCase, self).setUp() + super().setUp() self._host = "localhost" self._username = "username" self._password = "password" # nosec diff --git a/osprofiler/tests/unit/drivers/test_mongodb.py b/osprofiler/tests/unit/drivers/test_mongodb.py index 6037653..2b81ab0 100644 --- a/osprofiler/tests/unit/drivers/test_mongodb.py +++ b/osprofiler/tests/unit/drivers/test_mongodb.py @@ -21,7 +21,7 @@ from osprofiler.tests import test class MongoDBParserTestCase(test.TestCase): def setUp(self): - super(MongoDBParserTestCase, self).setUp() + super().setUp() self.mongodb = MongoDB("mongodb://localhost") def test_build_empty_tree(self): diff --git a/osprofiler/tests/unit/drivers/test_otlp.py b/osprofiler/tests/unit/drivers/test_otlp.py index 4162822..f7bceda 100644 --- a/osprofiler/tests/unit/drivers/test_otlp.py +++ b/osprofiler/tests/unit/drivers/test_otlp.py @@ -24,7 +24,7 @@ from osprofiler.tests import test class OTLPTestCase(test.TestCase): def setUp(self): - super(OTLPTestCase, self).setUp() + super().setUp() opts.set_defaults(cfg.CONF) diff --git a/osprofiler/tests/unit/drivers/test_redis_driver.py b/osprofiler/tests/unit/drivers/test_redis_driver.py index b8d3e5e..ec3efa3 100644 --- a/osprofiler/tests/unit/drivers/test_redis_driver.py +++ b/osprofiler/tests/unit/drivers/test_redis_driver.py @@ -24,7 +24,7 @@ from osprofiler.tests import test class RedisParserTestCase(test.TestCase): def setUp(self): - super(RedisParserTestCase, self).setUp() + super().setUp() self.redisdb = Redis("redis://localhost:6379") def test_build_empty_tree(self): diff --git a/osprofiler/tests/unit/test_notifier.py b/osprofiler/tests/unit/test_notifier.py index 47229c8..a497d01 100644 --- a/osprofiler/tests/unit/test_notifier.py +++ b/osprofiler/tests/unit/test_notifier.py @@ -24,7 +24,7 @@ class NotifierTestCase(test.TestCase): def tearDown(self): notifier.set(notifier._noop_notifier) # restore defaults notifier.clear_notifier_cache() - super(NotifierTestCase, self).tearDown() + super().tearDown() def test_set(self): diff --git a/osprofiler/tests/unit/test_opts.py b/osprofiler/tests/unit/test_opts.py index 31af2ab..e342c03 100644 --- a/osprofiler/tests/unit/test_opts.py +++ b/osprofiler/tests/unit/test_opts.py @@ -23,7 +23,7 @@ from osprofiler.tests import test class ConfigTestCase(test.TestCase): def setUp(self): - super(ConfigTestCase, self).setUp() + super().setUp() self.conf_fixture = self.useFixture(fixture.Config()) def test_options_defaults(self): diff --git a/osprofiler/tests/unit/test_profiler.py b/osprofiler/tests/unit/test_profiler.py index ec24046..59d75d8 100644 --- a/osprofiler/tests/unit/test_profiler.py +++ b/osprofiler/tests/unit/test_profiler.py @@ -285,7 +285,7 @@ class TraceDecoratorTestCase(test.TestCase): mock_stop.assert_called_once_with(info=stop_info) -class FakeTracedCls(object): +class FakeTracedCls: def method1(self, a, b, c=10): return a + b + c @@ -488,7 +488,7 @@ class TraceClsDecoratorTestCase(test.TestCase): self.assertFalse(mock_stop.called) -class FakeTraceWithMetaclassBase(object, metaclass=profiler.TracedMeta): +class FakeTraceWithMetaclassBase(metaclass=profiler.TracedMeta): __trace_args__ = {"name": "rpc", "info": {"a": 10}} diff --git a/osprofiler/tests/unit/test_utils.py b/osprofiler/tests/unit/test_utils.py index 2239aa1..3205692 100644 --- a/osprofiler/tests/unit/test_utils.py +++ b/osprofiler/tests/unit/test_utils.py @@ -137,7 +137,7 @@ class UtilsTestCase(test.TestCase): def test_itersubclasses(self): - class A(object): + class A: pass class B(A): diff --git a/osprofiler/tests/unit/test_web.py b/osprofiler/tests/unit/test_web.py index 7ceade0..a88071f 100644 --- a/osprofiler/tests/unit/test_web.py +++ b/osprofiler/tests/unit/test_web.py @@ -31,7 +31,7 @@ def dummy_app(environ, response): class WebTestCase(test.TestCase): def setUp(self): - super(WebTestCase, self).setUp() + super().setUp() profiler.clean() self.addCleanup(profiler.clean) @@ -61,7 +61,7 @@ class WebTestCase(test.TestCase): class WebMiddlewareTestCase(test.TestCase): def setUp(self): - super(WebMiddlewareTestCase, self).setUp() + super().setUp() profiler.clean() # it's default state of _ENABLED param, so let's set it here web._ENABLED = None @@ -69,7 +69,7 @@ class WebMiddlewareTestCase(test.TestCase): def tearDown(self): web.enable() - super(WebMiddlewareTestCase, self).tearDown() + super().tearDown() def test_factory(self): mock_app = mock.MagicMock() diff --git a/osprofiler/web.py b/osprofiler/web.py index c83d68a..cdacfb5 100644 --- a/osprofiler/web.py +++ b/osprofiler/web.py @@ -65,7 +65,7 @@ def enable(hmac_keys=None): _HMAC_KEYS = utils.split(hmac_keys or "") -class WsgiMiddleware(object): +class WsgiMiddleware: """WSGI Middleware that enables tracing for an application.""" def __init__(self, application, hmac_keys=None, enabled=False, **kwargs): diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index 2496c25..a00044c 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/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/tools/patch_tox_venv.py b/tools/patch_tox_venv.py index 52b724c..a3c1d43 100644 --- a/tools/patch_tox_venv.py +++ b/tools/patch_tox_venv.py @@ -37,7 +37,7 @@ def main(argv): os.path.join(root, 'test-requirements.txt'), os.path.join(root, 'tools', 'test-requires'), ]) - py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1]) + py_version = "python{}.{}".format(sys.version_info[0], sys.version_info[1]) project = 'oslo' install = install_venv.InstallVenv(root, venv, pip_requires, test_requires, py_version, project)