Hacker News new | ask | show | jobs
by ggm 1515 days ago
Maybe catenation of an fString and a string should yield an fString by type promotion? String is morally "any" so it feels to me like a contextual narrowing of type.
2 comments

What if you wanted to append a string with braces, could you? (I don’t know Python!)

Plus it would lead to subtle security vulns and other bugs. A contrived example :

f”{bot} spammed my repo saying” + “touch(‘{path}’) was wrong lol.”

Now my path var has been disclosed.

If you want braces in your f strings you double them up.

Ex:

n = "hn"

print(f"hello {n} your path is {{path}}")

Out: hello hn your path is {path}

Strings and f-strings are not separate types in Python, sadly.