Skip to content

fix: mvtbtool's %precision line spuriously echoes with --showassign - #79

Open
petercorke wants to merge 1 commit into
mainfrom
fix/mvtbtool-precision-echo
Open

fix: mvtbtool's %precision line spuriously echoes with --showassign#79
petercorke wants to merge 1 commit into
mainfrom
fix/mvtbtool-precision-echo

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

  • "_precision = %precision %.3g;" relied on the trailing ; to suppress output, but IPython's magic-line parsing swallows the entire rest of the line — including the ; — into %precision's own argument string, so it never actually functions as a suppression marker.
  • This stays latent by default (plain assignments aren't auto-displayed under IPython's default ast_node_interactivity), but surfaces the moment --showassign is passed: Out[1]: '%.3g;' prints right before the first real prompt.
  • Same class of bug just fixed in RTB's rtbtool (fix: rtbtool's %precision line spuriously echoes its own return value robotics-toolbox-python#592), originally found while doing the equivalent fix in RVC3-python's rvctool.
  • Fixed by wrapping the magic call in get_ipython().run_line_magic(...) and printing the result explicitly, so the line's last statement is a print() call — never auto-displayed regardless of ast_node_interactivity.

Test plan

  • mvtbtool (default) — confirmed clean, shows Default numeric formatting: %.3g
  • mvtbtool --showassign — confirmed clean too (this was the case that actually triggered the bug before)
  • pytest tests/test_bin.py — 6 passed, 3 skipped (optional deps not installed)

"_precision = %precision %.3g;" relied on the trailing ';' suppressing
output, but IPython's magic-line parsing swallows the whole rest of
the line -- including the ';' -- into %precision's own argument
string, so it never functions as a suppression marker. This stayed
latent by default (assignments aren't auto-displayed under the
default ast_node_interactivity), but surfaces the moment --showassign
is passed (same class of bug just fixed in rtbtool, and originally
found in RVC3-python's rvctool): Out[1]: '%.3g;' printed right before
the first real prompt.

Wrap the magic call in run_line_magic() and print the result
explicitly instead, so the last statement is a print() call, which is
never auto-displayed regardless of ast_node_interactivity.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant