Skip to content

Fix option_dict_to_string flag serialization (missing f-string)#804

Merged
DLWoodruff merged 1 commit into
Pyomo:mainfrom
DLWoodruff:fix-option-dict-to-string
Jul 16, 2026
Merged

Fix option_dict_to_string flag serialization (missing f-string)#804
DLWoodruff merged 1 commit into
Pyomo:mainfrom
DLWoodruff:fix-option-dict-to-string

Conversation

@DLWoodruff

Copy link
Copy Markdown
Collaborator

What

sputils.option_dict_to_string serialized a valueless (flag-style) option — one whose value is None — as the literal string {i} instead of the option's name. The None branch used a plain string literal where an f-string was intended:

if v is None:
    ostr += "{i} "        # emitted literal "{i}"
else:
    ostr += f"{i}={v} "

So, e.g., option_dict_to_string({'LogFile': None, 'mipgap': 0.01}) returned '{i} mipgap=0.01 '.

Fix

Use an f-string for the flag branch so flags serialize as their name and round-trip cleanly back through option_string_to_dict. The accumulator loop is collapsed into a single join while here.

return "".join(f"{k} " if v is None else f"{k}={v} "
               for k, v in odict.items())

Behavior is unchanged for the other cases and preserves the docstring's "None begets None, empty begets empty" contract:

input output
None None
{} ''
{'LogFile': None} 'LogFile '
{'mipgap': 0.01} 'mipgap=0.01 '
{'LogFile': None, 'mipgap': 0.01, 'threads': 4} 'LogFile mipgap=0.01 threads=4 '

All round-trip back through option_string_to_dict.

🤖 Generated with Claude Code

For a valueless (flag-style) option, option_dict_to_string emitted the
literal string "{i}" instead of the option name, because the None branch
used a plain string literal rather than an f-string. Flags now serialize
as their name and round-trip cleanly through option_string_to_dict.

Also collapsed the accumulator loop into a single join expression.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.18%. Comparing base (3174edf) to head (20f844a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #804      +/-   ##
==========================================
- Coverage   76.19%   76.18%   -0.01%     
==========================================
  Files         169      169              
  Lines       22268    22263       -5     
==========================================
- Hits        16966    16960       -6     
- Misses       5302     5303       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DLWoodruff
DLWoodruff merged commit a105686 into Pyomo:main Jul 16, 2026
32 checks passed
@DLWoodruff
DLWoodruff deleted the fix-option-dict-to-string branch July 16, 2026 18:36
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