flake8 complains on boolean comparison “==” in filter clause

折月煮酒 提交于 2019-11-29 09:02:31

That's because SQLAlchemy filters are one of the few places where == False actually makes sense. Everywhere else you should not use it.

Add a # noqa comment to the line and be done with it.

Or you can use sqlalchemy.sql.expression.false:

from sqlalchemy.sql.expression import false

TestCase.obsoleted == false()

where false() returns the right value for your session SQL dialect. There is a matching sqlalchemy.expression.true.

SQL Alchemy also has is_ and isnot functions you can use. An example would be

Model.filter(Model.deleted.is_(False))

More on those here

@Jruv Use # noqa in front of statement, it'll ignore the warning.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!