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

[BUG-ish]: Python's duck typing hides a loud C++ API break #136

Open
gerth2 opened this issue Jan 15, 2025 · 4 comments
Open

[BUG-ish]: Python's duck typing hides a loud C++ API break #136

gerth2 opened this issue Jan 15, 2025 · 4 comments
Labels
package: wpimath subprojects/robotpy-wpimath

Comments

@gerth2
Copy link

gerth2 commented Jan 15, 2025

Problem description

2024: https://robotpy.readthedocs.io/projects/robotpy/en/2024.3.2.1/wpimath.controller/SimpleMotorFeedforwardMeters.html#wpimath.controller.SimpleMotorFeedforwardMeters.calculate

calculate(curVel, curAccel)

versus

2025: https://robotpy.readthedocs.io/projects/robotpy/en/stable/wpimath.controller/SimpleMotorFeedforwardMeters.html#wpimath.controller.SimpleMotorFeedforwardMeters.calculate

calculate(curVel, nextVel)

Here's where we got burned:

https://github.com/RobotCasserole1736/RobotCasserole2025/blob/902ba40f83ad67a8f2dd23db6c10b35afdf920c9/drivetrain/swerveModuleControl.py#L202

The change in API is mentioned (indirectly-ish) in the wpilib 2025 change notes (and shows up in the doc text for that function), so we were able to find it within ~30 minutes of debug.

However, per a quick chat with Peter, this is maybe something to consider, since the API break relied on C++'s units implementation, which is currently collapsed away in python.

I'm not sure what exactly could be done to help catch this in python in future years (typehinting checks?), but I also haven't thought about it a ton. I will do some more thinking/asking around, and make some comments if I have ideas.

Operating System

Windows

Installed Python Packages

N/A

Reproducible example code

See links above.
@auscompgeek auscompgeek added the package: wpimath subprojects/robotpy-wpimath label Jan 15, 2025
@auscompgeek
Copy link
Member

Hmm. It might be good for next year to make all the units names typing.NewTypes, so a type checker (e.g. mypy, pyright) is able to highlight mismatching units at development time.

@virtuald
Copy link
Member

The other way to catch this sort of thing is to write unit tests that cover all the APIs, but that's fairly unrealistic at this point I think.

@PeterJohnson
Copy link
Member

For this year it feels prudent to rename the function like what we did in Java? I’m a bit hesitant about requiring units in the wrappers as that’s likely going to be difficult to deal with in Blockly / beginner Python users?

@virtuald
Copy link
Member

To be consistent we'd have to rename anything that has units in it to something different -- and have it be some automated thing that way if the unit changes then the function name changes too.

We could consider such a thing for 2027, but tbh that doesn't sound great to me to do it everywhere, and if we did it manually then we could still run into this issue.

Elsewhere in RobotPy we use the default names and the default units for most functions, and when we add different unit overloads then we name them (which is usually something like fromFeet et al).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: wpimath subprojects/robotpy-wpimath
Projects
None yet
Development

No branches or pull requests

4 participants