|
|
Subscribe / Log in / New account

Formalizing f-strings

Formalizing f-strings

Posted Jan 10, 2023 23:25 UTC (Tue) by KaiRo (subscriber, #1987)
Parent article: Formalizing f-strings

IMHO, it's fine to allow quote reuse in this PEP, but the PEP-8 guidelines/standard should be extended to discourage quote reuse at least in single-line f-strings.


to post comments

Formalizing f-strings

Posted Jan 11, 2023 2:31 UTC (Wed) by JoeBuck (subscriber, #2330) [Link]

It's a similar issue, I think, to shadowing in C/C++. We can have
int foo;
code;
if (condition) {
    double foo;
    use(foo);
}
and the behavior is well-defined but not recommended, so we have -Wshadow. The {...} in an f-string is a similar kind of inner scope. Re-use of the same quote character can be confusing and perhaps might produce a warning, but it's not difficult to parse, and forbidding it can be more work than letting it pass.

Formalizing f-strings

Posted Jan 11, 2023 11:43 UTC (Wed) by smurf (subscriber, #17840) [Link]

"Discourage" isn't the same as "forbid", though. With this change, I can now copy+paste an arbitrary expression directly from my code into an f-string that reports its value, and I don't have to bother with quoting or any other may-not-appear-in-an-fstring-ism.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds