Skip to content

Commit 7c2f9fc

Browse files
committed
refactor: pyupgrade --py37-plus
1 parent aa02ed7 commit 7c2f9fc

File tree

7 files changed

+21
-25
lines changed

7 files changed

+21
-25
lines changed

django_coverage_plugin/plugin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from django.template.base import Lexer, NodeList, Template, TextNode
1818
from django.template.defaulttags import VerbatimNode
1919
from django.templatetags.i18n import BlockTranslateNode
20-
from six.moves import range
2120

2221
try:
2322
from django.template.base import TokenType
@@ -165,7 +164,7 @@ def sys_info(self):
165164
return [
166165
("django_template_dir", self.django_template_dir),
167166
("environment", sorted(
168-
("%s = %s" % (k, v))
167+
("{} = {}".format(k, v))
169168
for k, v in os.environ.items()
170169
if "DJANGO" in k
171170
)),
@@ -239,7 +238,7 @@ def line_number_range(self, frame):
239238
return -1, -1
240239

241240
if SHOW_TRACING:
242-
print("{!r}: {}".format(render_self, position))
241+
print(f"{render_self!r}: {position}")
243242
s_start, s_end = position
244243
if isinstance(render_self, TextNode):
245244
first_line = render_self.s.splitlines(True)[0]
@@ -294,7 +293,7 @@ def get_line_map(self, filename):
294293

295294
class FileReporter(coverage.plugin.FileReporter):
296295
def __init__(self, filename):
297-
super(FileReporter, self).__init__(filename)
296+
super().__init__(filename)
298297
# TODO: html filenames are absolute.
299298

300299
self._source = None
@@ -303,15 +302,15 @@ def source(self):
303302
if self._source is None:
304303
try:
305304
self._source = read_template_source(self.filename)
306-
except (IOError, UnicodeError) as exc:
307-
raise NoSource("Couldn't read {}: {}".format(self.filename, exc))
305+
except (OSError, UnicodeError) as exc:
306+
raise NoSource(f"Couldn't read {self.filename}: {exc}")
308307
return self._source
309308

310309
def lines(self):
311310
source_lines = set()
312311

313312
if SHOW_PARSING:
314-
print("-------------- {}".format(self.filename))
313+
print(f"-------------- {self.filename}")
315314

316315
if django.VERSION >= (1, 9):
317316
lexer = Lexer(self.source())
@@ -389,7 +388,7 @@ def lines(self):
389388
source_lines.update(range(lineno, lineno+num_lines))
390389

391390
if SHOW_PARSING:
392-
print("\t\t\tNow source_lines is: {!r}".format(source_lines))
391+
print(f"\t\t\tNow source_lines is: {source_lines!r}")
393392

394393
return source_lines
395394

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
"""
99

10-
import io
1110
import re
1211
from os.path import dirname, join
1312

@@ -19,7 +18,7 @@ def read(*names, **kwargs):
1918
2019
Parameter: encoding kwarg may be set
2120
"""
22-
return io.open(
21+
return open(
2322
join(dirname(__file__), *names),
2423
encoding=kwargs.get('encoding', 'utf8')
2524
).read()

tests/plugin_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class DjangoPluginTestCase(StdStreamCapturingMixin, TempDirMixin, TestCase):
6666
"""A base class for all our tests."""
6767

6868
def setUp(self):
69-
super(DjangoPluginTestCase, self).setUp()
69+
super().setUp()
7070
self.template_directory = "templates"
7171

7272
def _path(self, name=None):
73-
return "{}/{}".format(self.template_directory, name or self.template_file)
73+
return f"{self.template_directory}/{name or self.template_file}"
7474

7575
def make_template(self, text, name=None):
7676
"""Make a template with `text`.
@@ -191,14 +191,14 @@ def assert_analysis(self, executable, missing=None, name=None):
191191
self.assertEqual(
192192
executable,
193193
actual_executable,
194-
"Executable lines aren't as expected: %r != %r" % (
194+
"Executable lines aren't as expected: {!r} != {!r}".format(
195195
executable, actual_executable,
196196
),
197197
)
198198
self.assertEqual(
199199
missing or [],
200200
actual_missing,
201-
"Missing lines aren't as expected: %r != %r" % (
201+
"Missing lines aren't as expected: {!r} != {!r}".format(
202202
missing, actual_missing,
203203
),
204204
)

tests/test_engines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class MultipleEngineTests(DjangoPluginTestCase):
1212
def setUp(self):
13-
super(MultipleEngineTests, self).setUp()
13+
super().setUp()
1414

1515
engine = {
1616
'NAME': 'other',

tests/test_html.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf8
21
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
32
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt
43

tests/test_simple.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf8
21
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
32
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt
43

@@ -7,7 +6,7 @@
76
from .plugin_test import DjangoPluginTestCase
87

98
# 200 Unicode chars: snowman + poo.
10-
UNIUNI = u"\u26C4\U0001F4A9"*100
9+
UNIUNI = "\u26C4\U0001F4A9"*100
1110
if isinstance(UNIUNI, str):
1211
UNISTR = UNIUNI
1312
else:
@@ -64,8 +63,8 @@ def test_non_ascii(self):
6463
υηιcσɗє ιѕ тяιcку
6564
{{more}}!
6665
""")
67-
text = self.run_django_coverage(context={'more': u'ɘboɔinU'})
68-
self.assertEqual(text, u'υηιcσɗє ιѕ тяιcку\nɘboɔinU!\n')
66+
text = self.run_django_coverage(context={'more': 'ɘboɔinU'})
67+
self.assertEqual(text, 'υηιcσɗє ιѕ тяιcку\nɘboɔinU!\n')
6968
self.assert_analysis([1, 2])
7069
self.assertEqual(self.get_html_report(), 100)
7170
self.assertEqual(self.get_xml_report(), 100)
@@ -215,8 +214,8 @@ def test_verbatim(self):
215214
text = self.run_django_coverage()
216215
self.assertEqual(
217216
text,
218-
u"1\n\n{{if dying}}Alive.{{/if}}\nsecond.\n"
219-
u"{%third%}.UNIUNI\n\n7\n".replace(u"UNIUNI", UNIUNI)
217+
"1\n\n{{if dying}}Alive.{{/if}}\nsecond.\n"
218+
"{%third%}.UNIUNI\n\n7\n".replace("UNIUNI", UNIUNI)
220219
)
221220
self.assert_analysis([1, 2, 3, 4, 5, 7])
222221

tests/test_source.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_non_utf8_error(self):
8888
text = self.run_django_coverage(name="main.html")
8989
self.assertEqual(text, "Hello")
9090

91-
self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
91+
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
9292
self.assert_analysis([1], name="main.html")
9393
with self.assertRaisesRegex(NoSource, r"changelog.txt.*invalid start byte"):
9494
self.cov.html_report()
@@ -110,7 +110,7 @@ def test_non_utf8_omitted(self):
110110
text = self.run_django_coverage(name="main.html")
111111
self.assertEqual(text, "Hello")
112112

113-
self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
113+
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
114114
self.assert_analysis([1], name="main.html")
115115
self.cov.html_report()
116116

@@ -131,7 +131,7 @@ def test_non_utf8_ignored(self):
131131
text = self.run_django_coverage(name="main.html")
132132
self.assertEqual(text, "Hello")
133133

134-
self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
134+
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
135135
self.assert_analysis([1], name="main.html")
136136
warn_msg = (
137137
"'utf-8' codec can't decode byte 0xf6 in position 2: " +

0 commit comments

Comments
 (0)