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

Adds Swerve2/3/4/6ControllerCommand to Commands2 #38

Closed
wants to merge 15 commits into from

Conversation

lospugs
Copy link
Contributor

@lospugs lospugs commented Dec 8, 2023

#28

This class is provided by the NewCommands VendorDep
"""

def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

I think this would benefit from the @overload approach too.

An easy way to see what they should look like is download the 2023 commands whl file, unzip it, and peek at commands2/_impl/__init__.pyi which has all of the definitions that the prior version defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually had no idea that @overload existed. If you haven't figured it out yet, not a Python programmer :)

Hopefully tomorrow I can work up some updates for the other PRs as well that will hopefully make this much cleaner than me just creating overloads by arbitrarily forcing optional arguments to be required in certain permutations.

Copy link
Member

Choose a reason for hiding this comment

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

Well, overload brings its own share of troubles -- it's just for the type checker, you still have to figure out which set of parameters are incoming.

See

def __init__(self, *args, **kwargs):
for how it was used elsewhere here. It would be nice if there was a generic way to validate/parse them, but there isn't yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just pushed a change to this one implementing overload.

I don't know if this is too much of a breaking change, but I forced kwargs for all the non-positional arguments and then added the overload for the type checker. I added more tests to validate, and it seems to "work".

I don't know enough about Python that by explicitly making the subsystem a Tuple and forcing kwargs, what that does on the other end of things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out the type checker was not happy about it in Mypy, though when stepping through with a debugger, both in my force Tuple, and in the status quo (before the Tuple change) at runtime addRequirements receives a tuple[Subsystem] as it's type, not a Subsystem (which is what the type checker in Mypy says is required.

Copy link
Member

Choose a reason for hiding this comment

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

It's important to remember that type checking is not enforced at runtime, so running code can sometimes work perfectly fine even if mypy is very angry about it. The primary utility of type hints is twofold: often mypy/pyright is right and type errors indicate that you should fix something (and you can find out before running the code), and it also serves as a useful API documentation to indicate what the function is expecting to receive.

I think we should investigate https://github.com/gabrieldemarmiesse/overtake + beartype to see if we can make this multiple dispatch stuff easier to write.

@lospugs lospugs force-pushed the swervecontrollercommand branch 3 times, most recently from 2d59765 to 3a8432e Compare December 11, 2023 17:06
@lospugs
Copy link
Contributor Author

lospugs commented Dec 30, 2023

Any idea what is going on here with the tests? I can run them locally in the VS Code test runner, and they also run successfully from the command line:

robotpy-commands-fork % python -m pytest
============================================================================= test session starts ==============================================================================
platform darwin -- Python 3.11.6, pytest-7.4.3, pluggy-1.3.0
rootdir: /Users/user/robotics/robotpy-commands-fork
plugins: reraise-2.1.2
collected 164 items                                                                                                                                                            

tests/test_command_decorators.py .....s..........                                                                                                                        [  9%]
tests/test_command_requirements.py ...                                                                                                                                   [ 11%]
tests/test_command_schedule.py .....                                                                                                                                     [ 14%]
tests/test_commandgroup_error.py ...                                                                                                                                     [ 16%]
tests/test_conditional_command.py ..                                                                                                                                     [ 17%]
tests/test_default_command.py ...                                                                                                                                        [ 19%]
tests/test_functional_command.py .                                                                                                                                       [ 20%]
tests/test_instant_command.py .                                                                                                                                          [ 20%]
tests/test_networkbutton.py .                                                                                                                                            [ 21%]
tests/test_notifier_command.py s                                                                                                                                         [ 21%]
tests/test_parallelcommandgroup.py .............                                                                                                                         [ 29%]
tests/test_paralleldeadlinegroup.py ............                                                                                                                         [ 37%]
tests/test_parallelracegroup.py ...............                                                                                                                          [ 46%]
tests/test_perpetualcommand.py .                                                                                                                                         [ 46%]
tests/test_pidcommand.py ...                                                                                                                                             [ 48%]
tests/test_printcommand.py .                                                                                                                                             [ 49%]
tests/test_proxycommand.py ..                                                                                                                                            [ 50%]
tests/test_repeatcommand.py .                                                                                                                                            [ 51%]
tests/test_robotdisabledcommand.py .......                                                                                                                               [ 55%]
tests/test_runcommand.py .                                                                                                                                               [ 56%]
tests/test_schedulecommand.py ..                                                                                                                                         [ 57%]
tests/test_scheduler.py .....                                                                                                                                            [ 60%]
tests/test_schedulingrecursion.py .........                                                                                                                              [ 65%]
tests/test_selectcommand.py ...........                                                                                                                                  [ 72%]
tests/test_sequentialcommandgroup.py ............                                                                                                                        [ 79%]
tests/test_startendcommand.py .                                                                                                                                          [ 80%]
tests/test_swervecontrollercommand.py ..................                                                                                                                 [ 91%]
tests/test_trigger.py ...........                                                                                                                                        [ 98%]
tests/test_waitcommand.py ..                                                                                                                                             [ 99%]
tests/test_waituntilcommand.py .                                                                                                                                         [100%]

======================================================================== 162 passed, 2 skipped in 0.81s ========================================================================

I tried making a Python 3.8 virtual environment on my apple silicon mac, but for some reason can't install robotpy betas with pip in the 3.8 virtual environment, it can't install robotpy-wpiutil for some reason (can't find the package).

In the meantime I'll try to build a VM with an older Ubuntu or something, but it's very confusing why the TypeErrors don't exist in my local test runs but they fail on the Ubuntu machines.

@lospugs
Copy link
Contributor Author

lospugs commented Dec 30, 2023

So, I experimented with that exact fix, but when I did that fix I actually had failures locally both in VS Code's test runner and running python -m pytest. What I pushed originally was in response to local failures...but I guess it's good they work in the CI/CD pipeline.

Macos 13, apple silicon, Python 3.11 (installed via Homebrew).

Edit to add: Confirmed running an amd64 VM via hypervisor. The behavior of Python 3.11 on Apple Silicon is for some reason opposite of the intel-based systems. Which is suprising.

@virtuald
Copy link
Member

The swerve APIs changed in beta 4 (robotpy/mostrobotpy#43), so you might not have upgraded your local robotpy installation.

@virtuald
Copy link
Member

Closing in favor of #45 (which was built on this, so thanks)

@virtuald virtuald closed this Jan 20, 2024
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.

2 participants