classification
Title: Pattern Matching section in tutorial refers to | as or
Type: enhancement Stage:
Components: Documentation Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Daniel Moisset, brandtbucher, docs@python, gvanrossum, ramalho, rhettinger, willingc
Priority: normal Keywords:

Created on 2021-03-02 21:22 by ramalho, last changed 2021-03-03 18:39 by rhettinger.

Messages (3)
msg387973 - (view) Author: Luciano Ramalho (ramalho) * Date: 2021-03-02 21:29
Section 4.6. "match Statements" of the Python 3.10 tutorial says:

"""
You can combine several literals in a single pattern using | (“or”):
"""

For someone just learning Python, this may suggest that | is always "or", when in fact it is a bitwise operator (that may be overloaded), but inside a match clause has this special meaning without any overloading. 

I believe this exception should be made explicit in section 4.6, otherwise it may lead readers of the tutorial to a misconception.
msg387993 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-03-03 01:26
This seems fine to me.   In pattern matching, it has both the meaning and pronunciation of "or":

    case "this" | "that": ...

It has similar mean in the re module:

    r'abc|def'

And it is also used the same way in typing:

   s: list | tuple

We've also long used it for sets:

   rich | tall       # People who are either rich OR tall  

Based on this, I don't there is any reason to suspect it will be confused with bitwise-or.

The only place the operator really isn't harmonious is with dicts where its meaning is "update" and where it isn't commutative.
msg387996 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-03-03 03:41
Another other thought, PEP 634 defines "|" as being an "or-pattern", so it part of the spec:

  https://www.python.org/dev/peps/pep-0634/#or-patterns
History
Date User Action Args
2021-03-03 18:39:15rhettingersetnosy: + gvanrossum, willingc, Daniel Moisset, brandtbucher
2021-03-03 03:41:59rhettingersetmessages: + msg387996
2021-03-03 01:26:08rhettingersetnosy: + rhettinger
messages: + msg387993
2021-03-02 21:29:27ramalhosetassignee: docs@python
type: enhancement

components: + Documentation
versions: + Python 3.10
nosy: + docs@python
title: Pattern Matching section in tutorial refers to | as -> Pattern Matching section in tutorial refers to | as or
messages: + msg387973
2021-03-02 21:22:01ramalhocreate