Closed
Description
With the addition of #2364, a very natural extension to py::type<T>()
would be py::type(h)
, mimicking py::cast
. I would propose we depreciate and eventually remove h.get_type()
in favor of py::type(h)
. Reasons:
- Free functions are generally better than member functions in C++; they are simpler, composable, etc.
- It would simplify the mixin, which currently gets added to several different classes, and keeps the API closer to Python.
h.str()
is already deprecated in favor ofpy:str(h)
.
It is only used internally, not publicly in any docs or tests, so to me it seems it would read better (more python like) and simplify the mixin.
For example, randomly picking one of the 10 places it's currently used:
if (!obj.get_type().is(matrix_type))
// Becomes
if (!py::type(obj).is(matrix_type))
For comparison, the Python would be:
if not type(obj) is matrix_type:
(Discussion moved from #2364).