python flask alchemy 在判断None值时候,推荐使用==/!=来判断。例如:
query.filter(User.name==None) query.filter(User.name!=None)
但是这样的代码提交后时过不了flake8的语法检查,会报错:
flake8...................................................................Failed
- hook id: flake8
- exit code: 1app/mode/xxx.py:393:74: E711 comparison to None should be 'if cond is None:'
app/models/xxx.py:409:74: E711 comparison to None should be 'if cond is None:'
app/models/xxx.py:442:70: E711 comparison to None should be 'if cond is None:'
alchemy中,要是使用is/is not来判断None值得不到想要的结果
??query.filter(User.name? is None)
?query.filter(User.name is not None)
但是我们可以这样写,既可以得到想要的结果,也可以通过flask8检查
??query.filter(User.name.is_(None))
?query.filter(User.name.isnot(None))