-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor: Replace h.get_type()
with py::type(h)
#2388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
👍 Yup, you already convinced me in #2364! ;-) |
Technically, I think that issue would be solved by |
Right, but I'm thinking we could create a |
Then we would lose |
Agh, I had naively thought/hoped you could make make a templated Best I can then think of is: class type {
public:
template <typename T>
static type of() { return type(typeid(T)); }
explicit type(const std::type_info &type_info) : m_type_info(type_info) {}
void print() {
std::cout << m_type_info.name() << std::endl;
}
private:
const std::type_info& m_type_info;
}; This Not sure if that's worth it, but I do like the conformity of having a |
I'd be okay with |
FWIW: I looked in the Google codebase: I see |
I know :-/ I'm quite conflicted as well. I quite like how @wjakob, any thoughts on this? Having |
+1 for this interface in general. I'm kind of torn about the specifics of naming it as well, but leaning slightly towards consistency with |
With the addition of #2364, a very natural extension to
py::type<T>()
would bepy::type(h)
, mimickingpy::cast
. I would propose we depreciate and eventually removeh.get_type()
in favor ofpy::type(h)
. Reasons: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:
For comparison, the Python would be:
(Discussion moved from #2364).
The text was updated successfully, but these errors were encountered: