Rename user_type to UserType

This commit is contained in:
Ralf W. Grosse-Kunstleve 2023-11-14 14:08:59 -08:00
parent 11040768ca
commit e5f210e61b
2 changed files with 25 additions and 25 deletions

View File

@ -5,25 +5,25 @@
namespace test_cases_for_stubgen {
struct user_type {
bool operator<(const user_type &) const { return false; }
struct UserType {
bool operator<(const UserType &) const { return false; }
};
struct minimal_caster {
static constexpr auto name = py::detail::const_name<user_type>();
static constexpr auto name = py::detail::const_name<UserType>();
static py::handle
cast(user_type const & /*src*/, py::return_value_policy /*policy*/, py::handle /*parent*/) {
cast(UserType const & /*src*/, py::return_value_policy /*policy*/, py::handle /*parent*/) {
return py::none().release();
}
// Maximizing simplicity. This will go terribly wrong for other arg types.
template <typename>
using cast_op_type = const user_type &;
using cast_op_type = const UserType &;
// NOLINTNEXTLINE(google-explicit-constructor)
operator user_type const &() {
static user_type obj;
operator UserType const &() {
static UserType obj;
return obj;
}
@ -36,19 +36,19 @@ namespace pybind11 {
namespace detail {
template <>
struct type_caster<test_cases_for_stubgen::user_type> : test_cases_for_stubgen::minimal_caster {};
struct type_caster<test_cases_for_stubgen::UserType> : test_cases_for_stubgen::minimal_caster {};
} // namespace detail
} // namespace pybind11
TEST_SUBMODULE(cases_for_stubgen, m) {
using namespace test_cases_for_stubgen;
using UserType = test_cases_for_stubgen::UserType;
m.def("pass_user_type", [](const user_type &) {});
m.def("return_user_type", []() { return user_type(); });
m.def("pass_user_type", [](const UserType &) {});
m.def("return_user_type", []() { return UserType(); });
py::bind_map<std::map<int, user_type>>(m, "MapIntUserType");
py::bind_map<std::map<user_type, int>>(m, "MapUserTypeInt");
py::bind_map<std::map<int, UserType>>(m, "MapIntUserType");
py::bind_map<std::map<UserType, int>>(m, "MapUserTypeInt");
#define MAP_TYPE(MapTypePythonName, ...) \
py::class_<__VA_ARGS__>(m, MapTypePythonName) \
@ -65,8 +65,8 @@ TEST_SUBMODULE(cases_for_stubgen, m) {
[](const __VA_ARGS__ &v) { return py::make_iterator(v.begin(), v.end()); }, \
py::keep_alive<0, 1>())
MAP_TYPE("MapFloatUserType", std::map<float, user_type>);
MAP_TYPE("MapUserTypeFloat", std::map<user_type, float>);
MAP_TYPE("MapFloatUserType", std::map<float, UserType>);
MAP_TYPE("MapUserTypeFloat", std::map<UserType, float>);
#undef MAP_TYPE
}

View File

@ -9,11 +9,11 @@ from pybind11_tests import stl as test_stl
[
(
m.pass_user_type.__doc__,
'pass_user_type(arg0: Annotated[Any, "test_cases_for_stubgen::user_type"]) -> None\n',
'pass_user_type(arg0: Annotated[Any, "test_cases_for_stubgen::UserType"]) -> None\n',
),
(
m.return_user_type.__doc__,
'return_user_type() -> Annotated[Any, "test_cases_for_stubgen::user_type"]\n',
'return_user_type() -> Annotated[Any, "test_cases_for_stubgen::UserType"]\n',
),
(
m.MapIntUserType.keys.__doc__,
@ -21,15 +21,15 @@ from pybind11_tests import stl as test_stl
),
(
m.MapIntUserType.values.__doc__,
'values(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ValuesView[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n',
'values(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ValuesView[Annotated[Any, "test_cases_for_stubgen::UserType"]]\n',
),
(
m.MapIntUserType.items.__doc__,
'items(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ItemsView[int, Annotated[Any, "test_cases_for_stubgen::user_type"]]\n',
'items(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ItemsView[int, Annotated[Any, "test_cases_for_stubgen::UserType"]]\n',
),
(
m.MapUserTypeInt.keys.__doc__,
'keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.KeysView[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n',
'keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.KeysView[Annotated[Any, "test_cases_for_stubgen::UserType"]]\n',
),
(
m.MapUserTypeInt.values.__doc__,
@ -37,7 +37,7 @@ from pybind11_tests import stl as test_stl
),
(
m.MapUserTypeInt.items.__doc__,
'items(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.ItemsView[Annotated[Any, "test_cases_for_stubgen::user_type"], int]\n',
'items(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.ItemsView[Annotated[Any, "test_cases_for_stubgen::UserType"], int]\n',
),
(
m.MapFloatUserType.keys.__doc__,
@ -45,15 +45,15 @@ from pybind11_tests import stl as test_stl
),
(
m.MapFloatUserType.values.__doc__,
'values(self: pybind11_tests.cases_for_stubgen.MapFloatUserType) -> Iterator[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n',
'values(self: pybind11_tests.cases_for_stubgen.MapFloatUserType) -> Iterator[Annotated[Any, "test_cases_for_stubgen::UserType"]]\n',
),
(
m.MapFloatUserType.__iter__.__doc__,
'__iter__(self: pybind11_tests.cases_for_stubgen.MapFloatUserType) -> Iterator[tuple[float, Annotated[Any, "test_cases_for_stubgen::user_type"]]]\n',
'__iter__(self: pybind11_tests.cases_for_stubgen.MapFloatUserType) -> Iterator[tuple[float, Annotated[Any, "test_cases_for_stubgen::UserType"]]]\n',
),
(
m.MapUserTypeFloat.keys.__doc__,
'keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeFloat) -> Iterator[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n',
'keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeFloat) -> Iterator[Annotated[Any, "test_cases_for_stubgen::UserType"]]\n',
),
(
m.MapUserTypeFloat.values.__doc__,
@ -61,7 +61,7 @@ from pybind11_tests import stl as test_stl
),
(
m.MapUserTypeFloat.__iter__.__doc__,
'__iter__(self: pybind11_tests.cases_for_stubgen.MapUserTypeFloat) -> Iterator[tuple[Annotated[Any, "test_cases_for_stubgen::user_type"], float]]\n',
'__iter__(self: pybind11_tests.cases_for_stubgen.MapUserTypeFloat) -> Iterator[tuple[Annotated[Any, "test_cases_for_stubgen::UserType"], float]]\n',
),
(
test_stl.cast_array.__doc__,