Skip to content

Commit efb32af

Browse files
authored
Merge pull request #49 from ulgens/clean-pre3.8
Clean pre3.8
2 parents e2eb66b + 7313a62 commit efb32af

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v3.21.0
4+
hooks:
5+
- id: pyupgrade
6+
args: ["--py38-plus"]

djclick/adapter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.core.management import CommandError
99

1010

11-
class ArgumentParserDefaults(object):
11+
class ArgumentParserDefaults:
1212
def __init__(self, args):
1313
self._args = args
1414

@@ -18,7 +18,7 @@ def _get_kwargs(self):
1818
}
1919

2020

21-
class ArgumentParserAdapter(object):
21+
class ArgumentParserAdapter:
2222
def __init__(self):
2323
self._actions = []
2424
self._mutually_exclusive_groups = []
@@ -27,7 +27,7 @@ def parse_args(self, args):
2727
return ArgumentParserDefaults(args)
2828

2929

30-
class DjangoCommandMixin(object):
30+
class DjangoCommandMixin:
3131
use_argparse = False
3232
option_list = []
3333
base_stealth_options = []
@@ -40,13 +40,13 @@ def stealth_options(self):
4040

4141
def invoke(self, ctx):
4242
try:
43-
return super(DjangoCommandMixin, self).invoke(ctx)
43+
return super().invoke(ctx)
4444
except CommandError as e:
4545
# Honor the --traceback flag
4646
if ctx.traceback: # NOCOV
4747
raise
4848
styled_message = click.style(
49-
"{}: {}".format(e.__class__.__name__, e), fg="red", bold=True
49+
f"{e.__class__.__name__}: {e}", fg="red", bold=True
5050
)
5151
click.echo(styled_message, err=True)
5252
ctx.exit(1)
@@ -55,7 +55,7 @@ def run_from_argv(self, argv):
5555
"""
5656
Called when run from the command line.
5757
"""
58-
prog_name = "{} {}".format(os.path.basename(argv[0]), argv[1])
58+
prog_name = f"{os.path.basename(argv[0])} {argv[1]}"
5959
try:
6060
# We won't get an exception here in standalone_mode=False
6161
exit_code = self.main(
@@ -76,7 +76,7 @@ def create_parser(self, progname, subcommand):
7676
return ArgumentParserAdapter()
7777

7878
def print_help(self, prog_name, subcommand):
79-
prog_name = "{} {}".format(prog_name, subcommand)
79+
prog_name = f"{prog_name} {subcommand}"
8080
self.main(["--help"], prog_name=prog_name, standalone_mode=False)
8181

8282
def map_names(self):
@@ -140,7 +140,7 @@ def suppress_colors(ctx, param, value):
140140
return value
141141

142142

143-
class BaseRegistrator(object):
143+
class BaseRegistrator:
144144
common_options = [
145145
click.option(
146146
"-v",

djclick/params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ def __init__(self, qs, lookup="pk"):
1010
if isinstance(qs, type) and issubclass(qs, models.Model):
1111
qs = qs.objects.all()
1212
self.qs = qs
13-
self.name = "{}.{}".format(qs.model._meta.app_label, qs.model.__name__,)
13+
self.name = f"{qs.model._meta.app_label}.{qs.model.__name__}"
1414
self.lookup = lookup
1515

1616
def convert(self, value, param, ctx):
1717
if value is None: # NOCOV
18-
return super(ModelInstance, self).convert(value, param, ctx)
18+
return super().convert(value, param, ctx)
1919
try:
2020
return self.qs.get(**{self.lookup: value})
2121
except ObjectDoesNotExist:

djclick/test/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def call(*args, **kwargs):
2929
def call_command():
3030
from django.core.management import call_command
3131

32-
class CallCommand(object):
32+
class CallCommand:
3333
def __init__(self):
3434
self.io = BytesIO()
3535

djclick/test/test_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ def test_convert_fail(call_command, args, error_message):
4141
# Use `.endswith()` because of differences between CPython and pypy
4242
assert e.type is BadParameter
4343
assert str(e.value).endswith(
44-
"could not find testapp.DummyModel with {}".format(error_message)
44+
f"could not find testapp.DummyModel with {error_message}"
4545
)

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
sys.exit()
3333

3434

35-
class Setup(object):
35+
class Setup:
3636
@staticmethod
3737
def read(fname, fail_silently=False):
3838
"""
@@ -41,7 +41,7 @@ def read(fname, fail_silently=False):
4141
"""
4242
try:
4343
filepath = os.path.join(os.path.dirname(__file__), fname)
44-
with io.open(filepath, "rt", encoding="utf8") as f:
44+
with open(filepath, encoding="utf8") as f:
4545
return f.read()
4646
except:
4747
if not fail_silently:
@@ -90,7 +90,7 @@ def get_files(*bases):
9090
def get_metavar(name):
9191
data = Setup.read(os.path.join(PACKAGE, "__init__.py"))
9292
value = (
93-
re.search(u"__{}__\s*=\s*u?'([^']+)'".format(name), data).group(1).strip()
93+
re.search(fr"__{name}__\s*=\s*u?'([^']+)'", data).group(1).strip()
9494
)
9595
return value
9696

0 commit comments

Comments
 (0)