Skip to content

Add get_by_comment method to NumberedObjectCollection - #1006

Open
digvijay-y wants to merge 4 commits into
idaholab:developfrom
digvijay-y:feat/search_by_comment
Open

digvijay-y wants to merge 4 commits into
idaholab:developfrom
digvijay-y:feat/search_by_comment

Conversation

@digvijay-y

@digvijay-y digvijay-y commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request Checklist for MontePy

Description

  • Add get_by_comment method to NumberedObjectCollection
  • Implemented a method to yield objects matching a comment string or regex pattern.
  • Added unit tests to validate functionality and error handling for the new method.

Fixes #982


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 25 or 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:
  • 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--1006.org.readthedocs.build/en/1006/

…ng tests

- Implemented a method to yield objects matching a comment string or regex pattern.
- Added unit tests to validate functionality and error handling for the new method.
@digvijay-y digvijay-y changed the title Add get_by_comment method to NumberedObjectCollection and correspondi… Add get_by_comment method to NumberedObjectCollection Sep 18, 2026
Signed-off-by: DIGVIJAY <144053736+digvijay-y@users.noreply.github.com>
@digvijay-y
digvijay-y marked this pull request as ready for review September 18, 2026 06:35
@digvijay-y
digvijay-y requested review from MicahGale and a lite review from Copilot and removed request for Copilot September 18, 2026 06:35
@MicahGale

Copy link
Copy Markdown
Collaborator

The test failure isn't your fault, but could you fix it while you have a PR open? The problem is that setuptools-scm changed their website structure. Could you change: https://setuptools-scm.readthedocs.io/en/latest/ to https://setuptools-scm.readthedocs.io/latest/ in the documentation?

@MicahGale MicahGale 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.

This is looking pretty good. Only that needs changed for sure is the changelog. Otherwise let's discuss the other concerns I had.

Comment thread doc/source/changelog.rst Outdated
Comment thread montepy/numbered_object_collection.py Outdated
Comment thread montepy/numbered_object_collection.py Outdated
Comment on lines +291 to +294
if not isinstance(searcher.pattern, str):
raise TypeError(
f"searcher must be a str, or a pattern compiled from a str. {searcher} given."
)

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.

Is it possible to make a pattern from not a string? I'm not familiar with when this branch would apply. Depending on the prevalence of re.compile(1) I would suggest simplifying this this logic, and just doing a basic type enforcement, and not worrying too much about how the pattern was compiled, but let's discuss if this case is common first.

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.

Technically it can by bytes (e.g. b"\[a-Z]+")

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.

I'm ok with allowing people to search with byte-strings. It might just find nothing.

cp_simple_problem.materials.check_number(-1)

def test_get_by_comment(self):
problem = montepy.read_input(os.path.join("tests", "inputs", "pin_cell.imcnp"))

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.

Is there a reason to use this test case over the test.imcnp given by the fixture read_simple_problem? I haven't looked at how many comments there are recently.

Comment thread tests/test_numbered_collection.py Outdated
Copilot AI lite review requested due to automatic review settings September 25, 2026 13:53
@digvijay-y
digvijay-y requested review from MicahGale and removed request for Copilot September 25, 2026 13:55

@MicahGale MicahGale 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.

Looking good overall. Patch coverage looks to be 100%. Just need to resolve that broken link discussion from earlier, and the one question I had about the test case.

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.

Implement a search by comment function

3 participants