Skip to content

Commit 51ecf3d

Browse files
committed
Remove builtin exceptions brackets
1 parent 6bc5c1e commit 51ecf3d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

docs/source/transforms/remove_exception_brackets.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Remove Builtin Exception Brackets
44
This transform removes parentheses when raising builtin exceptions with no arguments.
55

66
The raise statement automatically instantiates exceptions with no arguments, so the parentheses are unnecessary.
7+
This transform does nothing on Python 2.
78

89
This transform is enabled by default. Disable by passing the ``remove_builtin_exception_brackets=False`` argument to the :func:`python_minifier.minify` function,
910
or passing ``--no-remove-builtin-exception-brackets`` to the pyminify command.

src/python_minifier/transforms/remove_exception_brackets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import ast
12+
import sys
1213

1314
from python_minifier.rename.binding import BuiltinBinding
1415

@@ -116,6 +117,9 @@ def _remove_empty_call(binding):
116117
def remove_no_arg_exception_call(module):
117118
assert isinstance(module, ast.Module)
118119

120+
if sys.version_info < (3, 0):
121+
return module
122+
119123
for binding in module.bindings:
120124
if isinstance(binding, BuiltinBinding) and binding.name in builtin_exceptions:
121125
# We can remove any calls to builtin exceptions

0 commit comments

Comments
 (0)