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

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

#countcontent
1n/a"""Fixer that changes 'a ,b' into 'a, b'.
2n/a
3n/aThis also changes '{a :b}' into '{a: b}', but does not touch other
4n/auses of colons. It does not touch other uses of whitespace.
5n/a
6n/a"""
7n/a
8n/afrom .. import pytree
9n/afrom ..pgen2 import token
10n/afrom .. import fixer_base
11n/a
12n/aclass FixWsComma(fixer_base.BaseFix):
13n/a
14n/a explicit = True # The user must ask for this fixers
15n/a
16n/a PATTERN = """
17n/a any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
18n/a """
19n/a
20n/a COMMA = pytree.Leaf(token.COMMA, ",")
21n/a COLON = pytree.Leaf(token.COLON, ":")
22n/a SEPS = (COMMA, COLON)
23n/a
24n/a def transform(self, node, results):
25n/a new = node.clone()
26n/a comma = False
27n/a for child in new.children:
28n/a if child in self.SEPS:
29n/a prefix = child.prefix
30n/a if prefix.isspace() and "\n" not in prefix:
31n/a child.prefix = ""
32n/a comma = True
33n/a else:
34n/a if comma:
35n/a prefix = child.prefix
36n/a if not prefix:
37n/a child.prefix = " "
38n/a comma = False
39n/a return new