Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
0e2e0035
Commit
0e2e0035
authored
Jul 12, 2021
by
Henry Schreiner
Committed by
Henry Schreiner
Jul 12, 2021
Browse files
style: add pyupgrade check, 2.7+
parent
11e12fe4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
17 deletions
+22
-17
.pre-commit-config.yaml
.pre-commit-config.yaml
+5
-0
tests/extra_python_package/test_files.py
tests/extra_python_package/test_files.py
+13
-13
tests/test_builtin_casters.py
tests/test_builtin_casters.py
+1
-1
tests/test_callbacks.py
tests/test_callbacks.py
+1
-1
tests/test_pytypes.py
tests/test_pytypes.py
+2
-2
No files found.
.pre-commit-config.yaml
View file @
0e2e0035
...
@@ -30,6 +30,11 @@ repos:
...
@@ -30,6 +30,11 @@ repos:
-
id
:
fix-encoding-pragma
-
id
:
fix-encoding-pragma
exclude
:
^noxfile.py$
exclude
:
^noxfile.py$
-
repo
:
https://github.com/asottile/pyupgrade
rev
:
v2.21.0
hooks
:
-
id
:
pyupgrade
# Black, the code formatter, natively supports pre-commit
# Black, the code formatter, natively supports pre-commit
-
repo
:
https://github.com/psf/black
-
repo
:
https://github.com/psf/black
rev
:
21.6b0
rev
:
21.6b0
...
...
tests/extra_python_package/test_files.py
View file @
0e2e0035
...
@@ -126,7 +126,7 @@ def test_build_sdist(monkeypatch, tmpdir):
...
@@ -126,7 +126,7 @@ def test_build_sdist(monkeypatch, tmpdir):
with
tarfile
.
open
(
str
(
sdist
))
as
tar
:
with
tarfile
.
open
(
str
(
sdist
))
as
tar
:
start
=
tar
.
getnames
()[
0
]
+
"/"
start
=
tar
.
getnames
()[
0
]
+
"/"
version
=
start
[
9
:
-
1
]
version
=
start
[
9
:
-
1
]
simpler
=
set
(
n
.
split
(
"/"
,
1
)[
-
1
]
for
n
in
tar
.
getnames
()[
1
:]
)
simpler
=
{
n
.
split
(
"/"
,
1
)[
-
1
]
for
n
in
tar
.
getnames
()[
1
:]
}
with
contextlib
.
closing
(
with
contextlib
.
closing
(
tar
.
extractfile
(
tar
.
getmember
(
start
+
"setup.py"
))
tar
.
extractfile
(
tar
.
getmember
(
start
+
"setup.py"
))
...
@@ -138,9 +138,9 @@ def test_build_sdist(monkeypatch, tmpdir):
...
@@ -138,9 +138,9 @@ def test_build_sdist(monkeypatch, tmpdir):
)
as
f
:
)
as
f
:
pyproject_toml
=
f
.
read
()
pyproject_toml
=
f
.
read
()
files
=
set
(
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
)
files
=
{
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
}
files
|=
sdist_files
files
|=
sdist_files
files
|=
set
(
"pybind11{}"
.
format
(
n
)
for
n
in
local_sdist_files
)
files
|=
{
"pybind11{}"
.
format
(
n
)
for
n
in
local_sdist_files
}
files
.
add
(
"pybind11.egg-info/entry_points.txt"
)
files
.
add
(
"pybind11.egg-info/entry_points.txt"
)
files
.
add
(
"pybind11.egg-info/requires.txt"
)
files
.
add
(
"pybind11.egg-info/requires.txt"
)
assert
simpler
==
files
assert
simpler
==
files
...
@@ -181,7 +181,7 @@ def test_build_global_dist(monkeypatch, tmpdir):
...
@@ -181,7 +181,7 @@ def test_build_global_dist(monkeypatch, tmpdir):
with
tarfile
.
open
(
str
(
sdist
))
as
tar
:
with
tarfile
.
open
(
str
(
sdist
))
as
tar
:
start
=
tar
.
getnames
()[
0
]
+
"/"
start
=
tar
.
getnames
()[
0
]
+
"/"
version
=
start
[
16
:
-
1
]
version
=
start
[
16
:
-
1
]
simpler
=
set
(
n
.
split
(
"/"
,
1
)[
-
1
]
for
n
in
tar
.
getnames
()[
1
:]
)
simpler
=
{
n
.
split
(
"/"
,
1
)[
-
1
]
for
n
in
tar
.
getnames
()[
1
:]
}
with
contextlib
.
closing
(
with
contextlib
.
closing
(
tar
.
extractfile
(
tar
.
getmember
(
start
+
"setup.py"
))
tar
.
extractfile
(
tar
.
getmember
(
start
+
"setup.py"
))
...
@@ -193,9 +193,9 @@ def test_build_global_dist(monkeypatch, tmpdir):
...
@@ -193,9 +193,9 @@ def test_build_global_dist(monkeypatch, tmpdir):
)
as
f
:
)
as
f
:
pyproject_toml
=
f
.
read
()
pyproject_toml
=
f
.
read
()
files
=
set
(
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
)
files
=
{
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
}
files
|=
sdist_files
files
|=
sdist_files
files
|=
set
(
"pybind11_global{}"
.
format
(
n
)
for
n
in
local_sdist_files
)
files
|=
{
"pybind11_global{}"
.
format
(
n
)
for
n
in
local_sdist_files
}
assert
simpler
==
files
assert
simpler
==
files
with
open
(
os
.
path
.
join
(
MAIN_DIR
,
"tools"
,
"setup_global.py.in"
),
"rb"
)
as
f
:
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):
...
@@ -220,7 +220,7 @@ def tests_build_wheel(monkeypatch, tmpdir):
(
wheel
,)
=
tmpdir
.
visit
(
"*.whl"
)
(
wheel
,)
=
tmpdir
.
visit
(
"*.whl"
)
files
=
set
(
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
)
files
=
{
"pybind11/{}"
.
format
(
n
)
for
n
in
all_files
}
files
|=
{
files
|=
{
"dist-info/LICENSE"
,
"dist-info/LICENSE"
,
"dist-info/METADATA"
,
"dist-info/METADATA"
,
...
@@ -233,10 +233,10 @@ def tests_build_wheel(monkeypatch, tmpdir):
...
@@ -233,10 +233,10 @@ def tests_build_wheel(monkeypatch, tmpdir):
with
zipfile
.
ZipFile
(
str
(
wheel
))
as
z
:
with
zipfile
.
ZipFile
(
str
(
wheel
))
as
z
:
names
=
z
.
namelist
()
names
=
z
.
namelist
()
trimmed
=
set
(
n
for
n
in
names
if
"dist-info"
not
in
n
)
trimmed
=
{
n
for
n
in
names
if
"dist-info"
not
in
n
}
trimmed
|=
set
(
trimmed
|=
{
"dist-info/{}"
.
format
(
n
.
split
(
"/"
,
1
)[
-
1
])
for
n
in
names
if
"dist-info"
in
n
"dist-info/{}"
.
format
(
n
.
split
(
"/"
,
1
)[
-
1
])
for
n
in
names
if
"dist-info"
in
n
)
}
assert
files
==
trimmed
assert
files
==
trimmed
...
@@ -250,8 +250,8 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
...
@@ -250,8 +250,8 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
(
wheel
,)
=
tmpdir
.
visit
(
"*.whl"
)
(
wheel
,)
=
tmpdir
.
visit
(
"*.whl"
)
files
=
set
(
"data/data/{}"
.
format
(
n
)
for
n
in
src_files
)
files
=
{
"data/data/{}"
.
format
(
n
)
for
n
in
src_files
}
files
|=
set
(
"data/headers/{}"
.
format
(
n
[
8
:])
for
n
in
headers
)
files
|=
{
"data/headers/{}"
.
format
(
n
[
8
:])
for
n
in
headers
}
files
|=
{
files
|=
{
"dist-info/LICENSE"
,
"dist-info/LICENSE"
,
"dist-info/METADATA"
,
"dist-info/METADATA"
,
...
@@ -264,6 +264,6 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
...
@@ -264,6 +264,6 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
names
=
z
.
namelist
()
names
=
z
.
namelist
()
beginning
=
names
[
0
].
split
(
"/"
,
1
)[
0
].
rsplit
(
"."
,
1
)[
0
]
beginning
=
names
[
0
].
split
(
"/"
,
1
)[
0
].
rsplit
(
"."
,
1
)[
0
]
trimmed
=
set
(
n
[
len
(
beginning
)
+
1
:]
for
n
in
names
)
trimmed
=
{
n
[
len
(
beginning
)
+
1
:]
for
n
in
names
}
assert
files
==
trimmed
assert
files
==
trimmed
tests/test_builtin_casters.py
View file @
0e2e0035
...
@@ -50,7 +50,7 @@ def test_single_char_arguments():
...
@@ -50,7 +50,7 @@ def test_single_char_arguments():
"""Tests failures for passing invalid inputs to char-accepting functions"""
"""Tests failures for passing invalid inputs to char-accepting functions"""
def
toobig_message
(
r
):
def
toobig_message
(
r
):
return
"Character code point not in range({
0
:#x})"
.
format
(
r
)
return
"Character code point not in range({:#x})"
.
format
(
r
)
toolong_message
=
"Expected a character, but multi-character string found"
toolong_message
=
"Expected a character, but multi-character string found"
...
...
tests/test_callbacks.py
View file @
0e2e0035
...
@@ -144,7 +144,7 @@ def test_async_callbacks():
...
@@ -144,7 +144,7 @@ def test_async_callbacks():
from
time
import
sleep
from
time
import
sleep
sleep
(
0.5
)
sleep
(
0.5
)
assert
sum
(
res
)
==
sum
(
[
x
+
3
for
x
in
work
]
)
assert
sum
(
res
)
==
sum
(
x
+
3
for
x
in
work
)
def
test_async_async_callbacks
():
def
test_async_async_callbacks
():
...
...
tests/test_pytypes.py
View file @
0e2e0035
...
@@ -65,7 +65,7 @@ def test_set(capture, doc):
...
@@ -65,7 +65,7 @@ def test_set(capture, doc):
"""
"""
)
)
assert
not
m
.
set_contains
(
set
(
[]
),
42
)
assert
not
m
.
set_contains
(
set
(),
42
)
assert
m
.
set_contains
({
42
},
42
)
assert
m
.
set_contains
({
42
},
42
)
assert
m
.
set_contains
({
"foo"
},
"foo"
)
assert
m
.
set_contains
({
"foo"
},
"foo"
)
...
@@ -448,7 +448,7 @@ def test_memoryview(method, args, fmt, expected_view):
...
@@ -448,7 +448,7 @@ def test_memoryview(method, args, fmt, expected_view):
view_as_list
=
list
(
view
)
view_as_list
=
list
(
view
)
else
:
else
:
# Using max to pick non-zero byte (big-endian vs little-endian).
# Using max to pick non-zero byte (big-endian vs little-endian).
view_as_list
=
[
max
(
[
ord
(
c
)
for
c
in
s
]
)
for
s
in
view
]
view_as_list
=
[
max
(
ord
(
c
)
for
c
in
s
)
for
s
in
view
]
assert
view_as_list
==
list
(
expected_view
)
assert
view_as_list
==
list
(
expected_view
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment