# HG changeset patch # User Paul Boddie # Date 1484253463 -3600 # Node ID 49ff782a1b304b58d03b53e2ac9566b385630e1e # Parent 09ae465e5515af1f5fb69e04be081a4599c7cf95 Support the raise statement with exception class and argument. diff -r 09ae465e5515 -r 49ff782a1b30 translator.py --- a/translator.py Thu Jan 12 21:09:51 2017 +0100 +++ b/translator.py Thu Jan 12 21:37:43 2017 +0100 @@ -1417,15 +1417,24 @@ # NOTE: Determine which raise statement variants should be permitted. if n.expr1: - exc = self.process_structure_node(n.expr1) + + # Names with accompanying arguments are treated like invocations. + + if n.expr2: + call = compiler.ast.CallFunc(n.expr1, [n.expr2]) + exc = self.process_structure_node(call) + self.writestmt("__Raise(%s);" % exc) # Raise instances, testing the kind at run-time if necessary and # instantiating any non-instance. - if isinstance(exc, TrInstanceRef): - self.writestmt("__Raise(%s);" % exc) else: - self.writestmt("__Raise(__ensure_instance(%s));" % exc) + exc = self.process_structure_node(n.expr1) + + if isinstance(exc, TrInstanceRef): + self.writestmt("__Raise(%s);" % exc) + else: + self.writestmt("__Raise(__ensure_instance(%s));" % exc) else: self.writestmt("__Throw(__tmp_exc);")