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.

Also add the pyupgrade hook to pre-commit to avoid merging additional
Python 2 syntaxes.

Change-Id: Ie3d3d797fc8b773e23d01e4b798a1d77feb0b475
This commit is contained in:
Takashi Kajinami
2024-10-19 23:28:42 +09:00
parent d5dc9f1c99
commit 6fe54adb26
10 changed files with 31 additions and 26 deletions

View File

@ -31,3 +31,8 @@ repos:
hooks:
- id: doc8
files: doc/source/.*\.rst$
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
args: [--py3-only]

View File

@ -36,7 +36,7 @@ class RejectedSubmission(Exception):
Future = _futures.Future
class _Gatherer(object):
class _Gatherer:
def __init__(self, submit_func, lock_factory, start_before_submit=False):
self._submit_func = submit_func
self._stats_lock = lock_factory()
@ -198,14 +198,14 @@ class ProcessPoolExecutor(_process.ProcessPoolExecutor):
def __init__(self, max_workers=None):
if max_workers is None:
max_workers = _utils.get_optimal_process_count()
super(ProcessPoolExecutor, self).__init__(max_workers=max_workers)
super().__init__(max_workers=max_workers)
if self._max_workers <= 0:
raise ValueError("Max workers must be greater than zero")
self._gatherer = _Gatherer(
# Since our submit will use this gatherer we have to reference
# the parent submit, bound to this instance (which is what we
# really want to use anyway).
super(ProcessPoolExecutor, self).submit,
super().submit,
self.threading.lock_object)
@property
@ -303,7 +303,7 @@ class GreenFuture(Future):
__doc__ = Future.__doc__
def __init__(self):
super(GreenFuture, self).__init__()
super().__init__()
if not _utils.EVENTLET_AVAILABLE:
raise RuntimeError('Eventlet is needed to use a green future')
# NOTE(harlowja): replace the built-in condition with a greenthread
@ -415,7 +415,7 @@ class GreenThreadPoolExecutor(_futures.Executor):
self._pool.waitall()
class ExecutorStatistics(object):
class ExecutorStatistics:
"""Holds *immutable* information about a executors executions."""
__slots__ = ['_failures', '_executed', '_runtime', '_cancelled']

View File

@ -32,7 +32,7 @@ if _utils.EVENTLET_AVAILABLE:
Queue = greenqueue.Queue
is_monkey_patched = greenpatcher.is_monkey_patched
class GreenThreading(object):
class GreenThreading:
@staticmethod
def event_object(*args, **kwargs):
@ -58,7 +58,7 @@ else:
is_monkey_patched = lambda mod: False
class GreenWorker(object):
class GreenWorker:
def __init__(self, work, work_queue):
self.work = work
self.work_queue = work_queue

View File

@ -16,7 +16,7 @@ import threading
import weakref
class Threading(object):
class Threading:
@staticmethod
def event_object(*args, **kwargs):
@ -44,7 +44,7 @@ class ThreadWorker(threading.Thread):
MAX_IDLE_FOR = 1
def __init__(self, executor, work_queue):
super(ThreadWorker, self).__init__()
super().__init__()
self.work_queue = work_queue
self.should_stop = False
self.idle = False

View File

@ -29,7 +29,7 @@ except ImportError:
EVENTLET_AVAILABLE = False
class WorkItem(object):
class WorkItem:
"""A thing to be executed by a executor."""
def __init__(self, future, fn, args, kwargs):
@ -62,7 +62,7 @@ class WorkItem(object):
del exc_type, exc_value, exc_tb
class Failure(object):
class Failure:
"""Object that captures a exception (and its associated information)."""
def __init__(self, retain_tb):
@ -139,7 +139,7 @@ def get_optimal_process_count(default=1):
return default
class Barrier(object):
class Barrier:
"""A class that ensures active <= 0 occur before unblocking."""
def __init__(self, cond_cls=threading.Condition):

View File

@ -64,7 +64,7 @@ class Work(collections.namedtuple("Work",
return self.callback(*self.args, **self.kwargs)
class Watcher(object):
class Watcher:
"""A **read-only** object representing a periodic callback's activities."""
def __init__(self, metrics, work):
@ -238,7 +238,7 @@ def _now_plus_periodicity(cb, now):
return how_often + now
class _Schedule(object):
class _Schedule:
"""Internal heap-based structure that maintains the schedule/ordering.
This stores a heap composed of the following ``(next_run, index)`` where
@ -278,7 +278,7 @@ def _on_failure_log(log, cb, kind, spacing, exc_info, traceback=None):
" seconds):\n%s", kind, cb_name, spacing, traceback)
class _Runner(object):
class _Runner:
def __init__(self, now_func, retain_traceback=True):
self.now_func = now_func
self.retain_traceback = retain_traceback
@ -316,7 +316,7 @@ def _build(now_func, works, next_run_scheduler):
_SCHEDULE_RETRY_EXCEPTIONS = (RuntimeError, futurist.RejectedSubmission)
class ExecutorFactory(object):
class ExecutorFactory:
"""Base class for any executor factory."""
shutdown = True
@ -338,7 +338,7 @@ class ExistingExecutor(ExecutorFactory):
return self._executor
class PeriodicWorker(object):
class PeriodicWorker:
"""Calls a collection of callables periodically (sleeping as needed...).
NOTE(harlowja): typically the :py:meth:`.start` method is executed in a

View File

@ -54,11 +54,11 @@ class TestExecutors(testscenarios.TestWithScenarios, base.TestCase):
]
def setUp(self):
super(TestExecutors, self).setUp()
super().setUp()
self.executor = self.executor_cls(**self.executor_kwargs)
def tearDown(self):
super(TestExecutors, self).tearDown()
super().tearDown()
self.executor.shutdown()
self.executor = None
@ -155,7 +155,7 @@ class TestRejection(testscenarios.TestWithScenarios, base.TestCase):
]
def setUp(self):
super(TestRejection, self).setUp()
super().setUp()
self.executor = self.executor_cls(**self.executor_kwargs)
self.addCleanup(self.executor.shutdown, wait=True)

View File

@ -428,7 +428,7 @@ class TestPeriodics(testscenarios.TestWithScenarios, base.TestCase):
def test_create_with_arguments(self):
m = mock.Mock()
class Object(object):
class Object:
@periodics.periodic(0.5)
def func1(self, *args, **kwargs):
m(*args, **kwargs)
@ -533,7 +533,7 @@ class RejectingExecutor(futurist.GreenThreadPoolExecutor):
def __init__(self):
self._rejections_count = 0
super(RejectingExecutor, self).__init__(check_and_reject=self._reject)
super().__init__(check_and_reject=self._reject)
class TestPformat(base.TestCase):

View File

@ -48,11 +48,11 @@ class TestWaiters(testscenarios.TestWithScenarios, base.TestCase):
]
def setUp(self):
super(TestWaiters, self).setUp()
super().setUp()
self.executor = self.executor_cls(**self.executor_kwargs)
def tearDown(self):
super(TestWaiters, self).tearDown()
super().tearDown()
self.executor.shutdown()
self.executor = None

View File

@ -113,7 +113,7 @@ def wait_for_any(fs, timeout=None):
'wait_for_any', timeout=timeout)
class _AllGreenWaiter(object):
class _AllGreenWaiter:
"""Provides the event that ``_wait_for_all_green`` blocks on."""
def __init__(self, pending):
@ -137,7 +137,7 @@ class _AllGreenWaiter(object):
self._decrement_pending()
class _AnyGreenWaiter(object):
class _AnyGreenWaiter:
"""Provides the event that ``_wait_for_any_green`` blocks on."""
def __init__(self):