我的公司严格遵守pydocstyle。我遇到了限制修改嵌套在json文件中的这些值的行限制。
Rem_Conf['RemediationConfigurations'][0]['Parameters']['AutomationAssumeRole']['StaticValue']['Values'][0] = rolearn
Rem_Conf['RemediationConfigurations'][0]['Parameters']['GranteeId']['StaticValue']['Values'][0] = canid
Rem_Conf['RemediationConfigurations'][0]['Parameters']['TargetBucket']['StaticValue']['Values'][0] = targetbucket
如何压缩它以满足79个字符的pydocstyle限制?
最佳答案
一种方法是用短命名变量替换内联键
cfg='RemediationConfigurations'
params='Parameters'
role='AutomationAssumeRole'
sval='StaticValue'
val='Values'
guid='GranteeId'
tbuk='TargetBucket'
Rem_Conf[cfg][0][params][role][sval][val][0] = rolearn
Rem_Conf[cfg][0][params][guid][sval][val][0] = canid
Rem_Conf[cfg][0][params][tbuk][sval][val][0] = targetbucket
这里最长的一行是
60
字符,它使值的模式对读者非常清楚