20
20
# Author: Collin Winter, Armin Ronacher
21
21
from __future__ import absolute_import
22
22
23
- # Local imports
24
- from lib2to3 import pytree , fixer_base
25
- from lib2to3 .pgen2 import token
26
- from lib2to3 .fixer_util import Name , Call , is_tuple
23
+ from lib2to3 .fixes import fix_raise
27
24
28
- class FixRaise (fixer_base . BaseFix ):
29
-
30
- BM_compatible = True
25
+ class FixRaise (fix_raise . FixRaise ):
26
+ # We don't want to match 3-argument raise, with a traceback;
27
+ # that is handled separately by fix_raise_six
31
28
PATTERN = """
32
29
raise_stmt< 'raise' exc=any [',' val=any] >
33
- """
34
-
35
- def transform (self , node , results ):
36
- syms = self .syms
37
-
38
- exc = results ["exc" ].clone ()
39
- if exc .type == token .STRING :
40
- msg = "Python 3 does not support string exceptions"
41
- self .cannot_convert (node , msg )
42
- return
43
-
44
- # Python 2 supports
45
- # raise ((((E1, E2), E3), E4), E5), V
46
- # as a synonym for
47
- # raise E1, V
48
- # Since Python 3 will not support this, we recurse down any tuple
49
- # literals, always taking the first element.
50
- if is_tuple (exc ):
51
- while is_tuple (exc ):
52
- # exc.children[1:-1] is the unparenthesized tuple
53
- # exc.children[1].children[0] is the first element of the tuple
54
- exc = exc .children [1 ].children [0 ].clone ()
55
- exc .prefix = u" "
56
-
57
- if "val" not in results :
58
- # One-argument raise
59
- new = pytree .Node (syms .raise_stmt , [Name (u"raise" ), exc ])
60
- new .prefix = node .prefix
61
- return new
62
-
63
- val = results ["val" ].clone ()
64
- if is_tuple (val ):
65
- args = [c .clone () for c in val .children [1 :- 1 ]]
66
- else :
67
- val .prefix = u""
68
- args = [val ]
69
-
70
- return pytree .Node (syms .raise_stmt ,
71
- [Name (u"raise" ), Call (exc , args )],
72
- prefix = node .prefix )
30
+ """
0 commit comments