PEP 622: Clarify the status of True, False and None as literals
This commit is contained in:
parent
1560745bdc
commit
8f43d3ef64
14
pep-0622.rst
14
pep-0622.rst
|
@ -215,7 +215,7 @@ Literal Pattern
|
|||
~~~~~~~~~~~~~~~
|
||||
|
||||
A literal pattern consists of a simple literal like a string, a number,
|
||||
a boolean, or ``None``::
|
||||
a Boolean literal (``True`` or ``False``), or ``None``::
|
||||
|
||||
match number:
|
||||
case 0:
|
||||
|
@ -237,6 +237,16 @@ 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``.
|
||||
|
||||
Note that because equality (``__eq__``) is used, and the equivalency
|
||||
between Booleans and the integers ``0`` and ``1``, there is no
|
||||
practical difference between the following two::
|
||||
|
||||
case True:
|
||||
...
|
||||
|
||||
case 1:
|
||||
...
|
||||
|
||||
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).
|
||||
|
@ -284,6 +294,8 @@ Note: one can still match on a collection with equal items using `guards`_.
|
|||
Also, ``[x, y] | Point(x, y)`` is a legal pattern because the two
|
||||
alternatives are never matched at the same time.
|
||||
|
||||
Also note that ``None``, ``False`` and ``True`` are literals, not names.
|
||||
|
||||
|
||||
.. _constant_value_pattern:
|
||||
|
||||
|
|
Loading…
Reference in New Issue