Skip to content

Fix Python 3.11 compatibility and shared DualShock defaults - #4025

Open
sylvesterkaczmarek wants to merge 2 commits into
moveit:mainfrom
sylvesterkaczmarek:fix/dualshock-python311-defaults
Open

sylvesterkaczmarek wants to merge 2 commits into
moveit:mainfrom
sylvesterkaczmarek:fix/dualshock-python311-defaults

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Nov 29, 2026 •

Copy link
Copy Markdown

[written by AI]

Description

Fixes #4023. Use dataclass factories and a fresh default teleop configuration to prevent import errors and shared controller mappings. Order the teleoperation bases so the ROS Node comes before ABC, preserving import compatibility with newer ROS 2.

Checklist

  • Formatting and pre-commit checks
  • Regression tests for independent default configurations
  • Migration note for ROS Node inheritance
  • Tutorials and GUI screenshots (not applicable)
  • Review another open PR

Validation: two Python 3.12 tests pass after the fix; both previously failed at import. ROS imports were stubbed locally and the teleop initialization was mocked. Full ROS integration remains pending CI.

Rolling CI follow-up

The Rolling test job exposed an existing incompatible MRO: rclpy Node now derives from BaseNode, which derives from ABC. With ABC first, importing TeleopDevice fails before the new tests can run. Commit ee05ca5 puts Node first in the implementation and stub and tests that TeleopDevice remains abstract and its concrete DualShock subclass does not. The two original tests fail at import with the ABC-derived Node stand-in before this change; afterward all three tests pass with each of the ordinary and ABC-derived Node stand-ins (six passes). Changed-file pre-commit checks pass. Real ROS integration requires hosted CI.

The three Lyrical jobs in run 46210307095 fail earlier while linking moveit_msgs because libfastcdr.so.2.3.7 is absent from the ROS installation. No dependency or workflow changes are included.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed DualShock configuration defaults so separate controllers and teleoperation instances no longer share mutable settings.
    • Improved compatibility for Python teleoperation devices with newer ROS 2 versions.
  • Documentation
    • Added guidance for custom teleoperation devices on ROS 2 versions where rclpy.Node inherits from ABC.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PS4 DualShock client now creates independent default mappings and teleoperation configurations. The TeleopDevice base-class order is updated for ROS Rolling compatibility, with a migration note and unit test coverage.

Changes: DualShock defaults

Layer / File(s) Summary
Independent DualShock configuration
moveit_py/moveit/servo_client/devices/ps4_dualshock.py, moveit_py/moveit/servo_client/devices/ps4_dualshock.pyi, moveit_py/test/unit/test_dualshock_defaults.py, moveit_py/CMakeLists.txt
DualShock mappings use default factories, and PS4DualShockTeleop creates a fresh configuration when none is supplied. Type stubs reflect the optional defaults. Unit tests cover independent mappings and configurations, explicit configuration handling, and CMake registers the test.

Teleoperation inheritance compatibility

Layer / File(s) Summary
Node and ABC base-class order
moveit_py/moveit/servo_client/teleop.py, moveit_py/moveit/servo_client/teleop.pyi, moveit_py/test/unit/test_dualshock_defaults.py, MIGRATION.md
TeleopDevice lists Node before ABC in its implementation and type stub. A unit test checks its abstract status, and the migration notes describe the ordering for custom devices.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: peterdavidfagan, rhaschke

Merge Risk: Minimal · up to ee05c

