On 10/22/2020 11:04 AM, Guido van Rossum wrote:
Another way this could go: If PEP 634 (pattern matching, reborn) gets
accepted, a future Python version could add f-string patterns (which
the PEP currently forbids). E.g.
```
x = "123 456 789"
match x:
case f"{a} {b}": print("A pair:", a, b)
case f"{a} {b} {c}": print("Triple", a, b, c)
```
Everything else (e.g. how to design the formatting language) would be
open. We could even designate "raw" f-strings (rf"...") as regular
expressions (<wink 0.5>).
I think it makes sense to move this into pattern matching, since it
already has the variable binding baked in and well specified.
As you say, it still leaves all of the issues about specifying the
format language. But as I've said, I think that should be done outside
of any syntax proposal, and could be done now. In particular it should
address returning types other than str. As MRAB points out (and assuming
the proposal allows type conversion), how would it specify datetimes,
decimals, etc., and how would it be extensible? And if it does specify
type conversions, I think it would need to be something that could be
understood by mypy.
Eric
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/7IM3XSEVNCRJAGK46FAFMAVORSSGXOXX/
Code of Conduct: http://python.org/psf/codeofconduct/