]> granicus.if.org Git - python/commitdiff
Allow classes to be defined with empty parentheses. This means that
authorBrett Cannon <bcannon@gmail.com>
Sat, 5 Mar 2005 06:47:57 +0000 (06:47 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sat, 5 Mar 2005 06:47:57 +0000 (06:47 +0000)
``class C(): pass`` is no longer a syntax error.

Grammar/Grammar
Misc/NEWS
Python/compile.c
Python/graminit.c

index 9e4dad8078f40ecebd25f6c13eeaed971e2aaf8a..7b6acf7313221044427bd070a7b301f9d2643c52 100644 (file)
@@ -99,7 +99,7 @@ testlist: test (',' test)* [',']
 testlist_safe: test [(',' test)+ [',']]
 dictmaker: test ':' test (',' test ':' test)* [',']
 
-classdef: 'class' NAME ['(' testlist ')'] ':' suite
+classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
 
 arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
 argument: [test '='] test [gen_for] # Really [keyword '='] test
index 86d3677d8753c282b8b4868cc87ed01ead5bf0cd..08a8f43b65ca809faba44ff3e6de98d0d03a84f0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Defining a class with empty parentheses is now allowed
+  (e.g., ``class C(): pass`` is no longer a syntax error)
+
 - Patch #1115086: Support PY_LONGLONG in structmember.
 
 - Bug #1155938: new style classes did not check that __init__() was
index 16bf291708d4e9ea8f2624e6d5975a0eb6f59314..5781b21ce4cde227face4144b3b263be4e1e7192 100644 (file)
@@ -4624,7 +4624,7 @@ com_classdef(struct compiling *c, node *n)
        char *name;
 
        REQ(n, classdef);
-       /* classdef: class NAME ['(' testlist ')'] ':' suite */
+       /* classdef: class NAME ['(' [testlist] ')'] ':' suite */
        if ((v = PyString_InternFromString(STR(CHILD(n, 1)))) == NULL) {
                c->c_errors++;
                return;
@@ -4635,7 +4635,8 @@ com_classdef(struct compiling *c, node *n)
        com_push(c, 1);
        Py_DECREF(v);
        /* Push the tuple of base classes on the stack */
-       if (TYPE(CHILD(n, 2)) != LPAR) {
+       if (TYPE(CHILD(n, 2)) != LPAR ||
+                       TYPE(CHILD(n, 3)) == RPAR) {
                com_addoparg(c, BUILD_TUPLE, 0);
                com_push(c, 1);
        }
index c4fe66148bf6bd5ccabfb8836c9e065aaccd57fb..464f0aeddd74e50d674f031e9255454c112c5d13 100644 (file)
@@ -1426,26 +1426,27 @@ static arc arcs_67_2[2] = {
        {13, 3},
        {21, 4},
 };
-static arc arcs_67_3[1] = {
+static arc arcs_67_3[2] = {
        {9, 5},
+       {15, 6},
 };
 static arc arcs_67_4[1] = {
-       {22, 6},
+       {22, 7},
 };
 static arc arcs_67_5[1] = {
-       {15, 7},
+       {15, 6},
 };
 static arc arcs_67_6[1] = {
-       {0, 6},
+       {21, 4},
 };
 static arc arcs_67_7[1] = {
-       {21, 4},
+       {0, 7},
 };
 static state states_67[8] = {
        {1, arcs_67_0},
        {1, arcs_67_1},
        {2, arcs_67_2},
-       {1, arcs_67_3},
+       {2, arcs_67_3},
        {1, arcs_67_4},
        {1, arcs_67_5},
        {1, arcs_67_6},