1"""Fixer for __nonzero__ -> __bool__ methods.""" 2# Author: Collin Winter 3 4# Local imports 5from .. import fixer_base 6from ..fixer_util import Name, syms 7 8class FixNonzero(fixer_base.BaseFix): 9 BM_compatible = True 10 PATTERN = """ 11 classdef< 'class' any+ ':' 12 suite< any* 13 funcdef< 'def' name='__nonzero__' 14 parameters< '(' NAME ')' > any+ > 15 any* > > 16 """ 17 18 def transform(self, node, results): 19 name = results["name"] 20 new = Name(u"__bool__", prefix=name.prefix) 21 name.replace(new) 22