参照文档:https://alvin.red/2017/10/07/python-pep-8/
一、f语句中条件过多,导致长度过长怎么办?
1. 原来的格式:
if ('skip_test' in api_dsl and api_dsl['skip_test']) or ('depend_on' not in api_dsl) or ('enabled_only' in api_dsl and api_dsl['enabled_only'] != env): continue
2. 优化后的格式:
if (('skip_test' in api_dsl and api_dsl['skip_test']) or ('depend_on' not in api_dsl) or ('enabled_only' in api_dsl and api_dsl['enabled_only'] != env)): continue
3. 优化方案:在if条件最外面添加圆括号,利用圆括号进行隐式续行。长行可以通过在括号内换行来分成多行。另外,运算符或者关键字要放在最前面哦~