mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-07 00:04:42 +00:00
feat: py::type::of<T>() and py::type::of(h) (#2364)
* feat: type<T>() * refactor: using py::type as class * refactor: py::object as base * wip: tigher api * refactor: fix conversion and limit API further * docs: some added notes from @EricCousineau-TRI * refactor: use py::type::of
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
.. _type-conversions:
|
||||
|
||||
Type conversions
|
||||
################
|
||||
|
||||
|
||||
@@ -1232,3 +1232,21 @@ appropriate derived-class pointer (e.g. using
|
||||
more complete example, including a demonstration of how to provide
|
||||
automatic downcasting for an entire class hierarchy without
|
||||
writing one get() function for each class.
|
||||
|
||||
Accessing the type object
|
||||
=========================
|
||||
|
||||
You can get the type object from a C++ class that has already been registered using:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
py::type T_py = py::type::of<T>();
|
||||
|
||||
You can directly use ``py::type::of(ob)`` to get the type object from any python
|
||||
object, just like ``type(ob)`` in Python.
|
||||
|
||||
.. note::
|
||||
|
||||
Other types, like ``py::type::of<int>()``, do not work, see :ref:`type-conversions`.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
|
||||
Reference in New Issue
Block a user