RE: [Python-Dev] Re: A syntax for function attributes?

From: Eric S. Raymond [mailto:esr@thyrsus.com]
Zack Weinberg <zack@codesourcery.com>:
I.e. allow a dictionary constructor expression between the argument list and the colon; this initializes the property dictionary of the code object. One could stick a call to spark.rule() in there, or have a metaclass do it automatically.
This allows the square bracket notation to be reserved for [classmethod] and the like. I suppose there's nothing stopping square brackets from being used for both, but I like having consistency with other dictionary constructor expressions.
I like this argument. +1.
All of the notations involving "stuff" between the definition and the colon look reasonable when the "stuff" is small, but start to look odd when it gets bigger (because it usually means that the colon is not on the same line as the "def"). How about leaving the [...] construct between the args and the colon, on the assumption that "normal use" is for short stuff, like [classmethod]. But for the dictionary option for function attributes, locate it after the docstring. The we have def p_expr_term(self,args): """docstring here""" { 'rule' : """expr ::= expr + term term ::= term * factor""" } pass It may get (slightly) hairy to parse, but should be OK, as docstrings are a precedent for bare literals at the start of a function definition having special meaning. Paul.
participants (1)
-
Moore, Paul