From bb6d834e95d7d8441c70e4865e3a6ae519b9334a Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Tue, 3 Mar 2020 22:22:42 -0800 Subject: [PATCH 1/3] What's New. --- Doc/whatsnew/3.9.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 6a4d07f62c69b6..1b99bab6bcd6e1 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -138,6 +138,10 @@ Other Language Changes There are similar changes for :class:`bytes` and :class:`bytearray` objects. (Contributed by Serhiy Storchaka in :issue:`28029`.) +* Any valid expression can now be used as a :term:`decorator`. Previously, the + grammar was much more restrictive. See :pep:`614` for details. + (Contributed by Brandt Bucher in :issue:`39702`.) + New Modules =========== From a8f0dcfcf6d9c7e141fd8e97ca5ae80321f72e33 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 5 Mar 2020 23:02:50 -0800 Subject: [PATCH 2/3] Update the Language Reference. --- Doc/reference/compound_stmts.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index ac2065b4cff9b1..705d1ec1f5583f 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -507,7 +507,7 @@ A function definition defines a user-defined function object (see section funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")" : ["->" `expression`] ":" `suite` decorators: `decorator`+ - decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE + decorator: "@" `assignment_expression` NEWLINE dotted_name: `identifier` ("." `identifier`)* parameter_list: `defparameter` ("," `defparameter`)* "," "/" ["," [`parameter_list_no_posonly`]] : | `parameter_list_no_posonly` @@ -550,6 +550,10 @@ is roughly equivalent to :: except that the original function is not temporarily bound to the name ``func``. +.. versionchanged:: 3.9 + Functions may be decorated with any valid expression. Previously, the + grammar was much more restrictive; see :pep:`614` for details. + .. index:: triple: default; parameter; value single: argument; function definition @@ -717,6 +721,10 @@ is roughly equivalent to :: The evaluation rules for the decorator expressions are the same as for function decorators. The result is then bound to the class name. +.. versionchanged:: 3.9 + Classes may be decorated with any valid expression. Previously, the grammar + was much more restrictive; see :pep:`614` for details. + **Programmer's note:** Variables defined in the class definition are class attributes; they are shared by instances. Instance attributes can be set in a method with ``self.name = value``. Both class and instance attributes are From 32345bd59a877fead6f1d69ad332ae46947da85f Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 6 Mar 2020 22:10:54 -0800 Subject: [PATCH 3/3] Make versionchanged note more specific. --- Doc/reference/compound_stmts.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 705d1ec1f5583f..c14e7c79fe14cf 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -551,8 +551,9 @@ is roughly equivalent to :: except that the original function is not temporarily bound to the name ``func``. .. versionchanged:: 3.9 - Functions may be decorated with any valid expression. Previously, the - grammar was much more restrictive; see :pep:`614` for details. + Functions may be decorated with any valid :token:`assignment_expression`. + Previously, the grammar was much more restrictive; see :pep:`614` for + details. .. index:: triple: default; parameter; value @@ -722,8 +723,9 @@ The evaluation rules for the decorator expressions are the same as for function decorators. The result is then bound to the class name. .. versionchanged:: 3.9 - Classes may be decorated with any valid expression. Previously, the grammar - was much more restrictive; see :pep:`614` for details. + Classes may be decorated with any valid :token:`assignment_expression`. + Previously, the grammar was much more restrictive; see :pep:`614` for + details. **Programmer's note:** Variables defined in the class definition are class attributes; they are shared by instances. Instance attributes can be set in a