Skip to content

Commit 248b12e

Browse files
style: pre-commit fixes
1 parent dadbf05 commit 248b12e

File tree

7 files changed

+59
-27
lines changed

7 files changed

+59
-27
lines changed

include/pybind11/cast.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,12 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
346346
return PyLong_FromUnsignedLongLong((unsigned long long) src);
347347
}
348348

349-
PYBIND11_TYPE_CASTER(T,
350-
io_name<std::is_integral<T>::value>(
351-
"typing.SupportsInt | typing.SupportsIndex", "int", "typing.SupportsFloat | typing.SupportsIndex", "float"));
349+
PYBIND11_TYPE_CASTER(
350+
T,
351+
io_name<std::is_integral<T>::value>("typing.SupportsInt | typing.SupportsIndex",
352+
"int",
353+
"typing.SupportsFloat | typing.SupportsIndex",
354+
"float"));
352355
};
353356

354357
template <typename T>

include/pybind11/complex.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ class type_caster<std::complex<T>> {
7070
return PyComplex_FromDoubles((double) src.real(), (double) src.imag());
7171
}
7272

73-
PYBIND11_TYPE_CASTER(std::complex<T>, io_name("typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex", "complex"));
73+
PYBIND11_TYPE_CASTER(
74+
std::complex<T>,
75+
io_name("typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex",
76+
"complex"));
7477
};
7578
PYBIND11_NAMESPACE_END(detail)
7679
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

tests/test_builtin_casters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ TEST_SUBMODULE(builtin_casters, m) {
368368
[](std::complex<float> x) { return "({}, {})"_s.format(x.real(), x.imag()); },
369369
py::arg{}.noconvert());
370370

371-
m.def("complex_convert", [](std::complex<float> x) {return x;});
372-
m.def("complex_noconvert", [](std::complex<float> x) {return x;}, py::arg{}.noconvert());
371+
m.def("complex_convert", [](std::complex<float> x) { return x; });
372+
m.def("complex_noconvert", [](std::complex<float> x) { return x; }, py::arg{}.noconvert());
373373

374374
// test int vs. long (Python 2)
375375
m.def("int_cast", []() { return (int) 42; });

tests/test_builtin_casters.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ def __int__(self):
286286

287287
convert, noconvert = m.int_passthrough, m.int_passthrough_noconvert
288288

289-
assert doc(convert) == "int_passthrough(arg0: typing.SupportsInt | typing.SupportsIndex) -> int"
289+
assert (
290+
doc(convert)
291+
== "int_passthrough(arg0: typing.SupportsInt | typing.SupportsIndex) -> int"
292+
)
290293
assert doc(noconvert) == "int_passthrough_noconvert(arg0: int) -> int"
291294

292295
def requires_conversion(v):
@@ -326,7 +329,7 @@ def test_float_convert(doc):
326329
class Int:
327330
def __int__(self):
328331
return -5
329-
332+
330333
class Index:
331334
def __index__(self) -> int:
332335
return -7
@@ -336,7 +339,10 @@ def __float__(self):
336339
return 41.45
337340

338341
convert, noconvert = m.float_passthrough, m.float_passthrough_noconvert
339-
assert doc(convert) == "float_passthrough(arg0: typing.SupportsFloat | typing.SupportsIndex) -> float"
342+
assert (
343+
doc(convert)
344+
== "float_passthrough(arg0: typing.SupportsFloat | typing.SupportsIndex) -> float"
345+
)
340346
assert doc(noconvert) == "float_passthrough_noconvert(arg0: float) -> float"
341347

342348
def requires_conversion(v):
@@ -479,22 +485,18 @@ def test_complex_cast(doc):
479485
"""std::complex casts"""
480486

481487
class Complex:
482-
483488
def __complex__(self) -> complex:
484489
return complex(5, 4)
485-
486-
class Float:
487490

491+
class Float:
488492
def __float__(self) -> float:
489493
return 5.0
490-
491-
class Int:
492494

495+
class Int:
493496
def __int__(self) -> int:
494497
return 3
495-
496-
class Index:
497498

499+
class Index:
498500
def __index__(self) -> int:
499501
return 1
500502

@@ -516,7 +518,10 @@ def requires_conversion(v):
516518
def cant_convert(v):
517519
pytest.raises(TypeError, convert, v)
518520

519-
assert doc(convert) == "complex_convert(arg0: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> complex"
521+
assert (
522+
doc(convert)
523+
== "complex_convert(arg0: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> complex"
524+
)
520525
assert doc(noconvert) == "complex_noconvert(arg0: complex) -> complex"
521526

522527
assert convert(1) == 1.0
@@ -534,6 +539,7 @@ def cant_convert(v):
534539
requires_conversion(Float())
535540
requires_conversion(Index())
536541

542+
537543
def test_bool_caster():
538544
"""Test bool caster implicit conversions."""
539545
convert, noconvert = m.bool_passthrough, m.bool_passthrough_noconvert

