Server Tests Fail when Local Tests Succeed

Not sure what to do about this, other than alert those in power that the problem exists.

Working on the Proverb exercise in Python. Found a solution that passed local tests but failed on the server because of f-string line breaks. These lines were causing the problem:

conclusion = f'And all for the want of a {
        qualifier + ' ' if qualifier else ''}{args[0]}.'

The error on the server after submission was the following (after a bunch of stack traces):

E       conclusion = f'And all for the want of a {
E                    ^
E   SyntaxError: unterminated string literal (detected at line 4)

The line break was inserted by the automatic formatting plugin I have in VS Code. I got around it by re-writing the line without f-strings:

conclusion = 'And all for the want of a ' + \
    (qualifier + ' ' if qualifier else '') + args[0] + '.'

This is above my skill to even investigate, I’m afraid. Not sure it’s worth trying to fix given the specificity of the problem (f-strings that are broken mid-substitution into multiple lines).

If you’d like to take a look at the actual submission, you can find it here: Exercism. You’ll find Iteration 4 to be the latest vailing version.

It looks like you may be depending on Python 3.13’s new f-string features. Exercism uses 3.12 which has less flexible f-strings.

@IsaacG – we are on Python 3.11.5. And AFAK, breaking across lines in an f-string is still not permitted even in 3.13.

1 Like

Hi @chivalry :wave:

Not sure what formatting tool you are using for VSCode, but the “canonical” preferred way to break a str or f-string (or other long chains) across multiple lines is to use Python’s implicit concatenation (quoting from PEP 8):

The preferred way of wrapping long lines is by using Python’s implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

The error you are seeing from the server is an error from Python 3.11 itself. It can’t figure out where the string literal ends, because there is a line break in the middle of things, and/or there is quote reuse.

Rewriting the line to:

conclusion = ("And all for the want of a "
f"{qualifier + ' ' if qualifier else ''}{args[0]}.")

or


conclusion = (f"And all for the want of a {qualifier + ' ' if qualifier else ''}"
              f"{args[0]}.")

Should fix it, but as Isaac has said above, we’re on Python 3.11, so you need to be mindful of quotes. You have to use " if internally you are going to use ', and vice-versa.

1 Like

@chivalry

The new grammar for f-strings (that IsaacG mentions) appeared in Python 3.12 (not 3.13) – so if you’re running that version locally, it explains why it works for you.

See the description in What’s new in Python 3.12.