-
-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Description
When using remove_debug=True, the minifier incorrectly removes entire if/elif/else blocks that use is True comparisons, even when these are functional code and not debug statements.
Reproduction
import python_minifier
source = '''
def check_is_internet_working(c):
url, url_hostname = get_url_and_url_hostname(c)
if is_internet_working_socket_test(c, url_hostname) is True:
c.is_internet_connected = True
elif is_internet_working_urllib_open(c, url) is True:
c.is_internet_connected = True
else:
c.is_internet_connected = False
return c.is_internet_connected
'''
# With remove_debug=True - BROKEN
result = python_minifier.minify(source, remove_debug=True)
print(result)Expected Output
The if/elif/else block should be preserved (perhaps with is True simplified):
def check_is_internet_working(c):
A,B=get_url_and_url_hostname(c)
if is_internet_working_socket_test(c,B):c.is_internet_connected=True
elif is_internet_working_urllib_open(c,A):c.is_internet_connected=True
else:c.is_internet_connected=False
return c.is_internet_connectedActual Output
The entire if/elif/else block is removed:
def check_is_internet_working(c):A,B=get_url_and_url_hostname(c);return c.is_internet_connectedImpact
This is a silent, breaking bug - the minified code passes syntax validation but produces completely different runtime behavior. In our case, this caused production IoT gateways to fail internet connectivity checks because the function that sets c.is_internet_connected = True was completely removed.
Environment
- python-minifier version: 3.1.0
- Python version: 3.12.3
Analysis
The remove_debug option appears to be treating func() is True patterns as debug assertions (similar to assert statements or if __debug__: blocks). However, is True comparisons are valid, functional code patterns, especially when checking for explicit True vs truthy values.
The minifier should either:
- Not remove
is Truecomparisons underremove_debug - Document this behavior prominently as a breaking change risk
- Provide a separate option for this specific transformation
Workaround
Set remove_debug=False when minifying code that uses is True comparisons in conditional logic.