<s> """<STR_LIT>""" <EOL> from . . pgen2 import token <EOL> from . . pygram import python_symbols as syms <EOL> from . . import fixer_base <EOL> from . . fixer_util import Name , Call , find_binding <EOL> bind_warning = "<STR_LIT>" <EOL> class FixNext ( fixer_base . BaseFix ) : <EOL> BM_compatible = True <EOL> PATTERN = """<STR_LIT>""" <EOL> order = "<STR_LIT>" <EOL> def start_tree ( self , tree , filename ) : <EOL> super ( FixNext , self ) . start_tree ( tree , filename ) <EOL> n = find_binding ( '<STR_LIT>' , tree ) <EOL> if n : <EOL> self . warning ( n , bind_warning ) <EOL> self . shadowed_next = True <EOL> else : <EOL> self . shadowed_next = False <EOL> def transform ( self , node , results ) : <EOL> assert results <EOL> base = results . get ( "<STR_LIT>" ) <EOL> attr = results . get ( "<STR_LIT>" ) <EOL> name = results . get ( "<STR_LIT:name>" ) <EOL> if base : <EOL> if self . shadowed_next : <EOL> attr . replace ( Name ( "<STR_LIT>" , prefix = attr . prefix ) ) <EOL> else : <EOL> base = [ n . clone ( ) for n in base ] <EOL> base [ <NUM_LIT:0> ] . prefix = "<STR_LIT>" <EOL> node . replace ( Call ( Name ( "<STR_LIT>" , prefix = node . prefix ) , base ) ) <EOL> elif name : <EOL> n = Name ( "<STR_LIT>" , prefix = name . prefix ) <EOL> name . replace ( n ) <EOL> elif attr : <EOL> if is_assign_target ( node ) : <EOL> head = results [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" . join ( [ str ( n ) for n in head ] ) . strip ( ) == '<STR_LIT>' : <EOL> self . warning ( node , bind_warning ) <EOL> return <EOL> attr . replace ( Name ( "<STR_LIT>" ) ) <EOL> elif "<STR_LIT>" in results : <EOL> self . warning ( node , bind_warning ) <EOL> self . shadowed_next = True <EOL> def is_assign_target ( node ) : <EOL> assign = find_assign ( node ) <EOL> if assign is None : <EOL> return False <EOL> for child in assign . children : <EOL> if child . type == token . EQUAL : <EOL> return False <EOL> elif is_subtree ( child , node ) : <EOL> return True <EOL> return False <EOL> def find_assign ( node ) : <EOL> if node . type == syms . expr_stmt : <EOL> return node <EOL> if node . type == syms . simple_stmt or node . parent is None : <EOL> return None <EOL> return find_assign ( node . parent ) <EOL> def is_subtree ( root , node ) : <EOL> if root == node : <EOL> return True <EOL> return any ( is_subtree ( c , node ) for c in root . children ) </s>