tests/test_methods_and_attributes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,21 +534,27 @@ def test_overload_ordering():
534534
assert m.overload_order(0) == 4
535535

536536
assert (
537-
"1. overload_order(arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in m.overload_order.__doc__
537+
"1. overload_order(arg0: typing.SupportsInt | typing.SupportsIndex) -> int"
538+
in m.overload_order.__doc__
538539
)
539540
assert "2. overload_order(arg0: str) -> int" in m.overload_order.__doc__
540541
assert "3. overload_order(arg0: str) -> int" in m.overload_order.__doc__
541542
assert (
542-
"4. overload_order(arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in m.overload_order.__doc__
543+
"4. overload_order(arg0: typing.SupportsInt | typing.SupportsIndex) -> int"
544+
in m.overload_order.__doc__
543545
)
544546

545547
with pytest.raises(TypeError) as err:
546548
m.overload_order([])
547549

548-
assert "1. (arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in str(err.value)
550+
assert "1. (arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in str(
551+
err.value
552+
)
549553
assert "2. (arg0: str) -> int" in str(err.value)
550554
assert "3. (arg0: str) -> int" in str(err.value)
551-
assert "4. (arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in str(err.value)
555+
assert "4. (arg0: typing.SupportsInt | typing.SupportsIndex) -> int" in str(
556+
err.value
557+
)
552558

553559

554560
def test_rvalue_ref_param():

tests/test_pytypes.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,8 @@ def test_fn_return_only(doc):
989989

990990
def test_type_annotation(doc):
991991
assert (
992-
doc(m.annotate_type) == "annotate_type(arg0: type[typing.SupportsInt | typing.SupportsIndex]) -> type"
992+
doc(m.annotate_type)
993+
== "annotate_type(arg0: type[typing.SupportsInt | typing.SupportsIndex]) -> type"
993994
)
994995

995996

@@ -1167,7 +1168,10 @@ def get_annotations_helper(o):
11671168
def test_module_attribute_types() -> None:
11681169
module_annotations = get_annotations_helper(m)
11691170

1170-
assert module_annotations["list_int"] == "list[typing.SupportsInt | typing.SupportsIndex]"
1171+
assert (
1172+
module_annotations["list_int"]
1173+
== "list[typing.SupportsInt | typing.SupportsIndex]"
1174+
)
11711175
assert module_annotations["set_str"] == "set[str]"
11721176
assert module_annotations["foo"] == "pybind11_tests.pytypes.foo"
11731177

@@ -1190,7 +1194,10 @@ def test_get_annotations_compliance() -> None:
11901194

11911195
module_annotations = get_annotations(m)
11921196

1193-
assert module_annotations["list_int"] == "list[typing.SupportsInt | typing.SupportsIndex]"
1197+
assert (
1198+
module_annotations["list_int"]
1199+
== "list[typing.SupportsInt | typing.SupportsIndex]"
1200+
)
11941201
assert module_annotations["set_str"] == "set[str]"
11951202

11961203

@@ -1204,7 +1211,10 @@ def test_class_attribute_types() -> None:
12041211
instance_annotations = get_annotations_helper(m.Instance)
12051212

12061213
assert empty_annotations is None
1207-
assert static_annotations["x"] == "typing.ClassVar[typing.SupportsFloat | typing.SupportsIndex]"
1214+
assert (
1215+
static_annotations["x"]
1216+
== "typing.ClassVar[typing.SupportsFloat | typing.SupportsIndex]"
1217+
)
12081218
assert (
12091219
static_annotations["dict_str_int"]
12101220
== "typing.ClassVar[dict[str, typing.SupportsInt | typing.SupportsIndex]]"
@@ -1236,7 +1246,10 @@ def test_class_attribute_types() -> None:
12361246
def test_redeclaration_attr_with_type_hint() -> None:
12371247
obj = m.Instance()
12381248
m.attr_with_type_hint_float_x(obj)
1239-
assert get_annotations_helper(obj)["x"] == "typing.SupportsFloat | typing.SupportsIndex"
1249+
assert (
1250+
get_annotations_helper(obj)["x"]
1251+
== "typing.SupportsFloat | typing.SupportsIndex"
1252+
)
12401253
with pytest.raises(
12411254
RuntimeError, match=r'^__annotations__\["x"\] was set already\.$'
12421255
):

tests/test_type_caster_pyobject_ptr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def test_return_list_pyobject_ptr_reference():
103103

104104
def test_type_caster_name_via_incompatible_function_arguments_type_error():
105105
with pytest.raises(
106-
TypeError, match=r"1\. \(arg0: object, arg1: typing.SupportsInt | typing.SupportsIndex\) -> None"
106+
TypeError,
107+
match=r"1\. \(arg0: object, arg1: typing.SupportsInt | typing.SupportsIndex\) -> None",
107108
):
108109
m.pass_pyobject_ptr_and_int(ValueHolder(101), ValueHolder(202))
109110

0 commit comments

Comments
 (0)