Skip to content

Commit 0e2e003

Browse files
committed
style: add pyupgrade check, 2.7+
1 parent 11e12fe commit 0e2e003

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ repos:
3030
- id: fix-encoding-pragma
3131
exclude: ^noxfile.py$
3232

33+
- repo: https://github.com/asottile/pyupgrade
34+
rev: v2.21.0
35+
hooks:
36+
- id: pyupgrade
37+
3338
# Black, the code formatter, natively supports pre-commit
3439
- repo: https://github.com/psf/black
3540
rev: 21.6b0

tests/extra_python_package/test_files.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_build_sdist(monkeypatch, tmpdir):
126126
with tarfile.open(str(sdist)) as tar:
127127
start = tar.getnames()[0] + "/"
128128
version = start[9:-1]
129-
simpler = set(n.split("/", 1)[-1] for n in tar.getnames()[1:])
129+
simpler = {n.split("/", 1)[-1] for n in tar.getnames()[1:]}
130130

131131
with contextlib.closing(
132132
tar.extractfile(tar.getmember(start + "setup.py"))
@@ -138,9 +138,9 @@ def test_build_sdist(monkeypatch, tmpdir):
138138
) as f:
139139
pyproject_toml = f.read()
140140

141-
files = set("pybind11/{}".format(n) for n in all_files)
141+
files = {"pybind11/{}".format(n) for n in all_files}
142142
files |= sdist_files
143-
files |= set("pybind11{}".format(n) for n in local_sdist_files)
143+
files |= {"pybind11{}".format(n) for n in local_sdist_files}
144144
files.add("pybind11.egg-info/entry_points.txt")
145145
files.add("pybind11.egg-info/requires.txt")
146146
assert simpler == files
@@ -181,7 +181,7 @@ def test_build_global_dist(monkeypatch, tmpdir):
181181
with tarfile.open(str(sdist)) as tar:
182182
start = tar.getnames()[0] + "/"
183183
version = start[16:-1]
184-
simpler = set(n.split("/", 1)[-1] for n in tar.getnames()[1:])
184+
simpler = {n.split("/", 1)[-1] for n in tar.getnames()[1:]}
185185

186186
with contextlib.closing(
187187
tar.extractfile(tar.getmember(start + "setup.py"))
@@ -193,9 +193,9 @@ def test_build_global_dist(monkeypatch, tmpdir):
193193
) as f:
194194
pyproject_toml = f.read()
195195

196-
files = set("pybind11/{}".format(n) for n in all_files)
196+
files = {"pybind11/{}".format(n) for n in all_files}
197197
files |= sdist_files
198-
files |= set("pybind11_global{}".format(n) for n in local_sdist_files)
198+
files |= {"pybind11_global{}".format(n) for n in local_sdist_files}
199199
assert simpler == files
200200

201201
with open(os.path.join(MAIN_DIR, "tools", "setup_global.py.in"), "rb") as f:
@@ -220,7 +220,7 @@ def tests_build_wheel(monkeypatch, tmpdir):
220220

221221
(wheel,) = tmpdir.visit("*.whl")
222222

223-
files = set("pybind11/{}".format(n) for n in all_files)
223+
files = {"pybind11/{}".format(n) for n in all_files}
224224
files |= {
225225
"dist-info/LICENSE",
226226
"dist-info/METADATA",
@@ -233,10 +233,10 @@ def tests_build_wheel(monkeypatch, tmpdir):
233233
with zipfile.ZipFile(str(wheel)) as z:
234234
names = z.namelist()
235235

236-
trimmed = set(n for n in names if "dist-info" not in n)
237-
trimmed |= set(
236+
trimmed = {n for n in names if "dist-info" not in n}
237+
trimmed |= {
238238
"dist-info/{}".format(n.split("/", 1)[-1]) for n in names if "dist-info" in n
239-
)
239+
}
240240
assert files == trimmed
241241

242242

@@ -250,8 +250,8 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
250250

251251
(wheel,) = tmpdir.visit("*.whl")
252252

253-
files = set("data/data/{}".format(n) for n in src_files)
254-
files |= set("data/headers/{}".format(n[8:]) for n in headers)
253+
files = {"data/data/{}".format(n) for n in src_files}
254+
files |= {"data/headers/{}".format(n[8:]) for n in headers}
255255
files |= {
256256
"dist-info/LICENSE",
257257
"dist-info/METADATA",
@@ -264,6 +264,6 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
264264
names = z.namelist()
265265

266266
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
267-
trimmed = set(n[len(beginning) + 1 :] for n in names)
267+
trimmed = {n[len(beginning) + 1 :] for n in names}
268268

269269
assert files == trimmed

tests/test_builtin_casters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_single_char_arguments():
5050
"""Tests failures for passing invalid inputs to char-accepting functions"""
5151

5252
def toobig_message(r):
53-
return "Character code point not in range({0:#x})".format(r)
53+
return "Character code point not in range({:#x})".format(r)
5454

5555
toolong_message = "Expected a character, but multi-character string found"
5656

tests/test_callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def gen_f():
144144
from time import sleep
145145

146146
sleep(0.5)
147-
assert sum(res) == sum([x + 3 for x in work])
147+
assert sum(res) == sum(x + 3 for x in work)
148148

149149

150150
def test_async_async_callbacks():

tests/test_pytypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_set(capture, doc):
6565
"""
6666
)
6767

68-
assert not m.set_contains(set([]), 42)
68+
assert not m.set_contains(set(), 42)
6969
assert m.set_contains({42}, 42)
7070
assert m.set_contains({"foo"}, "foo")
7171

@@ -448,7 +448,7 @@ def test_memoryview(method, args, fmt, expected_view):
448448
view_as_list = list(view)
449449
else:
450450
# Using max to pick non-zero byte (big-endian vs little-endian).
451-
view_as_list = [max([ord(c) for c in s]) for s in view]
451+
view_as_list = [max(ord(c) for c in s) for s in view]
452452
assert view_as_list == list(expected_view)
453453

454454

0 commit comments

Comments
 (0)