Skip to content
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

DM-10384: Refactor pybind11 wrapper code into a single module. #14

Merged
merged 2 commits into from Oct 1, 2018

Conversation

TallJimbo
Copy link
Member

No description provided.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I have much useful to say about the refactored pybind11 itself. It probably would have been more useful to have the diff be between the old and new files directly, instead of deleted and added files.

This new style is going to take some care to make sure it's clear to developers what the different blocks of code/wrappers are.

});
cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
/* Members */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more whitespace to separate the various blocks would be handy in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

But just to satisfy my own curiosity: what about the extra whitespace in this context do you like? I tend to find the sections like this in the pybind11 annoying (I imagine @pschella started them and then they got copied), I suppose because I don't like things competing with the vertical whitespace between functions and classes without a very good reason. But I'm getting the impression I may be in the minority there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do like white space and that is where it came from (I guess). But it is also fine with me to remove it (not that it matters what I think, but still).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having some separation between logically-connected blocks of similar code. Makes it easier to find the thing you're looking for.

cls.def("clip", &Box2D::clip);
cls.def("getCorners", &Box2D::getCorners);
cls.def("toString", &Box2D::toString);
cls.def("__repr__", [](Box2D const &self) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little more whitespace; at least separate the stringification/dunder methods from the above block for clarity.

Copy link

@pschella pschella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just skimmed it to get the overall structure. I do like the approach, even if it is a bit boilerplate heavy. It does take it a bit further away from what pybind11 wrappers normally look like, and so I'm curious what the upstream developers think of this and if they had a different solution in mind for this kind of problem. But that of course should not stop us here.

mod.attr("ONE_OVER_PI") = py::float_(ONE_OVER_PI);
mod.attr("SQRTPI") = py::float_(SQRTPI);
mod.attr("INVSQRTPI") = py::float_(INVSQRTPI);
mod.attr("ROOT2") = py::float_(ROOT2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a wrapAttributes, or wrapConstants? This looks a bit confusing in a wrapFunctions block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point; what I really want is one word that means "module-scope things". Maybe just wrap would be better?

wrappers.wrapType(
PyAngle(wrappers.module, "Angle"),
[](auto & mod, auto & cls) mutable {
cls.def(py::init<double, AngleUnit>(), py::arg("val"), py::arg("units") = radians);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why py::arg instead of the literals? Remnant from the past?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just a remnant. Didn't even notice it until now.

});
cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
/* Members */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do like white space and that is where it came from (I guess). But it is also fine with me to remove it (not that it matters what I think, but still).

@TallJimbo
Copy link
Member Author

I'm curious what the upstream developers think of this and if they had a different solution in mind for this kind of problem

If I were them, my response would probably be, "oh, wow, why do you have so many circular dependencies? Stop doing that!"

It doesn't just do functions.
@TallJimbo TallJimbo merged commit 017a494 into master Oct 1, 2018
@TallJimbo TallJimbo deleted the tickets/DM-10384 branch October 1, 2018 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants