Skip to content

Commit abd7a9a

Browse files
committed
Merge branch 'smart_holder' into pywrapcc_merge_sh
2 parents 9efd8a1 + 9cbf45d commit abd7a9a

12 files changed

+70
-67
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ repos:
4242

4343
# Black, the code formatter, natively supports pre-commit
4444
- repo: https://github.com/psf/black
45-
rev: "23.1.0" # Keep in sync with blacken-docs
45+
rev: "23.3.0" # Keep in sync with blacken-docs
4646
hooks:
4747
- id: black
4848

@@ -52,11 +52,11 @@ repos:
5252
hooks:
5353
- id: blacken-docs
5454
additional_dependencies:
55-
- black==23.1.0 # keep in sync with black hook
55+
- black==23.3.0 # keep in sync with black hook
5656

5757
# Changes tabs to spaces
5858
- repo: https://github.com/Lucas-C/pre-commit-hooks
59-
rev: "v1.4.2"
59+
rev: "v1.5.1"
6060
hooks:
6161
- id: remove-tabs
6262
exclude: (^docs/.*|\.patch)?$
@@ -70,7 +70,7 @@ repos:
7070

7171
# Ruff, the Python auto-correcting linter written in Rust
7272
- repo: https://github.com/charliermarsh/ruff-pre-commit
73-
rev: v0.0.254
73+
rev: v0.0.263
7474
hooks:
7575
- id: ruff
7676
args: ["--fix", "--show-fixes"]
@@ -85,7 +85,7 @@ repos:
8585

8686
# PyLint has native support - not always usable, but works for us
8787
- repo: https://github.com/PyCQA/pylint
88-
rev: "v2.16.4"
88+
rev: "v3.0.0a6"
8989
hooks:
9090
- id: pylint
9191
files: ^pybind11
@@ -101,7 +101,7 @@ repos:
101101

102102
# Check static types with mypy
103103
- repo: https://github.com/pre-commit/mirrors-mypy
104-
rev: "v1.0.1"
104+
rev: "v1.1.1"
105105
hooks:
106106
- id: mypy
107107
args: []
@@ -121,11 +121,11 @@ repos:
121121
# Use tools/codespell_ignore_lines_from_errors.py
122122
# to rebuild .codespell-ignore-lines
123123
- repo: https://github.com/codespell-project/codespell
124-
rev: "v2.2.2"
124+
rev: "v2.2.4"
125125
hooks:
126126
- id: codespell
127127
exclude: ".supp$"
128-
args: ["-x", ".codespell-ignore-lines"]
128+
args: ["-x.codespell-ignore-lines", "-Lccompiler"]
129129

130130
# Check for common shell mistakes
131131
- repo: https://github.com/shellcheck-py/shellcheck-py
@@ -144,7 +144,7 @@ repos:
144144

145145
# Clang format the codebase automatically
146146
- repo: https://github.com/pre-commit/mirrors-clang-format
147-
rev: "v15.0.7"
147+
rev: "v16.0.0"
148148
hooks:
149149
- id: clang-format
150150
types_or: [c++, c, cuda]

