[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Guido van Rossum
On Thu, Jun 24, 2021 at 10:34 AM micro codery wrote: > As pointed out already, f-strings and format are subtly different (not > counting that one can eval and the other cannot). Besides quoting, the > f-sting mini language has diverged from format's > >>> spam="Spam" > >>> f"{spam=}" > "spam='Spa

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Eric V. Smith
What part are you trying to delay, the expression evaluations, or the string building part? There was a recent discussion on python-ideas starting at https://mail.python.org/archives/list/python-id...@python.org/message/LYAC7JC5253QISKDLRMUCN27GZVIUWZC/ that might interest you. Eric On 6/24

[Python-Dev] Re: Towards removing asynchat, asyncore and smtpd from the stdlib

2021-06-24 Thread Barry Warsaw
On Jun 23, 2021, at 16:34, Miro Hrončok wrote: > Yes, we have a way to check all Fedora's Python packages by reusing our > Python 3.10 pre-releases test-rebuild-everything mechanism, but it takes a > few days to finish the builds and analyze the failures. Test failures caused > by DeprecationWa

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread micro codery
As pointed out already, f-strings and format are subtly different (not counting that one can eval and the other cannot). Besides quoting, the f-sting mini language has diverged from format's >>> spam="Spam" >>> f"{spam=}" "spam='Spam'" >>> "{spam=}".format(spam=spam) Traceback (most recent call las

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Eric Nieuwland
Except I like the mini-language of f-strings much better than format()’s. And there is a performance difference between f-strings and format(). > On 24 Jun 2021, at 19:03, Luciano Ramalho wrote: > > I don't think that would be a good idea since we already have > .format() which covers that use

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Eric Nieuwland
I didn’t make myself clear, sorry. The code example was just to give an initial what I was suggesting. The errors you show demonstrate the example is incomplete. I’d like them to work. > On 24 Jun 2021, at 18:37, Martin (gzlist) wrote: > > On Thu, 24 Jun 2021 at 17:25, Eric Nieuwland wrote: >>

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Luciano Ramalho
I don't think that would be a good idea since we already have .format() which covers that use case and is more flexible than f-strings (it supports positional arguments, as well as *args and **kwargs). I think keeping f-strings simple is a better idea. Best, Luciano On Thu, Jun 24, 2021 at 1:30

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Martin (gzlist) via Python-Dev
On Thu, 24 Jun 2021 at 17:37, Martin (gzlist) wrote: > > >>> d = dict(a=1) > >>> f'{d["a"]}' > '1' > >>> str(DelayedFString('{d["a"]}')) > Traceback (most recent call last): > File "", line 1, in > File "", line 5, in __str__ > KeyError: '"a"' And the other si

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Martin (gzlist) via Python-Dev
On Thu, 24 Jun 2021 at 17:25, Eric Nieuwland wrote: > > class DelayedFString(str): > def __str__(self): > vars = inspect.currentframe().f_back.f_globals.copy() > vars.update(inspect.currentframe().f_back.f_locals) > return self.format(**vars) This isn't quite right as

[Python-Dev] Re: Delayed evaluation of f-strings?

2021-06-24 Thread Thomas Grainger
for your usecase I'd write: def delayed_fstring(*, name: str) -> str: return "The current name is {name}" def new_scope() -> None: for name in ["foo", "bar"]: print(delayed_fstring(name=name)) for logging I use: class Msg: def __init__(self, fn: Callable[[], str]):

[Python-Dev] Delayed evaluation of f-strings?

2021-06-24 Thread Eric Nieuwland
In a recent discussion with a colleague we wondered if it would be possible to postpone the evaluation of an f-string so we could use it like a regular string and .format() or ‘%’. I found https://stackoverflow.com/questions/42497625/how-to-postpone-defer-the-evaluation-of-f-strings and tweake

[Python-Dev] Re: Roundup to GitHub Issues migration

2021-06-24 Thread Barry Warsaw
That sounds great, thanks Mariatta. -Barry > On Jun 23, 2021, at 12:36, Mariatta wrote: > > My understanding is that Ezio is/will be working on updating PEP 588. > Last I heard from Ezio is that he would be co-author of PEP 588 and he would > be updating it/rewrite it to better match the curre