diff --git a/pep-3129.txt b/pep-3129.txt index 874ebd1b3..26c050934 100644 --- a/pep-3129.txt +++ b/pep-3129.txt @@ -65,13 +65,25 @@ For a detailed examination of decorators, please refer to PEP 318. Implementation ============== -The grammar for class declarations changes from :: +Adapating Python's grammar to support class decorators requires +modifying two rules and adding a new rule :: - classdef: 'class' NAME ['(' [testlist] ')'] ':' suite - -to :: + funcdef: [decorators] 'def' NAME parameters ['->' test] ':' suite + + compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | + with_stmt | funcdef | classdef + +need to be changed to :: + + decorated: decorators (classdef | funcdef) - classdef: [decorators] 'class' NAME ['(' [testlist] ')'] ':' suite + funcdef: 'def' NAME parameters ['->' test] ':' suite + + compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | + with_stmt | funcdef | classdef | decorated + +Adding ``decorated`` is necessary to avoid an ambiguity in the +grammar. The Python AST and bytecode must be modified accordingly.