Repository: apache/superset
File: superset/models/helpers.py (Python)

Code before:
                        ADVANCED_DATA_TYPES[col_advanced_data_type].translate_filter(
                            sqla_col, op, bus_resp["values"]
                        )
                    )
                elif is_list_target:
                    assert isinstance(eq, (tuple, list))
                    if len(eq) == 0:
                        raise QueryObjectValidationError(
                            _("Filter value list cannot be empty")
                        )
                    if len(eq) > len(
                        eq_without_none := [x for x in eq if x is not None]
                    ):
                        is_null_cond = sqla_col.is_(None)
                        if eq:
                            cond = or_(is_null_cond, sqla_col.in_(eq_without_none))
                        else:
                            cond = is_null_cond
                    else:
                        cond = sqla_col.in_(eq)
                    if op == utils.FilterOperator.NOT_IN.value:
                        cond = ~cond
                    where_clause_and.append(cond)
                elif op in {
                    utils.FilterOperator.IS_NULL.value,
                    utils.FilterOperator.IS_NOT_NULL.value,
                }:
                    where_clause_and.append(
                        db_engine_spec.handle_null_filter(sqla_col, op)
                    )
                elif op == utils.FilterOperator.IS_TRUE.value:
                    where_clause_and.append(
                        db_engine_spec.handle_boolean_filter(sqla_col, op, True)
                    )
                elif op == utils.FilterOperator.IS_FALSE.value:
                    where_clause_and.append(
                        db_engine_spec.handle_boolean_filter(sqla_col, op, False)
                    )
                else:
                    if (
                        op
                        not in {
                            utils.FilterOperator.EQUALS.value,
                            utils.FilterOperator.NOT_EQUALS.value,
                        }
                        and eq is None
                    ):
                        raise QueryObjectValidationError(
                            _(
                                "Must specify a value for filters "
                                "with comparison operators"

Review comment (suggestion):
Cast `op` to an enum earlier with (though you need to change the variable name to prevent mypy from complaining the type has changed):

```python
try:
    op = utils.FilterOperator(op)
except ValueError:
    valid = ", ".join(operator.value for operator in utils.FilterOperator)
    raise SomeException(f"Invalid operator type: {op}. Supported values are: {valid}")
```

Then do all comparisons with the enum instead of string:

```suggestion
                elif op in {
                    utils.FilterOperator.IS_NULL,
                    utils.FilterOperator.IS_NOT_NULL,
```

Code after:
                        ADVANCED_DATA_TYPES[col_advanced_data_type].translate_filter(
                            sqla_col, op, bus_resp["values"]
                        )
                    )
                elif is_list_target:
                    assert isinstance(eq, (tuple, list))
                    if len(eq) == 0:
                        raise QueryObjectValidationError(
                            _("Filter value list cannot be empty")
                        )
                    if len(eq) > len(
                        eq_without_none := [x for x in eq if x is not None]
                    ):
                        is_null_cond = sqla_col.is_(None)
                        if eq:
                            cond = or_(is_null_cond, sqla_col.in_(eq_without_none))
                        else:
                            cond = is_null_cond
                    else:
                        cond = sqla_col.in_(eq)
                    if op == utils.FilterOperator.NOT_IN:
                        cond = ~cond
                    where_clause_and.append(cond)
                elif op in {
                    utils.FilterOperator.IS_NULL,
                    utils.FilterOperator.IS_NOT_NULL,
                }:
                    where_clause_and.append(
                        db_engine_spec.handle_null_filter(sqla_col, op)
                    )
                elif op == utils.FilterOperator.IS_TRUE:
                    where_clause_and.append(
                        db_engine_spec.handle_boolean_filter(sqla_col, op, True)
                    )
                elif op == utils.FilterOperator.IS_FALSE:
                    where_clause_and.append(
                        db_engine_spec.handle_boolean_filter(sqla_col, op, False)
                    )
                else:
                    if (
                        op
                        not in {
                            utils.FilterOperator.EQUALS,
                            utils.FilterOperator.NOT_EQUALS,
                        }
                        and eq is None
                    ):
                        raise QueryObjectValidationError(
                            _(
                                "Must specify a value for filters "
                                "with comparison operators"