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 -- 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/ZXRUDEMIY4AV3SIVIEAWHFKFMPGOLI4J/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to