From ed43ca64652a7d64a4536ae5665e672ffcc7db4a Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Thu, 13 Aug 2026 18:10:19 +1000 Subject: [PATCH] fix: mvtbtool's %precision line spuriously echoes with --showassign "_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. --- src/machinevisiontoolbox/bin/mvtbtool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/machinevisiontoolbox/bin/mvtbtool.py b/src/machinevisiontoolbox/bin/mvtbtool.py index 98f02197..fa20f1ba 100755 --- a/src/machinevisiontoolbox/bin/mvtbtool.py +++ b/src/machinevisiontoolbox/bin/mvtbtool.py @@ -391,7 +391,8 @@ def out_prompt_tokens(self, cli=None): code = [ f"%matplotlib{' '+args.backend if args.backend is not None else ''}", "import matplotlib.pyplot as plt", - "_precision = %precision %.3g;", + "_prec = get_ipython().run_line_magic('precision', '%.3g'); " + "print(f'Default numeric formatting: {_prec}')", ] if args.base: code.append("from machinevisiontoolbox.base import *")