include/pybind11/detail/type_caster_base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ struct value_and_holder {
258258

259259
// Main constructor for a found value/holder:
260260
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
261-
: inst{i}, index{index}, type{type}, vh{inst->simple_layout
262-
? inst->simple_value_holder
263-
: &inst->nonsimple.values_and_holders[vpos]} {}
261+
: inst{i}, index{index}, type{type},
262+
vh{inst->simple_layout ? inst->simple_value_holder
263+
: &inst->nonsimple.values_and_holders[vpos]} {}
264264

265265
// Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
266266
value_and_holder() = default;

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests
9393

9494
[tool.ruff.per-file-ignores]
9595
"tests/**" = ["EM", "N"]
96+
"tests/test_call_policies.py" = ["PLC1901"]

tests/test_class_sh_property.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_uqp(m_attr_readwrite, msg):
9292
field_orig.num = 39
9393
setattr(outer, m_attr_readwrite, field_orig)
9494
with pytest.raises(ValueError) as excinfo:
95-
field_orig.num
95+
_ = field_orig.num
9696
assert (
9797
msg(excinfo.value)
9898
== "Missing value for wrapped C++ type: Python instance was disowned."
@@ -103,7 +103,7 @@ def test_uqp(m_attr_readwrite, msg):
103103
field_retr1.num = 93
104104
setattr(outer, m_attr_readwrite, field_retr1)
105105
with pytest.raises(ValueError):
106-
field_retr1.num
106+
_ = field_retr1.num
107107
field_retr2 = getattr(outer, m_attr_readwrite)
108108
assert field_retr2.num == 93
109109

@@ -150,7 +150,7 @@ def test_unique_ptr_field_proxy_poc(m_attr):
150150
assert field_proxy.num == 45
151151
assert field_proxy.num == 45
152152
with pytest.raises(AttributeError):
153-
field_proxy.xyz
153+
_ = field_proxy.xyz
154154
assert field_proxy.num == 45
155155
field_proxy.num = 82
156156
assert field_proxy.num == 82

tests/test_class_sh_property_non_owning.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ struct CoreField {
1414
struct DataField {
1515
DataField(int i_value, int i_shared, int i_unique)
1616
: core_fld_value{i_value}, core_fld_shared_ptr{new CoreField{i_shared}},
17-
core_fld_raw_ptr{core_fld_shared_ptr.get()}, core_fld_unique_ptr{
18-
new CoreField{i_unique}} {}
17+
core_fld_raw_ptr{core_fld_shared_ptr.get()},
18+
core_fld_unique_ptr{new CoreField{i_unique}} {}
1919
CoreField core_fld_value;
2020
std::shared_ptr<CoreField> core_fld_shared_ptr;
2121
CoreField *core_fld_raw_ptr;

tests/test_class_sh_trampoline_self_life_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_m_big5():
1414
assert o1 is not obj
1515
assert o1.history == "Seed"
1616
with pytest.raises(ValueError) as excinfo:
17-
obj.history
17+
_ = obj.history
1818
assert "Python instance was disowned" in str(excinfo.value)
1919
assert o2 is None
2020

tests/test_class_sh_trampoline_shared_from_this.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_release_and_shared_from_this_leak():
2929
obj = PySft("")
3030
while True:
3131
m.pass_shared_ptr(obj)
32-
assert obj.history == ""
32+
assert not obj.history
3333
assert m.use_count(obj) == 1
3434
break # Comment out for manual leak checking (use `top` command).
3535

@@ -82,11 +82,11 @@ def test_release_and_stash_leak():
8282
while True:
8383
stash1 = m.SftSharedPtrStash(1)
8484
stash1.Add(obj)
85-
assert obj.history == ""
85+
assert not obj.history
8686
assert m.use_count(obj) == 2
8787
assert stash1.use_count(0) == 1
8888
stash1.Add(obj)
89-
assert obj.history == ""
89+
assert not obj.history
9090
assert m.use_count(obj) == 3
9191
assert stash1.use_count(0) == 2
9292
assert stash1.use_count(1) == 2
@@ -117,10 +117,10 @@ def test_release_and_stash_via_shared_from_this_leak():
117117
stash1.AddSharedFromThis(obj)
118118
assert str(exc_info.value) == "bad_weak_ptr"
119119
stash1.Add(obj)
120-
assert obj.history == ""
120+
assert not obj.history
121121
assert stash1.use_count(0) == 1
122122
stash1.AddSharedFromThis(obj)
123-
assert obj.history == ""
123+
assert not obj.history
124124
assert stash1.use_count(0) == 2
125125
assert stash1.use_count(1) == 2
126126
break # Comment out for manual leak checking (use `top` command).
@@ -186,7 +186,7 @@ def test_multiple_registered_instances_for_same_pointee_leak():
186186
stash1.Add(m.Sft(obj0))
187187
assert stash1.use_count(0) == 1
188188
assert stash1.use_count(1) == 1
189-
assert obj0.history == ""
189+
assert not obj0.history
190190
break # Comment out for manual leak checking (use `top` command).
191191

192192

tests/test_iostream.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ def test_captured(capsys):
99
m.captured_output(msg)
1010
stdout, stderr = capsys.readouterr()
1111
assert stdout == msg
12-
assert stderr == ""
12+
assert not stderr
1313

1414
m.captured_output_default(msg)
1515
stdout, stderr = capsys.readouterr()
1616
assert stdout == msg
17-
assert stderr == ""
17+
assert not stderr
1818

1919
m.captured_err(msg)
2020
stdout, stderr = capsys.readouterr()
21-
assert stdout == ""
21+
assert not stdout
2222
assert stderr == msg
2323

2424

@@ -30,7 +30,7 @@ def test_captured_large_string(capsys):
3030
m.captured_output_default(msg)
3131
stdout, stderr = capsys.readouterr()
3232
assert stdout == msg
33-
assert stderr == ""
33+
assert not stderr
3434

3535

3636
def test_captured_utf8_2byte_offset0(capsys):
@@ -40,7 +40,7 @@ def test_captured_utf8_2byte_offset0(capsys):
4040
m.captured_output_default(msg)
4141
stdout, stderr = capsys.readouterr()
4242
assert stdout == msg
43-
assert stderr == ""
43+
assert not stderr
4444

4545

4646
def test_captured_utf8_2byte_offset1(capsys):
@@ -50,7 +50,7 @@ def test_captured_utf8_2byte_offset1(capsys):
5050
m.captured_output_default(msg)
5151
stdout, stderr = capsys.readouterr()
5252
assert stdout == msg
53-
assert stderr == ""
53+
assert not stderr
5454

5555

5656
def test_captured_utf8_3byte_offset0(capsys):
@@ -60,7 +60,7 @@ def test_captured_utf8_3byte_offset0(capsys):
6060
m.captured_output_default(msg)
6161
stdout, stderr = capsys.readouterr()
6262
assert stdout == msg
63-
assert stderr == ""
63+
assert not stderr
6464

6565

6666
def test_captured_utf8_3byte_offset1(capsys):
@@ -70,7 +70,7 @@ def test_captured_utf8_3byte_offset1(capsys):
7070
m.captured_output_default(msg)
7171
stdout, stderr = capsys.readouterr()
7272
assert stdout == msg
73-
assert stderr == ""
73+
assert not stderr
7474

7575

7676
def test_captured_utf8_3byte_offset2(capsys):
@@ -80,7 +80,7 @@ def test_captured_utf8_3byte_offset2(capsys):
8080
m.captured_output_default(msg)
8181
stdout, stderr = capsys.readouterr()
8282
assert stdout == msg
83-
assert stderr == ""
83+
assert not stderr
8484

8585

8686
def test_captured_utf8_4byte_offset0(capsys):
@@ -90,7 +90,7 @@ def test_captured_utf8_4byte_offset0(capsys):
9090
m.captured_output_default(msg)
9191
stdout, stderr = capsys.readouterr()
9292
assert stdout == msg
93-
assert stderr == ""
93+
assert not stderr
9494

9595

9696
def test_captured_utf8_4byte_offset1(capsys):
@@ -100,7 +100,7 @@ def test_captured_utf8_4byte_offset1(capsys):
100100
m.captured_output_default(msg)
101101
stdout, stderr = capsys.readouterr()
102102
assert stdout == msg
103-
assert stderr == ""
103+
assert not stderr
104104

105105

106106
def test_captured_utf8_4byte_offset2(capsys):
@@ -110,7 +110,7 @@ def test_captured_utf8_4byte_offset2(capsys):
110110
m.captured_output_default(msg)
111111
stdout, stderr = capsys.readouterr()
112112
assert stdout == msg
113-
assert stderr == ""
113+
assert not stderr
114114

115115

116116
def test_captured_utf8_4byte_offset3(capsys):
@@ -120,15 +120,15 @@ def test_captured_utf8_4byte_offset3(capsys):
120120
m.captured_output_default(msg)
121121
stdout, stderr = capsys.readouterr()
122122
assert stdout == msg
123-
assert stderr == ""
123+
assert not stderr
124124

125125

126126
def test_guard_capture(capsys):
127127
msg = "I've been redirected to Python, I hope!"
128128
m.guard_output(msg)
129129
stdout, stderr = capsys.readouterr()
130130
assert stdout == msg
131-
assert stderr == ""
131+
assert not stderr
132132

133133

134134
def test_series_captured(capture):
@@ -145,7 +145,7 @@ def test_flush(capfd):
145145
with m.ostream_redirect():
146146
m.noisy_function(msg, flush=False)
147147
stdout, stderr = capfd.readouterr()
148-
assert stdout == ""
148+
assert not stdout
149149

150150
m.noisy_function(msg2, flush=True)
151151
stdout, stderr = capfd.readouterr()
@@ -164,15 +164,15 @@ def test_not_captured(capfd):
164164
m.raw_output(msg)
165165
stdout, stderr = capfd.readouterr()
166166
assert stdout == msg
167-
assert stderr == ""
168-
assert stream.getvalue() == ""
167+
assert not stderr
168+
assert not stream.getvalue()
169169

170170
stream = StringIO()
171171
with redirect_stdout(stream):
172172
m.captured_output(msg)
173173
stdout, stderr = capfd.readouterr()
174-
assert stdout == ""
175-
assert stderr == ""
174+
assert not stdout
175+
assert not stderr
176176
assert stream.getvalue() == msg
177177

178178

@@ -182,16 +182,16 @@ def test_err(capfd):
182182
with redirect_stderr(stream):
183183
m.raw_err(msg)
184184
stdout, stderr = capfd.readouterr()
185-
assert stdout == ""
185+
assert not stdout
186186
assert stderr == msg
187-
assert stream.getvalue() == ""
187+
assert not stream.getvalue()
188188

189189
stream = StringIO()
190190
with redirect_stderr(stream):
191191
m.captured_err(msg)
192192
stdout, stderr = capfd.readouterr()
193-
assert stdout == ""
194-
assert stderr == ""
193+
assert not stdout
194+
assert not stderr
195195
assert stream.getvalue() == msg
196196

197197

@@ -221,21 +221,21 @@ def test_redirect(capfd):
221221
m.raw_output(msg)
222222
stdout, stderr = capfd.readouterr()
223223
assert stdout == msg
224-
assert stream.getvalue() == ""
224+
assert not stream.getvalue()
225225

226226
stream = StringIO()
227227
with redirect_stdout(stream), m.ostream_redirect():
228228
m.raw_output(msg)
229229
stdout, stderr = capfd.readouterr()
230-
assert stdout == ""
230+
assert not stdout
231231
assert stream.getvalue() == msg
232232

233233
stream = StringIO()
234234
with redirect_stdout(stream):
235235
m.raw_output(msg)
236236
stdout, stderr = capfd.readouterr()
237237
assert stdout == msg
238-
assert stream.getvalue() == ""
238+
assert not stream.getvalue()
239239

240240

241241
def test_redirect_err(capfd):
@@ -248,7 +248,7 @@ def test_redirect_err(capfd):
248248
m.raw_err(msg2)
249249
stdout, stderr = capfd.readouterr()
250250
assert stdout == msg
251-
assert stderr == ""
251+
assert not stderr
252252
assert stream.getvalue() == msg2
253253

254254

@@ -262,8 +262,8 @@ def test_redirect_both(capfd):
262262
m.raw_output(msg)
263263
m.raw_err(msg2)
264264
stdout, stderr = capfd.readouterr()
265-
assert stdout == ""
266-
assert stderr == ""
265+
assert not stdout
266+
assert not stderr
267267
assert stream.getvalue() == msg
268268
assert stream2.getvalue() == msg2
269269

0 commit comments

Comments
 (0)