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

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

#countcontent
1n/a"""Fix "for x in f.xreadlines()" -> "for x in f".
2n/a
3n/aThis fixer will also convert g(f.xreadlines) into g(f.__iter__)."""
4n/a# Author: Collin Winter
5n/a
6n/a# Local imports
7n/afrom .. import fixer_base
8n/afrom ..fixer_util import Name
9n/a
10n/a
11n/aclass FixXreadlines(fixer_base.BaseFix):
12n/a BM_compatible = True
13n/a PATTERN = """
14n/a power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > >
15n/a |
16n/a power< any+ trailer< '.' no_call='xreadlines' > >
17n/a """
18n/a
19n/a def transform(self, node, results):
20n/a no_call = results.get("no_call")
21n/a
22n/a if no_call:
23n/a no_call.replace(Name("__iter__", prefix=no_call.prefix))
24n/a else:
25n/a node.replace([x.clone() for x in results["call"]])