Remix.run Logo
xg15 3 days ago

here's a valid f-string:

>>> f'{'}'}' '}'

Huh? I remember learning the rule that you can't nest quotes inside fstrings if they are the same kind (unlike in bash) - e.g

  f"{mydict["foo"]}"
would be a syntax error, but

  f"{mydict['foo']}"
or

  f'{mydict["foo"]}'
would be valid.

The reason being the same like for the rstring weirdness: The lexer comes first and identifies the string literal, then for fstrings, the python parser is invoked again for each {...} expression to parse it.

This is unlike other nested expressions, which are already split up by the lexer and then parsed in one go.

Did that change at some point?

xg15 3 days ago | parent [-]

Update: They really changed it! (in python 3.12)

There was a PEP about it:

https://stackoverflow.com/questions/78388333/nested-quotes-i...

https://docs.python.org/3.12/whatsnew/3.12.html#pep-701-synt...

globular-toast 2 hours ago | parent [-]

Wow, I didn't know this either. I find it a bit crazy. It must make no sense without syntax highlighting. But I suppose who writes code without highlighting any more?

dotancohen 2 hours ago | parent [-]

It's been a long time since I've had to SSH into a box to fix an issue in production. But it is comforting to know that I _could_.

VI (not even VIM) on minimal Debian installs does not have syntax highlighting.

vova_hn2 an hour ago | parent [-]

How often do you have SSH access to a box but don't have SFTP access?

Most IDEs support editing files on a remote machine through SFTP.