ยปCore Development>Code coverage>Lib/lib2to3/fixes/fix_nonzero.py

Python code coverage for Lib/lib2to3/fixes/fix_nonzero.py

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