with as J2 keyword (WAS: Re: J2 0-2-6 is available)

Steven Bethard steven.bethard at gmail.com
Wed Aug 25 06:36:37 CEST 2004


Doug Holton <insert <at> spam.here> writes:
> with:
>      classmethod
>      .author = "François Pinard"
> def foo(cls):
>      pass
> 
> def bar():
>      pass
> with bar:
>      staticmethod
>      .version = "0.2.4"

Note that one of the common decorator examples has been something like:

@classmethod
@funcattrs(author="François Pinard")
def foo(cls):
    pass

So for functions, people already want to put classmethod and the author 
attribute in the same place.  So when "with" blocks come along, and people get 
used to writing

with self:
    .x = 3

they're going to wonder why they have to move their metadata to after the 
function if they want to use the .xxx syntax.

That aside, I tend to agree with you.  I think mixing the .xxx assignments 
(which are statements) with things like "classmethod" and "memoize" (which are 
expressions) is bound to be confusing, e.g. your example:

> with self:
>      init
>      .version = 3
> Is that supposed to mean:
> init(self)
> self.version = 3?

Presumably anyone who was pushing for "with" as the keyword would, at the 
least, disallow this sort of syntax for non-funcdefs, but this is certainly a 
great example of how horrible it could be.  =)

Steve




More information about the Python-list mailing list