mirror of https://github.com/python/cpython
bpo-39702: Update the Language Reference (PEP 614) (GH-18802)
This commit is contained in:
parent
02f64cb791
commit
8f13053692
|
@ -507,7 +507,7 @@ A function definition defines a user-defined function object (see section
|
||||||
funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")"
|
funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")"
|
||||||
: ["->" `expression`] ":" `suite`
|
: ["->" `expression`] ":" `suite`
|
||||||
decorators: `decorator`+
|
decorators: `decorator`+
|
||||||
decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE
|
decorator: "@" `assignment_expression` NEWLINE
|
||||||
dotted_name: `identifier` ("." `identifier`)*
|
dotted_name: `identifier` ("." `identifier`)*
|
||||||
parameter_list: `defparameter` ("," `defparameter`)* "," "/" ["," [`parameter_list_no_posonly`]]
|
parameter_list: `defparameter` ("," `defparameter`)* "," "/" ["," [`parameter_list_no_posonly`]]
|
||||||
: | `parameter_list_no_posonly`
|
: | `parameter_list_no_posonly`
|
||||||
|
@ -550,6 +550,11 @@ is roughly equivalent to ::
|
||||||
|
|
||||||
except that the original function is not temporarily bound to the name ``func``.
|
except that the original function is not temporarily bound to the name ``func``.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.9
|
||||||
|
Functions may be decorated with any valid :token:`assignment_expression`.
|
||||||
|
Previously, the grammar was much more restrictive; see :pep:`614` for
|
||||||
|
details.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
triple: default; parameter; value
|
triple: default; parameter; value
|
||||||
single: argument; function definition
|
single: argument; function definition
|
||||||
|
@ -717,6 +722,11 @@ is roughly equivalent to ::
|
||||||
The evaluation rules for the decorator expressions are the same as for function
|
The evaluation rules for the decorator expressions are the same as for function
|
||||||
decorators. The result is then bound to the class name.
|
decorators. The result is then bound to the class name.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.9
|
||||||
|
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
|
**Programmer's note:** Variables defined in the class definition are class
|
||||||
attributes; they are shared by instances. Instance attributes can be set in a
|
attributes; they are shared by instances. Instance attributes can be set in a
|
||||||
method with ``self.name = value``. Both class and instance attributes are
|
method with ``self.name = value``. Both class and instance attributes are
|
||||||
|
|
|
@ -138,6 +138,10 @@ Other Language Changes
|
||||||
There are similar changes for :class:`bytes` and :class:`bytearray` objects.
|
There are similar changes for :class:`bytes` and :class:`bytearray` objects.
|
||||||
(Contributed by Serhiy Storchaka in :issue:`28029`.)
|
(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
|
New Modules
|
||||||
===========
|
===========
|
||||||
|
|
Loading…
Reference in New Issue