(self, node: ast.Import, from_: str, to: str)
return self.wrapper.get_body(previous=node,  # type: ignore
                                     current=rewrote)[0]
Replace import with try/except with old and new import.
Replace import with try/except with old and new import.
Replace import with try / except with old and new import .
def _replace_import(self, node: ast.Import, from_: str, to: str) -> ast.Try:
        """Replace import with try/except with old and new import."""
        self._tree_changed = True

        rewrote_name = node.names[0].name.replace(from_, to, 1)
        import_as = node.names[0].asname or node.names[0].name.split('.')[-1]

        rewrote = ast.Import(names=[
            ast.alias(name=rewrote_name,
                      asname=import_as)])

        return self.wrapper.get_body(previous=node,  # type: ignore
                                     current=rewrote)[0]
def _replace_import ( self , node : ast . Import , from_ : str , to : str ) -> ast . Try : self . _tree_changed = True rewrote_name = node . names [ 0 ] . name . replace ( from_ , to , 1 ) import_as = node . names [ 0 ] . asname or node . names [ 0 ] . name . split ( '.' ) [ - 1 ] rewrote = ast . Import ( names = [ ast . alias ( name = rewrote_name , asname = import_as ) ] ) return self . wrapper . get_body ( previous = node , # type: ignore current = rewrote ) [ 0 ]