PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 2ms RepoModel.GetById 119ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_nonzero.py

http://unladen-swallow.googlecode.com/
Python | 20 lines | 15 code | 2 blank | 3 comment | 0 complexity | 6f8983345b023d63ddce248a93c5db83 MD5 | raw file
 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    PATTERN = """
10    classdef< 'class' any+ ':'
11              suite< any*
12                     funcdef< 'def' name='__nonzero__'
13                              parameters< '(' NAME ')' > any+ >
14                     any* > >
15    """
16
17    def transform(self, node, results):
18        name = results["name"]
19        new = Name("__bool__", prefix=name.get_prefix())
20        name.replace(new)