Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 409d8f2

Browse files
committed
Allow classes to be defined with empty parentheses. This means that
``class C(): pass`` is no longer a syntax error.
1 parent 653a5ad commit 409d8f2

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

Grammar/Grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ testlist: test (',' test)* [',']
9999
testlist_safe: test [(',' test)+ [',']]
100100
dictmaker: test ':' test (',' test ':' test)* [',']
101101

102-
classdef: 'class' NAME ['(' testlist ')'] ':' suite
102+
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
103103

104104
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
105105
argument: [test '='] test [gen_for] # Really [keyword '='] test

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 2.5 alpha 1?
1010
Core and builtins
1111
-----------------
1212

13+
- Defining a class with empty parentheses is now allowed
14+
(e.g., ``class C(): pass`` is no longer a syntax error)
15+
1316
- Patch #1115086: Support PY_LONGLONG in structmember.
1417

1518
- Bug #1155938: new style classes did not check that __init__() was

Python/compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4624,7 +4624,7 @@ com_classdef(struct compiling *c, node *n)
46244624
char *name;
46254625

46264626
REQ(n, classdef);
4627-
/* classdef: class NAME ['(' testlist ')'] ':' suite */
4627+
/* classdef: class NAME ['(' [testlist] ')'] ':' suite */
46284628
if ((v = PyString_InternFromString(STR(CHILD(n, 1)))) == NULL) {
46294629
c->c_errors++;
46304630
return;
@@ -4635,7 +4635,8 @@ com_classdef(struct compiling *c, node *n)
46354635
com_push(c, 1);
46364636
Py_DECREF(v);
46374637
/* Push the tuple of base classes on the stack */
4638-
if (TYPE(CHILD(n, 2)) != LPAR) {
4638+
if (TYPE(CHILD(n, 2)) != LPAR ||
4639+
TYPE(CHILD(n, 3)) == RPAR) {
46394640
com_addoparg(c, BUILD_TUPLE, 0);
46404641
com_push(c, 1);
46414642
}

Python/graminit.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,26 +1426,27 @@ static arc arcs_67_2[2] = {
14261426
{13, 3},
14271427
{21, 4},
14281428
};
1429-
static arc arcs_67_3[1] = {
1429+
static arc arcs_67_3[2] = {
14301430
{9, 5},
1431+
{15, 6},
14311432
};
14321433
static arc arcs_67_4[1] = {
1433-
{22, 6},
1434+
{22, 7},
14341435
};
14351436
static arc arcs_67_5[1] = {
1436-
{15, 7},
1437+
{15, 6},
14371438
};
14381439
static arc arcs_67_6[1] = {
1439-
{0, 6},
1440+
{21, 4},
14401441
};
14411442
static arc arcs_67_7[1] = {
1442-
{21, 4},
1443+
{0, 7},
14431444
};
14441445
static state states_67[8] = {
14451446
{1, arcs_67_0},
14461447
{1, arcs_67_1},
14471448
{2, arcs_67_2},
1448-
{1, arcs_67_3},
1449+
{2, arcs_67_3},
14491450
{1, arcs_67_4},
14501451
{1, arcs_67_5},
14511452
{1, arcs_67_6},

0 commit comments

Comments
 (0)