-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: py::type::of<T>() and py::type::of(h) #2364
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
Changes from 5 commits
2f7b356
47c5485
7548f7a
3de181d
38729d0
e950722
636d5cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) | |||||||||||
| /* A few forward declarations */ | ||||||||||||
| class handle; class object; | ||||||||||||
| class str; class iterator; | ||||||||||||
| class type; | ||||||||||||
| struct arg; struct arg_v; | ||||||||||||
|
|
||||||||||||
| PYBIND11_NAMESPACE_BEGIN(detail) | ||||||||||||
|
|
@@ -890,6 +891,21 @@ class iterator : public object { | |||||||||||
| object value = {}; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class type : public object { | ||||||||||||
| public: | ||||||||||||
| PYBIND11_OBJECT_COMMON(type, object, PyType_Check) | ||||||||||||
|
|
||||||||||||
| explicit type(handle h): type((PyObject*) Py_TYPE(h.ptr()), borrowed_t{}) {} | ||||||||||||
| explicit type(object ob): type((PyObject*) Py_TYPE(ob.ptr()), borrowed_t{}) {} | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't necessary, I think?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, some slicing, since it's not by reference. But there are precedents for that, I think?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you/we choose to keep the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no, pybind11/include/pybind11/pytypes.h Lines 813 to 817 in cc982ac
How do we fix this such that it works in the intended way? When do we want
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I'll try dropping this overload soon)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤦 How did I miss that?
Probably, but I don't think it's necessary. |
||||||||||||
|
|
||||||||||||
| /// Convert C++ type to py::type if previously registered. Does not convert | ||||||||||||
| //standard types, like int, float. etc. yet. | ||||||||||||
|
henryiii marked this conversation as resolved.
Outdated
|
||||||||||||
| template<typename T> | ||||||||||||
| static type of(); | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| class iterable : public object { | ||||||||||||
| public: | ||||||||||||
| PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check) | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.