~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_nonzero.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)