From 6b77a7f8e20aa7f86dc9303a4f361efa29f61a6a Mon Sep 17 00:00:00 2001 From: Collin Winter Date: Tue, 1 May 2007 20:14:28 +0000 Subject: [PATCH] Fix the grammar in PEP 3129. --- pep-3129.txt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) 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.