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