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

[wpilib] Make robot base class functions protected #6645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

calcmogul
Copy link
Member

Users should be inheriting from these classes instead of directly instantiating them.

@calcmogul calcmogul requested a review from a team as a code owner May 21, 2024 19:58
Starlight220
Starlight220 previously approved these changes May 21, 2024
Copy link
Member

@virtuald virtuald left a comment

Choose a reason for hiding this comment

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

Changing functions from public to protected will break RobotPy and require workarounds to fix the resulting compilation errors.

I don't see why this is needed.

@calcmogul
Copy link
Member Author

calcmogul commented May 22, 2024

It prevents the user from doing obviously incorrect things. Why can't pybind11 handle protected methods?

@virtuald
Copy link
Member

virtuald commented May 22, 2024

Why does it matter what the user does? How often does this come up?

pybind11 can bind protected methods with a trampoline, but I think I would need an additional workaround to deal with protected constructors, as pybind11 tries to do the thing you're explicitly disabling -- instantiate the class from outside the class.

@calcmogul
Copy link
Member Author

calcmogul commented May 22, 2024

instantiate the class from outside the class

This is precisely what we're trying to prevent the user from doing at the API design level. It's a trivial change in C++/Java, which is why I made this PR as opposed to leaving it alone. Pybind11 is the one overcomplicating it.

Pybind11 shouldn't be instantiating the class directly; it should be inheriting from it instead. If that isn't possible in Pybind11, that seems like a pretty basic shortcoming of the tool. Perhaps those few classes should be written in Python instead so they can use inheritance as intended?

@calcmogul calcmogul force-pushed the wpilib-make-robot-base-class-functions-protected branch 3 times, most recently from 41a056c to b5fb738 Compare July 17, 2024 15:09
@calcmogul calcmogul force-pushed the wpilib-make-robot-base-class-functions-protected branch 2 times, most recently from f2657ce to be7b72a Compare September 13, 2024 01:41
@calcmogul calcmogul force-pushed the wpilib-make-robot-base-class-functions-protected branch 3 times, most recently from d9e02d8 to 53a57a5 Compare November 7, 2024 21:42
Users should be inheriting from these classes instead of directly
instantiating them.
@calcmogul calcmogul force-pushed the wpilib-make-robot-base-class-functions-protected branch from 53a57a5 to 3127ba9 Compare November 9, 2024 04:48
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.

3 participants