def _api_rename(node: LN, capture: Capture, filename: Filename): code = '' for leaf in node.leaves(): code = code + leaf.value found_rename = False found_warning = False api = None for _api in rename_map.keys(): if utils.startswith(code, _api): found_rename = True api = _api break for _api in warning_map.keys(): if utils.startswith(code, _api): found_warning = True api = _api break if not found_rename and not found_warning: return # if found rename, replace old_api with new_api if found_rename: utils.replace_module_path(node, api, rename_map[api]) # if not found rename and found warning, print warning elif found_warning: log_warning(filename, node.get_lineno(), warning_map[api])
def _print_warning(argument_node): if argument_node.type != python_symbols.argument: return if len(argument_node.children) == 3: key = argument_node.children[0].value if key in args_warning: warning_msg = args_warning[key] log_warning(filename, argument_node.get_lineno(), warning_msg)
def _remove_import(node: LN, capture: Capture, filename: Filename): if not is_import(node): return _node = capture.get('as_import', None) or capture.get( 'from_import', None) if _node is not None: prefix = _node.prefix p = _node.parent _node.remove() log_warning(filename, p.get_lineno(), 'remove "{}"'.format(utils.node2code(_node))) # delete NEWLINE node after delete as_import or from_import if p and p.children and len( p.children) == 1 and p.children[0].type == token.NEWLINE: p.children[0].remove() # restore comment p.next_sibling.prefix = prefix + p.next_sibling.prefix