contrib/import-checker.py
changeset 29207 a09098c61fea
parent 29122 660d8d4ec7aa
child 29208 cba8bc11ed10
equal deleted inserted replaced
29206:0ec8501af800 29207:a09098c61fea
   454                 else:
   454                 else:
   455                     seenlocal = fullname
   455                     seenlocal = fullname
   456 
   456 
   457             # Direct symbol import is only allowed from certain modules and
   457             # Direct symbol import is only allowed from certain modules and
   458             # must occur before non-symbol imports.
   458             # must occur before non-symbol imports.
       
   459             found = fromlocal(node.module, node.level)
       
   460             if found and found[2]:  # node.module is a package
       
   461                 prefix = found[0] + '.'
       
   462                 symbols = [n.name for n in node.names
       
   463                            if not fromlocal(prefix + n.name)]
       
   464             else:
       
   465                 symbols = [n.name for n in node.names]
   459             if node.module and node.col_offset == root_col_offset:
   466             if node.module and node.col_offset == root_col_offset:
   460                 found = fromlocal(node.module, node.level)
       
   461                 if found and found[2]:  # node.module is a package
       
   462                     prefix = found[0] + '.'
       
   463                     symbols = [n.name for n in node.names
       
   464                                if not fromlocal(prefix + n.name)]
       
   465                 else:
       
   466                     symbols = [n.name for n in node.names]
       
   467 
       
   468                 if symbols and fullname not in allowsymbolimports:
   467                 if symbols and fullname not in allowsymbolimports:
   469                     yield msg('direct symbol import %s from %s',
   468                     yield msg('direct symbol import %s from %s',
   470                               ', '.join(symbols), fullname)
   469                               ', '.join(symbols), fullname)
   471 
   470 
   472                 if symbols and seennonsymbolrelative:
   471                 if symbols and seennonsymbolrelative: