Skip to content

Commit e950722

Browse files
committed
docs: some added notes from @EricCousineau-TRI
1 parent 38729d0 commit e950722

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

docs/advanced/cast/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _type-conversions:
2+
13
Type conversions
24
################
35

docs/advanced/classes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,4 +1245,8 @@ You can get the type object from a C++ class that has already been registered us
12451245
You can directly use ``py::type::of(ob)`` to get the type object from any python
12461246
object, just like ``type(ob)`` in Python.
12471247

1248+
.. note::
1249+
1250+
Other types, like ``py::type::of<int>``, do not work, see :ref:`type-conversions`.
1251+
12481252
.. versionadded:: 2.6

include/pybind11/pytypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ class type : public object {
901901
explicit type(object ob): type((PyObject*) Py_TYPE(ob.ptr()), borrowed_t{}) {}
902902

903903
/// Convert C++ type to py::type if previously registered. Does not convert
904-
//standard types, like int, float. etc. yet.
904+
// standard types, like int, float. etc. yet.
905+
// See https://github.com/pybind/pybind11/issues/2486
905906
template<typename T>
906907
static type of();
907908
};

tests/test_class.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ TEST_SUBMODULE(class_, m) {
139139
// test_type
140140
m.def("check_type", [](int category) {
141141
// Currently not supported (via a fail at compile time)
142+
// See https://github.com/pybind/pybind11/issues/2486
142143
// if (category == 2)
143144
// return py::type::of<int>();
144145
if (category == 1)

tests/test_class.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_type():
3535
assert 'Invalid' in str(execinfo.value)
3636

3737
# Currently not supported
38+
# See https://github.com/pybind/pybind11/issues/2486
3839
# assert m.check_type(2) == int
3940

4041

0 commit comments

Comments
 (0)