From 116055a9120194f0754bff9f4d6c940a2565586a Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 19 Oct 2024 23:08:28 +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. Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I920992b0fdd3df6f7276268d57e7345c70272d12 --- .pre-commit-config.yaml | 5 +++++ debtcollector/_utils.py | 2 +- debtcollector/moves.py | 2 +- debtcollector/removals.py | 2 +- debtcollector/tests/test_deprecation.py | 18 +++++++++--------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d174849..31d9d64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,3 +23,8 @@ repos: hooks: - id: hacking additional_dependencies: [] + - repo: https://github.com/asottile/pyupgrade + rev: v3.18.0 + hooks: + - id: pyupgrade + args: [--py3-only] diff --git a/debtcollector/_utils.py b/debtcollector/_utils.py index e6bff65..cdc3119 100644 --- a/debtcollector/_utils.py +++ b/debtcollector/_utils.py @@ -99,7 +99,7 @@ def get_class_name(obj, fully_qualified=True): return obj.__name__ if fully_qualified and hasattr(obj, '__module__'): - return '%s.%s' % (obj.__module__, obj.__name__) + return '{}.{}'.format(obj.__module__, obj.__name__) else: return obj.__name__ diff --git a/debtcollector/moves.py b/debtcollector/moves.py index 0f50aa7..413dc04 100644 --- a/debtcollector/moves.py +++ b/debtcollector/moves.py @@ -85,7 +85,7 @@ def moved_function(new_func, old_func_name, old_module_name, return old_new_func -class moved_read_only_property(object): +class moved_read_only_property: """Descriptor for read-only properties moved to another location. This works like the ``@property`` descriptor but can be used instead to diff --git a/debtcollector/removals.py b/debtcollector/removals.py index ea44c67..8970acb 100644 --- a/debtcollector/removals.py +++ b/debtcollector/removals.py @@ -33,7 +33,7 @@ def _fetch_first_result(fget, fset, fdel, apply_func, value_not_found=None): return value_not_found -class removed_property(object): +class removed_property: """Property descriptor that deprecates a property. This works like the ``@property`` descriptor but can be used instead to diff --git a/debtcollector/tests/test_deprecation.py b/debtcollector/tests/test_deprecation.py index b5575e7..2f89fed 100644 --- a/debtcollector/tests/test_deprecation.py +++ b/debtcollector/tests/test_deprecation.py @@ -52,7 +52,7 @@ def blip_blop_blip_unwrapped(type='cat'): return "The %s meowed quietly" % type -class WoofWoof(object): +class WoofWoof: @property def bark(self): return 'woof' @@ -73,7 +73,7 @@ class WoofWoof(object): return 'super-duper' -class KittyKat(object): +class KittyKat: @moves.moved_method('supermeow') def meow(self, volume=11): @@ -87,7 +87,7 @@ class KittyKat(object): return 'supermeow' -class Giraffe(object): +class Giraffe: color = 'orange' colour = moves.moved_read_only_property('colour', 'color') @@ -98,7 +98,7 @@ class Giraffe(object): heightt = moves.moved_read_only_property('heightt', 'height') -class NewHotness(object): +class NewHotness: def hot(self): return 'cold' @@ -136,28 +136,28 @@ yellowish_sun = moves.moved_function(yellow_sun, 'yellowish_sun', __name__) @removals.remove() -class EFSF(object): +class EFSF: pass @removals.remove(category=PendingDeprecationWarning) -class EFSF_2(object): +class EFSF_2: pass @removals.removed_class("StarLord") -class StarLord(object): +class StarLord: def __init__(self): self.name = "star" class StarLordJr(StarLord): def __init__(self, name): - super(StarLordJr, self).__init__() + super().__init__() self.name = name -class ThingB(object): +class ThingB: @removals.remove() def black_tristars(self): pass