From 066baeb179062e397aa9f4dfd5d74ecb8dd3bb8c Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 19 Oct 2024 23:26:59 +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. Change-Id: Iee7bdff54efe4bea1b255c1114a4291c3e62fea0 --- .pre-commit-config.yaml | 5 +++++ doc/source/conf.py | 1 - etcd3gw/__init__.py | 3 --- etcd3gw/client.py | 2 +- etcd3gw/exceptions.py | 2 +- etcd3gw/lease.py | 2 +- etcd3gw/lock.py | 2 +- etcd3gw/tests/test_etcd3gw.py | 2 +- etcd3gw/watch.py | 2 +- releasenotes/source/conf.py | 1 - 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ab651e2..db9ce89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,3 +24,8 @@ repos: - id: hacking additional_dependencies: [] exclude: '^(doc|releasenotes|tools)/.*$' + - 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 3706d89..7d6a818 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # etcd3-gateway documentation build configuration file, created by # sphinx-quickstart on Sat Mar 25 20:42:09 2017. diff --git a/etcd3gw/__init__.py b/etcd3gw/__init__.py index 806a237..126c792 100644 --- a/etcd3gw/__init__.py +++ b/etcd3gw/__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 @@ -12,7 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from __future__ import absolute_import import pbr.version from etcd3gw.client import client diff --git a/etcd3gw/client.py b/etcd3gw/client.py index bdca6f0..c44ecd9 100644 --- a/etcd3gw/client.py +++ b/etcd3gw/client.py @@ -41,7 +41,7 @@ _EXCEPTIONS_BY_CODE = { DEFAULT_API_PATH = os.getenv('ETCD3GW_API_PATH') -class Etcd3Client(object): +class Etcd3Client: def __init__(self, host='localhost', port=2379, protocol="http", ca_cert=None, cert_key=None, cert_cert=None, timeout=None, api_path=DEFAULT_API_PATH): diff --git a/etcd3gw/exceptions.py b/etcd3gw/exceptions.py index 4294ff1..55942af 100644 --- a/etcd3gw/exceptions.py +++ b/etcd3gw/exceptions.py @@ -13,7 +13,7 @@ class Etcd3Exception(Exception): def __init__(self, detail_text=None, *args): - super(Etcd3Exception, self).__init__(*args) + super().__init__(*args) self.detail_text = detail_text diff --git a/etcd3gw/lease.py b/etcd3gw/lease.py index 79f3b4a..27e3e38 100644 --- a/etcd3gw/lease.py +++ b/etcd3gw/lease.py @@ -13,7 +13,7 @@ from etcd3gw.utils import _decode -class Lease(object): +class Lease: def __init__(self, id, client=None): """Lease object for expiring keys diff --git a/etcd3gw/lock.py b/etcd3gw/lock.py index c659054..f12da5d 100644 --- a/etcd3gw/lock.py +++ b/etcd3gw/lock.py @@ -17,7 +17,7 @@ from etcd3gw.utils import DEFAULT_TIMEOUT from etcd3gw.utils import LOCK_PREFIX -class Lock(object): +class Lock: def __init__(self, name, ttl=DEFAULT_TIMEOUT, client=None): """Create a lock using the given name with specified timeout diff --git a/etcd3gw/tests/test_etcd3gw.py b/etcd3gw/tests/test_etcd3gw.py index 158d866..d8e5a39 100644 --- a/etcd3gw/tests/test_etcd3gw.py +++ b/etcd3gw/tests/test_etcd3gw.py @@ -360,7 +360,7 @@ class TestEtcd3Gateway(base.TestCase): self.assertEqual( event['kv']['key'], - ('%s%s' % (key, change_count)).encode("latin-1"), + ('{}{}'.format(key, change_count)).encode("latin-1"), ) self.assertEqual( event['kv']['value'], diff --git a/etcd3gw/watch.py b/etcd3gw/watch.py index 1745355..1da3df1 100644 --- a/etcd3gw/watch.py +++ b/etcd3gw/watch.py @@ -39,7 +39,7 @@ def _watch(resp, callback): callback(event) -class Watcher(object): +class Watcher: KW_ARGS = ['start_revision', 'progress_notify', 'filters', 'prev_kv'] KW_ENCODED_ARGS = ['range_end'] diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index 98ed70b..8057bd2 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