発生したのは、以下のような sqlalchemy での条件文が flake8 の lint エラーになったので、対応したかった。

Flake8 error: E712 comparison to True should be 'if cond is True:' or 'if cond:'

実装していた処理は以下

ExampleModel.sa.delete_flag == True

これが lint エラーになるからって、以下にすると、解消するけど、うまく動かない(条件判定がおかしくなる)
落とし穴!!!

ExampleModel.sa.delete_flag is True
# または
ExampleModel.sa.delete_flag
# 上記や、上記の否定など
not ExampleModel.sa.delete_flag

結論としては、sqlalchemy.sql.expression.true, sqlalchemy.sql.expression.false あるからそれ使う

# import
from sqlalchemy import false, true

# ussage
ExampleModel.sa.delete_flag == true()

いやいやいや…

Refs