WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

remove_debug=True incorrectly removes if/elif/else blocks comparing with 'is True' #142

@mccarthysean

Description

@mccarthysean

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_connected

Actual 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_connected

Impact

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:

  1. Not remove is True comparisons under remove_debug
  2. Document this behavior prominently as a breaking change risk
  3. Provide a separate option for this specific transformation

Workaround

Set remove_debug=False when minifying code that uses is True comparisons in conditional logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions