Skip to content

Fixed how data block importances handle trailing comments. - #1049

Merged
MicahGale merged 8 commits into
patch_devfrom
imp_trail_comment
Nov 5, 2026
Merged

MicahGale merged 8 commits into
patch_devfrom
imp_trail_comment

Conversation

@MicahGale

@MicahGale MicahGale commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request Checklist for MontePy

Description

This fixes a bug with how Importance handles syntax trees while in the data block. This is one of the most complicated CellModifierInputs. Importance stores multiple copies of its syntax trees in two dictionaries, because all importances of all particle types get stored by a single object, and then at export this is split back into multiple outputs as needed.

The issue was that the trailing comments were pulled from _real_tree, but were not being cleared from _real_tree. In updating this it was decided that it was better for _real_tree and _particle_importances to be the same objects in the data block version. This is because the distinction is only necessary where the data is actually mutating; in the cell block. So, here it is safe for both to point to the same objects, and then ensure that _real_tree has its trailing comment cleared. Also another test had to be updated because it accidentally had duplicate comments baked into the expected output.

Also this tackles the shortcut recompression bug, which was related, but not quite common-mode failure.

During the _update_values process when two trees can be printed as the same one tree was used to replace both copies. This broke the pointers from one of the trees to its ValueNodes, which breaks shortcut recompression which relies on id. Rather than replacing one tree with the other this now simply updates both trees with the proper particle classifier data, then when formatting the logic automatically uses these particle lists to determine if the next tree needs to be printed.

Fixes #1048.
Fixes #397.


General Checklist

  • I have performed a self-review of my own code.
  • The code follows the standards outlined in the development documentation.
  • I have formatted my code with black version 26.
  • I have added tests that prove my fix is effective or that my feature works (if applicable).

LLM Disclosure

  1. Are you?

    • A human user
    • A large language model (LLM), including ones acting on behalf of a human
  2. Were any large language models (LLM or "AI") used in to generate any of this code?

  • Yes
    • Model(s) used: Opus 5.5
    • Harness used: medium
    • Reasoning effort: Claude code
  • No

Documentation Checklist

  • I have documented all added classes and methods.
  • I have added type hints to all functions as needed.
  • I have marked all changes with the .. versionchanged:: or .. versionadded:: directives.

Infrastructure Changes

  • For infrastructure updates, I have updated the developer's guide.

Significant features or Behavior changes

  • For significant new features, I have added a section to the getting started guide.

First-Time Contributor Checklist

  • If this is your first contribution, add yourself to pyproject.toml if you wish to do so.

Additional Notes for Reviewers

Ensure that:

  • This PR fully addresses and resolves the referenced issue(s).
  • The submitted code is consistent with the merge checklist outlined here.
  • The PR covers all relevant aspects according to the development guidelines.
  • 100% coverage of the patch is achieved, or justification for a variance is given.

📚 Documentation preview 📚: https://montepy--1049.org.readthedocs.build/en/1049/

@MicahGale MicahGale self-assigned this Nov 5, 2026
@MicahGale MicahGale added bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error". bugs of unusual importance Bugs related to the Rube Goldberg machine that is the Importance class. prettification 🦋 Priority 4. Make it pretty labels Nov 5, 2026
@MicahGale
MicahGale requested a review from tjlaboss November 5, 2026 04:50
@MicahGale
MicahGale marked this pull request as ready for review November 5, 2026 04:50
@MicahGale
MicahGale changed the base branch from develop to patch_dev November 5, 2026 05:17
MicahGale and others added 5 commits November 5, 2026 08:38
Share the data-block _real_tree with _particle_importances and delete
the trailing comment from both, so the comment is no longer duplicated
after the next input's leading comment is moved.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MicahGale
MicahGale marked this pull request as draft November 5, 2026 15:41
@MicahGale MicahGale linked an issue Nov 5, 2026 that may be closed by this pull request
@MicahGale

Copy link
Copy Markdown
Collaborator Author

Coveralls: https://coveralls.io/jobs/191002258

@MicahGale
MicahGale marked this pull request as ready for review November 5, 2026 17:01

@tjlaboss tjlaboss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, closing out some old issues.

@MicahGale
MicahGale merged commit cb5841a into patch_dev Nov 5, 2026
20 checks passed
@MicahGale
MicahGale deleted the imp_trail_comment branch November 5, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugs of unusual importance Bugs related to the Rube Goldberg machine that is the Importance class. bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error". prettification 🦋 Priority 4. Make it pretty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments after an imp input are duplicated on every write Importance not recompressing Shortcuts on export

2 participants