2012-03-02 122 views
21

在模塊中使用私有元數據變量(如__author__)的約定來自哪裏?__author__的起源是什麼?

This Python郵件列表線程在2001年似乎暗示了一些關於它的討論,但通過它的聲音,大會已經在野外。

除此之外,我只能找到this PEP on package metadata,這似乎有影響力,但最好是正切。

我想嘗試找到關於這個主題的一些明確材料,這樣我的文檔工具就可以成功地解析這些元數據變量。

回答

17

我的猜測是,這是從過去封裝元數據不常見的時候開始的。 在PEP 8中,鼓勵使用__version__頂級變量來保存正在使用的版本控制系統的版本ID。這可以追溯到2001-05-01。 PEP 396正在取代模塊__version__屬性。

對於__author__,有一篇關於此事的python開發郵件列表。這個可以追溯到2001-03-01。作者質疑__author__的使用:「下一步是什麼?__cute_signoff__?」。

由於在PEP中沒有提到,所以我們不必擔心__author__。打包元數據是我們的朋友。

http://mail.python.org/pipermail/python-dev/2001-March/013328.html

 
Ping just checked in this: 

> Log Message: 
> Add __author__ and __credits__ variables. 
> 
> 
> Index: tokenize.py 
> =================================================================== 
> RCS file: /cvsroot/python/python/dist/src/Lib/tokenize.py,v 
> retrieving revision 1.19 
> retrieving revision 1.20 
> diff -C2 -r1.19 -r1.20 
> *** tokenize.py 2001/03/01 04:27:19 1.19 
> --- tokenize.py 2001/03/01 13:56:40 1.20 
> *************** 
> *** 10,14 **** 
> it produces COMMENT tokens for comments and gives type OP for all operators.""" 
> 
> ! __version__ = "Ka-Ping Yee, 26 October 1997; patched, GvR 3/30/98" 
> 
> import string, re 
> --- 10,15 ---- 
> it produces COMMENT tokens for comments and gives type OP for all operators.""" 
> 
> ! __author__ = 'Ka-Ping Yee ' 
> ! __credits__ = 'first version, 26 October 1997; patched, GvR 3/30/98' 
> 
> import string, re 

I'm slightly uncomfortable with the __credits__ variable inserted 
here. First of all, __credits__ doesn't really describe the 
information given. Second, doesn't this info belong in the CVS 
history? I'm not for including random extracts of a module's history 
in the source code -- this is more likely than not to become out of 
date. (E.g. from the CVS log it's not clear why my contribution 
deserves a mention while Tim's doesn't -- it looks like Tim probably 
spent a lot more time thinking about it than I did.) 

Anothor source of discomfort is that there's absolutely no standard 
for this kind of meta-data variables. We've got __version__, and I 
believe we once agreed on that (in 1994 or so :-). But __author__? 
__credits__? What next -- __cute_signoff__? 
+0

鑑於這可能是有沒有辦法可靠地分析\ _ \ _筆者\ _ \ _或\ _ \ _學分\ _ \ _屬性。 – itsafire 2012-03-05 10:21:18