From a4b2b5e21c5d385b32efea251cca9eddb7177561 Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Mon, 13 Feb 2023 22:46:14 -0800 Subject: [PATCH] Remove parenthesis for single argument exceptions in `raise` statement: There is no semantic difference between `raise X()` and `raise X`, so for the few instances where you are raising an exception with no arguments you can save 2 bytes. The AST comparison is failing now though due to the `Call` node being replaced with a `Name` node, so I don't know what the best way to go about fixing that is. --- src/python_minifier/module_printer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/python_minifier/module_printer.py b/src/python_minifier/module_printer.py index 235368ef..7ebf1926 100644 --- a/src/python_minifier/module_printer.py +++ b/src/python_minifier/module_printer.py @@ -227,7 +227,10 @@ def visit_Raise(self, node): if node.exc: self.code += ' ' - self._expression(node.exc) + if isinstance(node.exc, ast.Call) and not node.exc.args: + self._lhs(node.exc.func, node.exc) + else: + self._expression(node.exc) if node.cause: self.code += ' from '