Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 12, 2024
1 parent c5fd1cf commit d121043
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions include/pybind11/detail/descr.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ constexpr enable_if_t<!B, T2> const_name(const T1 &, const T2 &d) {
return d;
}

template <auto Bool, typename std::enable_if<std::is_same<decltype(Bool), bool>::value, int>::type = 0>
template <auto Bool,
typename std::enable_if<std::is_same<decltype(Bool), bool>::value, int>::type = 0>
auto constexpr const_name() {
return const_name<Bool>("True", "False");
}

template <auto Size, typename std::enable_if<std::is_same<decltype(Size), int>::value, int>::type = 0>
template <auto Size,
typename std::enable_if<std::is_same<decltype(Size), int>::value, int>::type = 0>
auto constexpr const_name() -> remove_cv_t<decltype(int_to_str<Size / 10, Size % 10>::digits)> {
return int_to_str<Size / 10, Size % 10>::digits;
}
Expand Down
6 changes: 4 additions & 2 deletions include/pybind11/typing.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@ struct handle_type_name<typing::Never> {
};

#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL)
template <auto StrLit, typename std::enable_if<std::is_same<decltype(StrLit), typing::StringLiteral>::value, int>::type = 0>
template <auto StrLit,
typename std::enable_if<std::is_same<decltype(StrLit), typing::StringLiteral>::value,
int>::type
= 0>
auto constexpr const_name() {
return const_name(StrLit.name);
}


template <typing::StringLiteral StrLit>
struct handle_type_name<typing::TypeVar<StrLit>> {
static constexpr auto name = const_name<StrLit>();
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ TEST_SUBMODULE(pytypes, m) {
#endif

#if defined(PYBIND11_CPP17)
m.def("annotate_literal", [](py::typing::Literal<3, 6, 1, 0, true, false> &o) -> py::object { return o; });
m.def("annotate_literal",
[](py::typing::Literal<3, 6, 1, 0, true, false> &o) -> py::object { return o; });

m.attr("PYBIND11_CPP17") = true;
#else
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,10 @@ def test_optional_object_annotations(doc):
def test_literal(doc):
assert (
doc(m.annotate_literal)
== 'annotate_literal(arg0: Literal[3, 6, 1, 0, True, False]) -> object'
== "annotate_literal(arg0: Literal[3, 6, 1, 0, True, False]) -> object"
)


@pytest.mark.skipif(
not m.defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL,
reason="C++20 non-type template args feature not available.",
Expand Down

0 comments on commit d121043

Please sign in to comment.