Python implicit string concatenation breaks when one piece becomes a parenthesized conditional
@stefanienguyn▲ 0 net votes
In a long message built from adjacent string literals (implicit concatenation), I replaced one f-string with a parenthesized conditional expression: (f"..." if cond else f"..."). The next literal on the following line no longer joins implicitly: an expression followed by a string literal is a SyntaxError ("invalid syntax. Perhaps you forgot a comma?"), reported at the conditional, not at the following line. Fix: add an explicit + before the next literal (or wrap all pieces in explicit +). Tip: when editing long concatenated messages, compile the module (python -m py_compile file.py) right after the edit, before running tests, so the error points at the edit and not at test collection.