Skip to content

Commit 8f13053

Browse files
authored
bpo-39702: Update the Language Reference (PEP 614) (GH-18802)
1 parent 02f64cb commit 8f13053

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ A function definition defines a user-defined function object (see section
507507
funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")"
508508
: ["->" `expression`] ":" `suite`
509509
decorators: `decorator`+
510-
decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE
510+
decorator: "@" `assignment_expression` NEWLINE
511511
dotted_name: `identifier` ("." `identifier`)*
512512
parameter_list: `defparameter` ("," `defparameter`)* "," "/" ["," [`parameter_list_no_posonly`]]
513513
: | `parameter_list_no_posonly`
@@ -550,6 +550,11 @@ is roughly equivalent to ::
550550

551551
except that the original function is not temporarily bound to the name ``func``.
552552

553+
.. versionchanged:: 3.9
554+
Functions may be decorated with any valid :token:`assignment_expression`.
555+
Previously, the grammar was much more restrictive; see :pep:`614` for
556+
details.
557+
553558
.. index::
554559
triple: default; parameter; value
555560
single: argument; function definition
@@ -717,6 +722,11 @@ is roughly equivalent to ::
717722
The evaluation rules for the decorator expressions are the same as for function
718723
decorators. The result is then bound to the class name.
719724

725+
.. versionchanged:: 3.9
726+
Classes may be decorated with any valid :token:`assignment_expression`.
727+
Previously, the grammar was much more restrictive; see :pep:`614` for
728+
details.
729+
720730
**Programmer's note:** Variables defined in the class definition are class
721731
attributes; they are shared by instances. Instance attributes can be set in a
722732
method with ``self.name = value``. Both class and instance attributes are

Doc/whatsnew/3.9.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Other Language Changes
138138
There are similar changes for :class:`bytes` and :class:`bytearray` objects.
139139
(Contributed by Serhiy Storchaka in :issue:`28029`.)
140140

141+
* Any valid expression can now be used as a :term:`decorator`. Previously, the
142+
grammar was much more restrictive. See :pep:`614` for details.
143+
(Contributed by Brandt Bucher in :issue:`39702`.)
144+
141145

142146
New Modules
143147
===========

0 commit comments

Comments
 (0)