PEP 622: Clarifications that came up on python-dev
- State that `case` is also a soft keyword - Triple-quoted strings are supported - Clarify that `__match__` must be a static or class method returning an object or None - Add two TODOs - Fix line of dashes
This commit is contained in:
parent
77462fe146
commit
8fd28e1e94
25
pep-0622.rst
25
pep-0622.rst
|
@ -157,9 +157,10 @@ many languages it is an expression, being a statement better suits the general
|
|||
logic of Python syntax. See `rejected ideas`_ for more discussion. The list of
|
||||
allowed patterns is specified below in the `patterns`_ subsection.
|
||||
|
||||
The ``match`` word is proposed to be a soft keyword, so that it is recognized
|
||||
as a keyword at the beginning of a match statement, but is allowed to be used in
|
||||
other places as a variable or argument name.
|
||||
The ``match`` and ``case`` keywords are proposed to be soft keywords,
|
||||
so that they are recognized as keywords at the beginning of a match
|
||||
statement or case block respectively, but are allowed to be used in
|
||||
other places as variable or argument names.
|
||||
|
||||
The proposed indentation structure is as following::
|
||||
|
||||
|
@ -236,7 +237,7 @@ literals for the purpose of pattern matching. Unary plus is not allowed.
|
|||
Binary plus and minus are allowed only to join a real number and an imaginary
|
||||
number to form a complex number, such as ``1+1j``.
|
||||
|
||||
Raw strings and byte strings
|
||||
Triple-quoted strings are supported. Raw strings and byte strings
|
||||
are supported. F-strings are not allowed (since in general they are not
|
||||
really literals).
|
||||
|
||||
|
@ -544,9 +545,15 @@ Runtime specification
|
|||
The ``__match__()`` protocol
|
||||
----------------------------
|
||||
|
||||
The ``__match__()`` method is used to decide whether an object matches a given
|
||||
class pattern and to extract the corresponding attributes. The procedure is as
|
||||
following:
|
||||
TODO: Show equivalent pseudo code.
|
||||
|
||||
The ``__match__()`` method is used to decide whether an object matches
|
||||
a given class pattern and to extract the corresponding attributes. It
|
||||
must be a class method or a static method returning an object
|
||||
(typically the same as the argument), or ``None`` to indicate that no
|
||||
match is possible. (More about the return value in the next section.)
|
||||
|
||||
The procedure is as following:
|
||||
|
||||
* The class object for ``Class`` in ``Class(<sub-patterns>)`` is looked up and
|
||||
``Class.__match__(obj)`` is called where ``obj`` is the value being matched.
|
||||
|
@ -684,7 +691,7 @@ required.
|
|||
|
||||
|
||||
The standard library
|
||||
------------------------------------
|
||||
--------------------
|
||||
|
||||
To facilitate the use of pattern matching, several changes will be made to
|
||||
the standard library:
|
||||
|
@ -1157,6 +1164,8 @@ In sample programs using `match`, written as part of the development of this
|
|||
PEP, a noticeable improvement in code brevity is observed, more than making up
|
||||
for the additional indentation level.
|
||||
|
||||
TODO: flat indentation with "match: expression" at the top.
|
||||
|
||||
|
||||
Alternatives for constant value pattern
|
||||
---------------------------------------
|
||||
|
|
Loading…
Reference in New Issue