@@ -231,10 +231,7 @@ def _get_item_comments(self, key, val):
231231 """Get per-item comments for specified parameter name/value."""
232232 item_comments = {}
233233
234- cand_above_comments = list (self .comments ['iterabove' ].get (key , {}).items ())
235- cand_above_comments .extend (list (self .comments ['above' ].items ()))
236-
237- for comment_key , comment_val in cand_above_comments :
234+ for comment_key , comment_val in self .comments ['iterabove' ].get (key , {}).items ():
238235 if str (val ) in comment_key :
239236 item_comments ['above' ] = comment_val
240237
@@ -434,9 +431,10 @@ def grab_more_comment_lines(lines, param_key):
434431 self .comments ['above' ][last_param_key ] = comment
435432 else :
436433 # if the comment is not above a parameter definition,
437- # just use the whole next line to determine where the comment belongs...
434+ # then it must be a comment for an item of an iterable parameter value
438435 before_comment , _ = split_on_comment_hash (rawlines [0 ], last_param_key )
439- self .comments ['above' ][before_comment .rstrip ()] = comment
436+ comment_key = before_comment .rstrip ()
437+ self .comments ['iterabove' ].setdefault (last_param_key , {})[comment_key ] = comment
440438 else :
441439 # if there are no more lines, the comment (block) is at the tail
442440 self .comments ['tail' ] = comment
0 commit comments