home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Bureautique / LibreOffice / LibreOffice_4.3.5_Win_x86.msi / fix_nonzero.py < prev    next >
Text File  |  2014-12-12  |  597b  |  22 lines

  1. """Fixer for __nonzero__ -> __bool__ methods."""
  2. # Author: Collin Winter
  3.  
  4. # Local imports
  5. from .. import fixer_base
  6. from ..fixer_util import Name, syms
  7.  
  8. class 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("__bool__", prefix=name.prefix)
  21.         name.replace(new)
  22.