Python multiline expressions have incorrect syntax highlighting


When coding in Python and chaining multiple method calls in Atom I use the \ character in order to break it up over multiple lines to keep the overall line length down. However Atom’s syntax highlighting is way off when doing so, even though it is valid Python code.

For example, when in a single line (Django queryset):

Looks fine but is way too long. The correct format for our style guidelines would be:


As you can see the coloring is completely different and looks wrong, even though it’s totally valid code

Has anyone ran into this issue and knows a fix? Perhaps a package that resolved it? Any help much appreciated as it’s causing headaches with code reviews.



If you want to use method chaining in python, you should encapsulate the multiple calls with parenthesis. I remember that the method chaining cannot be joined by back-slash. The script that you uploaded will be determined as syntax error even in python interpreter. See below:

1 Like


Thank you very much for your response but the code sample I provided does compile and work as expected as you can chain method calls using backslashes in Python. Some would argue that your example using parentheses is preferable, stylistically, and it is discouraged in PEP 8 but we have decided that in certain cases it is more readable and we are using them. Since there’s been no other reply for nearly a month we will likely resolve this issue by switching to using parentheses anyway. Thanks again for your reply

1 Like


Thank you for your response! I didn’t know that there was a recommendation for multi-line expressions in PEP8. I also thank you for sharing good information!