On Wed., 24 Jun. 2020, 2:07 am Guido van Rossum, <guido@python.org> wrote:
I'm happy to present a new PEP for the python-dev community to review. This is joint work with Brandt Bucher, Tobias Kohn, Ivan Levkivskyi and Talin.

Very nice!

As with some others, the main thing that gives me pause is the elevation of "_" to pseudo keyword status by making it the wildcard character for pattern matching.

Users already find the existing common usages at least somewhat confusing [1], so adding a 5th use case will definitely make that situation worse.

The first alternative I can see would be to adopt regex wildcard notation for match patterns as well:

* exactly one arbitrary element: .
* any number of arbitrary elements: .*
* one or more arbitrary elements: .+
* zero or 1 arbitrary elements: .?

And then frame the ".name" reference syntax as another form of element constraint (matching a value lookup rather than being completely arbitrary).

Alternatively, the file globbing notation, "?", could be used as a new non-identifier symbol to indicate items that are present, but neither bound nor constrained (exactly as "_" is currently used in the PEP).

This syntax would have the added bonus of potentially being added to iterable unpacking, such that "a, b, *? = iterable" would mean "retrieve the first two items without trying to retrieve more than that" (whereas the existing throwaway variable convention still exhausts the RHS even when you only care about the first few items).

That said, I don't think the extra confusion generated by using "_" would be intolerable - I just think the possibility of using regex or globbing inspired wildcard notations is worth considering, and unless I missed something, the PEP doesn't currently cover any possible alternatives to using "_".

Cheers,
Nick.

[1] https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python