Back to Intellij Community

PyChainedComparisonsInspection

python/python-psi-impl/resources/inspectionDescriptions/PyChainedComparisonsInspection.html

2025.3-rc-2379 B
Original Source

Reports chained comparisons that can be simplified.

Example:

def do_comparison(x):
    xmin = 10
    xmax = 100
    if x >= xmin and x <= xmax:
        pass

The IDE offers to simplify if x >= xmin and x <= xmax. When the quick-fix is applied, the code changes to:

def do_comparison(x):
    xmin = 10
    xmax = 100
    if xmin <= x <= xmax:
        pass