This change fixes the Python 3.11+ import failure in the PS4 DualShock client and stops default mappings and teleoperation configurations from being shared between instances. It also reorders the TeleopDevice base classes for ROS Rolling compatibility. No merge-blocking risk is evident; full ROS integration still depends on CI.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names two changes that the changeset does make: Python 3.11 compatibility fixes (the mutable dataclass defaults are replaced with field(default_factory=...), and the TeleopDevice base-class …
Linked Issues check Passed [#4023] Requirement 1: the module imports on Python 3.11+. At the reviewed head, PS4DualShock.Axes and PS4DualShock.Buttons use field(default_factory=DualShockAxes) and `field(default_factory=Du…
Out of Scope Changes check Passed Changes at the reviewed head against merge base 5399d29:
- ps4_dualshock.py and ps4_dualshock.pyi: directly implement the #4023 default-sharing fix. In scope.
- `test/unit/test_dualshock_defaults.…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names two changes that the changeset does make: Python 3.11 compatibility fixes (the mutable dataclass defaults are replaced with field(default_factory=...), and the TeleopDevice base-class order is changed to Node before ABC) and independent DualShock defaults (the Axes/Buttons defaults are no longer shared, and PS4DualShockTeleop builds a fresh PS4DualShock when device_config is None). The title covers the main intent of PR #4025 and the linked issue #4023. It is a single, specific sentence and does not use vague terms.

Full details: Linked Issues check

Explanation

[#4023] Requirement 1: the module imports on Python 3.11+. At the reviewed head, PS4DualShock.Axes and PS4DualShock.Buttons use field(default_factory=DualShockAxes) and field(default_factory=DualShockButtons) in moveit_py/moveit/servo_client/devices/ps4_dualshock.py. This removes the mutable dataclass default that raised the ValueError. Static inspection supports this. The PR reports two Python 3.12 tests passing, but ROS imports were stubbed and CI integration is pending.

[#4023] Requirement 2: each default configuration owns its mappings. test_dualshock_mappings_are_independent checks that two default PS4DualShock() instances do not share Axes or Buttons. PS4DualShockTeleop.__init__ now defaults device_config to None and builds PS4DualShock() per instance. test_default_teleop_configs_are_independent checks distinct default configs and pass-through of an explicit config. The .pyi stub matches the new signature.

The issue describes the teleop constructor's shared default as a problem. That default is now fresh per call. No unmet coding requirement was found.

Full details: Out of Scope Changes check

Explanation

Changes at the reviewed head against merge base 5399d29:

  • ps4_dualshock.py and ps4_dualshock.pyi: directly implement the #4023 default-sharing fix. In scope.
  • test/unit/test_dualshock_defaults.py and the moveit_py/CMakeLists.txt registration: regression tests for #4023. In scope.
  • teleop.py and teleop.pyi: TeleopDevice base order changes from (ABC, Node) to (Node, ABC). The issue does not mention this change. It is an import-compatibility change. With rclpy.Node inheriting from ABC, the original order yields an inconsistent MRO at import time, so the change is connected to the requirement that the module imports. The test test_teleop_device_remains_abstract checks that the abstract status is kept.
  • MIGRATION.md: documents the base-order change for ROS Rolling. It is documentation for that change, so it is connected to it.

The base-order change and its migration note are only weakly tied to the issue text. They do not conflict with it. No demonstrated unrelated change was found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5399d29 and ee05ca5.

Files selected for processing: 7

  • MIGRATION.md
  • moveit_py/CMakeLists.txt
  • moveit_py/moveit/servo_client/devices/ps4_dualshock.py
  • moveit_py/moveit/servo_client/devices/ps4_dualshock.pyi
  • moveit_py/moveit/servo_client/teleop.py
  • moveit_py/moveit/servo_client/teleop.pyi
  • moveit_py/test/unit/test_dualshock_defaults.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@mergify

mergify Bot commented Nov 29, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@sylvesterkaczmarek

Copy link
Copy Markdown
Author

[written by AI]

The Rolling job exposed an MRO error importing TeleopDevice because the current rclpy Node already inherits ABC. I fixed the base-class order in ee05ca5, synchronized the type stub, and retained the abstract interface. The two original tests reproduced the import failure with an ABC-derived Node stand-in; all three tests now pass with both Node hierarchies, and scoped pre-commit checks pass. The three Lyrical failures are separate: moveit_msgs cannot link the missing libfastcdr.so.2.3.7. Fresh ROS CI is needed.

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.

PS4 DualShock client fails to import on Python 3.11 and newer

1 participant