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]):
self._fn = fn
def __str__(self) -> str:
return self._fn()
...
logger.info(Msg(lambda: f"The current name is {name}"))
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/ZXRUDEMIY4AV3SIVIEAWHFKFMPGOLI4J/
Code of Conduct: http://python.org/psf/codeofconduct/