Skip to content

Fix docstring examples that do not parse as Python, and add a test that parses them - #1318

Open
Jeremy Rose (jeremyrose-viam) wants to merge 1 commit into
viamrobotics:mainfrom
jeremyrose-viam:fix-docstring-samples
Open

Jeremy Rose (jeremyrose-viam) wants to merge 1 commit into
viamrobotics:mainfrom
jeremyrose-viam:fix-docstring-samples

Conversation

@jeremyrose-viam

Copy link
Copy Markdown
Member

Docstring examples are shown on python.viam.dev and copied into other documentation, so readers paste them. 19 of the 330 :: example blocks in src/viam are not valid Python. This PR fixes only syntax, and adds a test so it stays that way.

Fixes

  1. Positional argument after keyword argument. from_robot(robot=machine, "my_detector") becomes from_robot(robot=machine, name="my_detector"). 14 call sites in Controller (4 methods), ServiceBase.do_command (inherited by the Discovery, Generic, Motion, SLAM, Vision, MLModel and WorldStateStore clients) and Vision (7 methods). from_robot(cls, robot, name) is unchanged; the examples were rewritten from from_robot(robot, "x") when "robot" became "machine" and picked up the keyword by mistake.
  2. Unquoted placeholders. get_invoices_summary(<ORG-ID>) becomes get_invoices_summary("<ORG-ID>"), the form other clients already use (for example part_id="<PART-ID>"). Affects BillingClient (class example, get_current_month_usage, get_invoice_pdf, get_invoices_summary, charge_organization) and DataClient.create_data_pipeline (["<YOUR-MQL-PIPELINE-AGGREGATION>"]).
  3. Missing commas. After start_time= and end_time= in DataClient.export_tabular_data, and after bbox_id= in DataClient.update_bounding_box.

Test

tests/test_docstring_examples.py collects every :: literal block from docstrings under src/viam (excluding gen/ and proto/) and runs ast.parse on it. On current main it fails for 19 blocks; with this change all 330 pass. It checks syntax only: it does not run examples or check argument names.

Not in this PR

Some examples parse but are still wrong, for example Motor.go_to uses revolutions= (the parameter is position_revolutions), Discovery.discover_resources passes a positional argument, and update_bounding_box calls the old name update_bounding_box_to_image_by_id. I left these for a separate change so this one stays mechanical.

Checks

pytest tests/test_docstring_examples.py and ruff check / ruff format --check on the test file pass. Docstring-only otherwise; no behavior change.

Notes

The "Code-Samples Warning" comment is expected: the PR touches input.py and vision.py, but only docstring text, not the functions listed in examples/apis.json.

🤖 Generated with Claude Code

…parses them

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base is_moving
board gpio_pin_by_name
button push
genericcomponent do_command
camera get_images
encoder get_position
motor is_moving
sensor get_readings
servo get_position
switch get_position
arm get_end_position
gantry get_lengths
gripper is_moving
movement_sensor get_linear_acceleration
input_controller get_controls
pose_tracker get_poses
power_sensor get_power
motion get_pose
vision get_properties
mlmodel metadata
genericservice do_command
slam get_point_cloud_map
audio_in get_properties
audio_out get_properties

@viambot

viambot commented Nov 25, 2026

Copy link
Copy Markdown
Member

👋 Thanks for requesting a review from the team!

We aim to review PRs within one business day. If this is urgent
or blocking you, please reach out in #team-sdk and
we'll prioritize it.

This branch has not been deployed

No deployments
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