[Python-ideas] Let’s make escaping in f-literals impossible

Chris Angelico rosuav at gmail.com
Fri Aug 19 15:00:57 EDT 2016


On Sat, Aug 20, 2016 at 4:43 AM, Eric V. Smith <eric at trueblade.com> wrote:
> Maybe I'm the odd man out, but I really don't care if my editor ever syntax
> highlights within f-strings. I don't plan on putting anything more
> complicated than variable names in my f-strings, and I think PEP 8 should
> recommend something similar.

I'd go further than "variable names", and happily include attribute
access, subscripting (item access), etc, including a couple of levels
of same:

def __repr__(self):
    return f"{self.__class__.__name__}(foo={self.foo!r}, spam={self.spam!r})"

But yes, I wouldn't put arbitrarily complex expressions into
f-strings. Whether PEP 8 needs to explicitly say so or not, I would
agree with you that it's a bad idea.

ChrisA


More information about the Python-ideas mailing list