0
我一直在修補Invoke,但我遇到了一個很奇怪的情況,那就是似乎沒有真正的PEP指南。PEP8裝修風格超過推薦線長
調用允許您爲您定義的任何任務定義自己的CLI參數,並且您可以選擇向裝飾器提供「幫助註釋」。具體例子可以發現here。
如果有更多的參數,我可以這樣做,但如果有很多任務,感覺有點奇怪。你們會做什麼樣的編碼風格?
help_for_hi = {
'name1': 'Name of Person 1',
'name2': 'Name of Person 2',
'name3': 'Name of Person 3',
}
@task(help=help_for_hi)
def hi(ctx, name1, name2, name3):
"""Say hi to three people."""
print("Hi %s, %s, and %s!" % (name1, name2, name3))
修訂
按照要求,這是 '太長' 可能會樣子。
@task(help={'name1': 'Name of Person 1', 'name2': 'Name of Person 2', 'name3': 'Name of Person 3'})
def hi(ctx, name1, name2, name3):
"""Say hi to three people."""
print("Hi %s, %s, and %s!" % (name1, name2, name3))
對不起,你能說出它太長時間後的樣子嗎?裝飾器表達式就像其他任何調用一樣,將其包裝到'(...)'中的多行中。 –
帶參數的裝飾器只是帶有前綴「@」的函數調用 - 所以只需按照PEP8函數調用的指導原則進行。 – martineau