Three Minor Feature Requests for 2.2

Raymond Hettinger othello at javanet.com
Thu May 10 11:02:52 EDT 2001


James_Althoff at i2.com wrote:

> Personally, I think the "lazy" argument is compelling enough.  But the
> other argument in favor of "class C():" is that it would be very nice to
> have some empathy with programmers new to Python who in relying on
> "reasonable consistency" as a cornerstone of the "least surprise" principle
> find it strange to see that of the following four choices, neither of the
> two "reasonably consistent" ones work:
>
> def spam(): pass     # yes
> class Eggs(): pass   # no
>
> def spam: pass       # no
> class Eggs: pass     # yes
>
> def spam: pass       # no
> class Eggs(): pass   # no
>
> def spam(): pass     # yes
> class Eggs: pass     # yes

I see your point -- more than one way to do it is generally bad;
but I think it more confusing the way it stands now.  The users
first encounter with the subject is:

    >>> class MyClass():
    Traceback (  File "<interactive input>", line 1
        class MyClass():
                ^
    SyntaxError: invalid syntax

This is hardly a user friendly introduction to an unusual syntax
which has a special case format for zero length argument lists.

The flip side of "more than one way to do it" is that when a
programmer types something sensible and unambiguous
like "class MyClass():", the interpreter should "do the right thing"
instead of slapping your wrists.

All in all, it's not a big deal. It would just be nice to see it cleaned-up
leaving zero length tuples as the only syntactic oddity that we have to
live with.

Raymond





More information about the Python-list mailing list