nodes: 0, module; 1, function_definition; 2, function_name:build_messages_modules; 3, parameters; 4, block; 5, identifier:messages; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, for_statement; 10, comment:"""Build and yield sorted list of messages per module.
  
      :param list messages: List of dict of messages
      :return: Tuple of 2 values: first is the module info, second is the list
               of messages sorted by line number
      """; 11, assignment; 12, identifier:line; 13, identifier:messages; 14, block; 15, pattern_list; 16, call; 17, block; 18, identifier:data; 19, call; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, identifier:module; 25, identifier:module_messages; 26, attribute; 27, argument_list; 28, expression_statement; 29, attribute; 30, argument_list; 31, assignment; 32, assignment; 33, assignment; 34, call; 35, identifier:data; 36, identifier:items; 37, yield; 38, identifier:collections; 39, identifier:defaultdict; 40, identifier:list; 41, identifier:module_name; 42, call; 43, identifier:module_path; 44, call; 45, identifier:module_info; 46, call; 47, attribute; 48, argument_list; 49, tuple; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, identifier:ModuleInfo; 55, argument_list; 56, subscript; 57, identifier:append; 58, identifier:line; 59, identifier:module; 60, call; 61, identifier:line; 62, identifier:get; 63, string; 64, identifier:line; 65, identifier:get; 66, string; 67, identifier:module_name; 68, identifier:module_path; 69, identifier:data; 70, identifier:module_info; 71, identifier:sorted; 72, argument_list; 73, string_content:module; 74, string_content:path; 75, identifier:module_messages; 76, keyword_argument; 77, identifier:key; 78, lambda; 79, lambda_parameters; 80, call; 81, identifier:x; 82, attribute; 83, argument_list; 84, identifier:x; 85, identifier:get; 86, string; 87, string_content:line
code: def build_messages_modules(messages):
      """Build and yield sorted list of messages per module.
  
      :param list messages: List of dict of messages
      :return: Tuple of 2 values: first is the module info, second is the list
               of messages sorted by line number
      """
      data = collections.defaultdict(list)
      for line in messages:
          module_name = line.get('module')
          module_path = line.get('path')
          module_info = ModuleInfo(
              module_name,
              module_path,
          )
          data[module_info].append(line)
  
      for module, module_messages in data.items():
          yield (
              module,
              sorted(module_messages, key=lambda x: x.get('line')))