cmakelists_parsing icon indicating copy to clipboard operation
cmakelists_parsing copied to clipboard

AttributeError: 'Command' object has no attribute 'comments'

Open suurjaak opened this issue 3 years ago • 3 comments

Example run:

import cmakelists_parsing.parsing as cmp
cmp.parse("""include_directories(
  # aa
  include
)""")

Result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.8/site-packages/cmakelists_parsing/parsing.py", line 50, in parse
    nums_items = list(parse_file(nums_toks))
  File "/home/user/.local/lib/python3.8/site-packages/cmakelists_parsing/parsing.py", line 107, in parse_file
    line_nums, cmd = parse_command(line_num, tok_contents, toks)
  File "/home/user/.local/lib/python3.8/site-packages/cmakelists_parsing/parsing.py", line 142, in parse_command
    cmd.comments.append(c)
AttributeError: 'Command' object has no attribute 'comments'

Parser is misusing its own API: Command-objects have attribute comment not comments.

suurjaak avatar Apr 20 '21 17:04 suurjaak

I met the same issue.

ramwin avatar May 25 '22 06:05 ramwin

Just wanted to add that I am getting the same error.

Furthermore, if you change comments to comment then now the error becomes:

File "/home/<redacted>/git_clones/ros2-support/scripts/catkin-to-ament.py", line 235, in port
    cmake = cmkp.parse(content)
  File "/home/<redacted>/.local/lib/python3.8/site-packages/parse_cmake/parsing.py", line 104, in parse
    nums_items = list(parse_file(nums_toks))
  File "/home/<redacted>/.local/lib/python3.8/site-packages/parse_cmake/parsing.py", line 212, in parse_file
    line_nums, cmd = parse_command(line_num, tok_contents, toks)
  File "/home/<redacted>/.local/lib/python3.8/site-packages/parse_cmake/parsing.py", line 252, in parse_command
    cmd.comment.append(c)
AttributeError: 'NoneType' object has no attribute 'append'

vineet131 avatar Jun 06 '22 14:06 vineet131

Okay. To correct the issue:

L127 in parsing.py

cmd = Command(name=command_name, body=[], comment=[])

L142 in parsing.py

cmd.comment.append(c)

vineet131 avatar Jun 06 '22 14:06 vineet131