On 2020-08-03 05:21, Guido van Rossum wrote:
Your point about wanting a way to use an unqualified name as a value pattern is not unreasonable, and as you may recall we had an elegant solution in version 1 of the PEP: a leading dot. However that was booed away by the critics, and there has been no consensus (not even close) on what to do instead.

Any solution that involves special markup (like bringing back the leading dot, or backticks, or a question mark, or any other sigil) can easily be added in a future version of Python.

There is one solution that I personally find acceptable but which found little support from the other PEP authors. It is a rule also adopted by Scala. This is to make it so that any identifier starting with a capital letter (possibly preceded by one or more underscores) is a value pattern. I note that in Scala, too, this is different in patterns than elsewhere in the language: Scala, like Python, allows identifiers starting with a capital letter to be assigned in other contexts -- just not in patterns. It also uses roughly the same *conventions* for naming things as PEP 8 (classes Capitalized, constants UPPERCASE, variables and methods lowercase). I also note that Scala allows backticks as another way to force interpretation as a value pattern (though apparently it's not used much for this purpose).

[snip]
A thought occurred to me. By default, the current rules of the PEP could apply, but why not allow prefixing with "as" for a capture and "is" for a value?

Yes, I know, comparison of the values is not by identity, but "is" is a short keyword that already exists and matches up with "as".


(After looking back through the thread it looks like Rob Cliffe has already had the same idea.)
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/XVAJ76OOVFT3RJXDJH3BRNEHOFS7PAJS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to