装饰J4 - 有任何异议吗? [英] decorator J4 - any objections?

查看:68
本文介绍了装饰J4 - 有任何异议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Guido已经表示他愿意考虑*一个*替代

装饰器语法。目前,(Phillip Eby的建议)J4

< URL: http://www.python.org/moin/PythonDecorators > (第5.21节J4)


对我来说看起来非常好 - 而且它是唯一没有底片的替代品。


def func(arg1, arg2)

@version(在2.4中添加)

@returns(无)

as:

""" Docstring可能在这里,或在装饰器部分上方""

#body到这里


(注意在函数线上缺少冒号;添加它会更加一致并且不会损害可读性。)


def func(arg1,arg2):

@version(在2.4中添加)

@returns(无)

as:

" "" Docstring可以在这里,或者在装饰部分上面""

#body到这里


虽然我认为这是最好的解决方案到目前为止,我意识到其他人

经常在这个问题上不同意我的意见 - 所以我很感激

一些反馈,特别是那些不喜欢的人J4合成器x。


披露:我自己喜欢装饰者,但是他们已经足够了

a特殊情况,我担心会把语言弄得乱七八糟/>
整个。 J4对我来说似乎是最好的妥协,但是我也可以和Guido现在的@proposal一起使用和/或
和平。


-jJ

Guido has said that he is open to considering *one* alternative
decorator syntax. At the moment, (Phillip Eby''s suggestion) J4

<URL: http://www.python.org/moin/PythonDecorators > (section 5.21 J4)

looks very good to me -- and it is the only alternative without negatives.

def func(arg1, arg2)
@version("Added in 2.4")
@returns(None)
as:
"""Docstring could be here, or in decorator part above"""
# body goes here

(Note the lack of colon on the func line; adding it would be more
consistent and not hurt readability.)

def func(arg1, arg2):
@version("Added in 2.4")
@returns(None)
as:
"""Docstring could be here, or in decorator part above"""
# body goes here

While I think this is the best solution so far, I realize that others
have often disagreed with me on this issue -- so I would appreciate
some feedback, particularly from those who don''t like the J4 syntax.

Disclosure: I like decorators on their own, but they are enough of
a special case that I worry about cluttering up the language as a
whole. J4 seems the best compromise to me, but I could also make
peace with Guido''s current @proposal.

-jJ

推荐答案

Ji ******** @ yahoo。 com(Jim Jewett)写道:
Ji********@yahoo.com (Jim Jewett) writes:
< URL: http://www.python.org/moin/PythonDecorators > (第5.21节J4)

对我来说非常好 - 而且它是唯一没有否定的替代方案。

def func(arg1,arg2)
@version (在2.4中添加)
@returns(无)
as:
""" Docstring可以在这里,或在装饰器部分上面""
#body到这里
<URL: http://www.python.org/moin/PythonDecorators > (section 5.21 J4)

looks very good to me -- and it is the only alternative without negatives.

def func(arg1, arg2)
@version("Added in 2.4")
@returns(None)
as:
"""Docstring could be here, or in decorator part above"""
# body goes here




使用时出了什么问题。或 - 而不是@?鉴于这是新语法,几乎任何角色都可以工作。或者说什么没有

特别标点符号呢?使用@会让我有点畏缩。


另外,为什么需要as关键词?如果它只是消除了b $ b,会发生什么?即:


def func(arg1,arg2)

@version(在2.4中添加)

@returns (无):


""" Docstring可以在这里,或者在装饰部分上面""

#body到这里



What was wrong with using . or - instead of @ ? Given that this is
new syntax, just about any character could work. Or what about no
special punctuation at all? Using @ makes me cringe somewhat.

Also, why the need for the "as" keyword? What happens if it''s just
eliminated? I.e.:

def func(arg1, arg2)
@version("Added in 2.4")
@returns(None):

"""Docstring could be here, or in decorator part above"""
# body goes here


Paul Rubin< http://ph****@nospam.invalid>写道:
Paul Rubin <http://ph****@nospam.invalid> wrote:

另外,为什么需要as关键词?如果它被消除了怎么办?即:

def func(arg1,arg2)
@ version(在2.4中添加)
@returns(无):

""" Docstring可以在这里,或者在装饰器部分上面""
#body到这里

Also, why the need for the "as" keyword? What happens if it''s just
eliminated? I.e.:

def func(arg1, arg2)
@version("Added in 2.4")
@returns(None):

"""Docstring could be here, or in decorator part above"""
# body goes here




这真的是当实际的

函数体开始时,有一个缩进标记很好。


martin



It''s really nice to have an outdented marker for when the actual
function body begins.

martin


Martin DeMello< ma *********** @ yahoo.com>写道:
Martin DeMello <ma***********@yahoo.com> writes:
def func(arg1,arg2)
@ version(在2.4中添加)
@returns(无):

"""文档字符串可以在这里,或者在装饰器部分上面""
#body到这里
def func(arg1, arg2)
@version("Added in 2.4")
@returns(None):

"""Docstring could be here, or in decorator part above"""
# body goes here



它当真正的
函数体开始时,有一个缩进标记真的很不错。



It''s really nice to have an outdented marker for when the actual
function body begins.




我不知道为什么,但装饰者不必缩进:


def func(arg1,arg2)

-version(在2.4中添加)

-returns(无):


""" Docstring可以在这里,或在装饰器部分上面""

#身体到这里


我想这很难看。



I don''t really see why, but the decorators don''t have to be indented:

def func(arg1, arg2)
-version("Added in 2.4")
-returns(None):

"""Docstring could be here, or in decorator part above"""
# body goes here

I guess that''s ugly though.


这篇关于装饰J4 - 有任何异议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