I would like to extract all added comment lines for a specific file. In order to do this I extract all the comments with tokenize and ast.
Additionally, I would get all the added lines for this file from git show commit -- pathfile
.
I am having troubles to get the added comment lines, especially if they are just empty lines. My matching code looks like this:
addedCommentLinesPerFile = []
for commentline in parsedCommentLines:
for line in addedLinesList:
if commentline == line or commentline in line:
try:
parsedCommentLines.remove(commentline)
addedLinesList.remove(line)
except ValueError:
continue
addedCommentLinesPerFile.append(commentline)
Let's say my file would like this:
def function():
+ print("hello") #prints hello
+
"""
foo
"""
So the lists would look like this:
parsedCommentLines = ["#prints hello","foo",""]
addedLinesList = [' print("hello") #prints hello',""]
The desired output would be:
addedCommentLinesPerFile = ["#prints hello"]
But I would get:
addedCommentLinesPerFile = ["#prints hello",""]
parsedCommentLines
,addedLinesList
, etc. Also it's unclear what you mean by 'empty comment lines'.