Skip to content

Easily add comments to objects #900

@tjlaboss

Description

@tjlaboss

Is your feature request related to a problem? Please describe.

I'm always frustrated when...

...creating objects from scratch and forgetting what they mean. There is not a natural way to do this at the moment, as comments, leading_comments, and trailing_comment can only get and not set.

>>> c = Cell("1 0  +2 -3  imp:n=1  $ existing comment")
>>> c.comments
[COMMENT: $ existing comment]
>>> x = montepy.input_parser.syntax_node.CommentNode("c New comment")
>>> c.comments.insert(0, x)
>>> c.comments
[COMMENT: $ existing comment]
>>> c.comments += [x]
  File "./montepy/mcnp_object.py", line 49, in wrapped
    add_line_number_to_exception(e, self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "./montepy/exceptions.py", line 259, in add_line_number_to_exception
    raise error.with_traceback(trace)
  File "./montepy/mcnp_object.py", line 41, in wrapped
    return func(*args, **kwargs)
  File "./montepy/mcnp_object.py", line 150, in __setattr__
    descriptor.__set__(self, value)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
AttributeError: property 'comments' of 'Cell' object has no setter

Error came from CELL: 1, mat: 0, DENS: None from an unknown file.

Describe the solution you'd like

Easily append, prepend, or extend an object's comments.

>>> c = Cell("1 0  +2 -3  imp:n=1")
>>> c.comments.append("Potato")
>>> c.comments.insert(0, "Mashed")
>>> c.comments.extend(["yeah"])
>>> c.comments
[COMMENT: "c Mashed",
 COMMENT: "c Potato",
 COMMENT: "c yeah"]

Describe alternatives you've considered

  • Require the user to start a comment with a c or $ . If it starts with a c , it is a leading comment by default. If it starts with $ , it is an inline comment, of which only one should be allowed for now.
  • Add getter and setter for inline_comment(s). Require the user to set one of: inline_comment(s), leading_comments, or trailing_comment. Keep comments as a pure getter.
  • An additional category for comments native to objects: FCn and SCn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestAn issue that improves the user interface.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions