Menu

#1020 Python multiline comments are wrong colour.

None
pending-invalid
nobody
v1.23.1
2
2014-02-25
2014-01-01
Mike Evans
No

Multiline Python comments enclosed by ''' to ''' (or """ to """) are not in the comment colour but are in the same colour as text anclosed by '' or "".

Discussion

  • Mike Evans

    Mike Evans - 2014-01-01

    Ah! I've just read the there is no such thing as multiline comments in Python, so maybe this isn't a valid bug as these are defined as multi-line strings. Please close this and sorry for the noise.

     
  • Colomban Wendling

    • labels: --> highlighting, python
    • status: open --> pending-invalid
    • Priority: 5 --> 2
     
  • Colomban Wendling

    Yes, the "multi-line" comments you're talking about are just plain strings. They are considered as "comments" only because they have no effect on the program, and allow verbatim text; but they still are syntactically strings.

    Coloring differently strings having no effect on the program behavior (hence being "comments") could be acceptable, but this would probably be overly complex (requires the parser to really understand the Python statement) for not so much benefit. If you though wish to work on this, see with the Scintilla project (the editing component we use) to get it patched.

     
  • Colomban Wendling

    @codebrainz pointed out to me that you can also simply change how the triple-quoted strings are highlighted using the color scheme feature, keys are triple (for '''...''') and tripledouble (for """..."""). This would affect all triple-quoted strings, but it might suit you, depending on your taste.

     
  • Mike Evans

    Mike Evans - 2014-01-02

    Thanks for the replies to my non-bug report. Using your previous suggestion would suit me just fine.

    I'm using geany-tango-dark theme and I've added a line "triple=0x43D731;0x2e3436;false;false" to geany-tango-dark.conf, and added "triple=triple" to the [styling] section of filetypes.python and it works perfectly. Awesome.

    Many thanks to you and codebrainz for the suggestion. Can I suggest that this makes into the docs at some point? I'll blog it, but no-one reads my blog, it's more a reminder for future-me.

    Happy new year to you all and thanks for your comments.

     
  • Simon Wiles

    Simon Wiles - 2014-02-25

    I'd be very much in favour of Colomban Wendling's suggestion of "[c]oloring differently strings having no effect on the program behavior". This seems to be the most correct way of handling it, given the BDFL's support for this syntax for multiline comments. I'll see if I can find a way to do it in Scintilla -- oughtn't to be too hard, I think?

     
  • Lex Trotman

    Lex Trotman - 2014-02-25

    Snippets to test with:

    a = """I am not
            a comment"""
    a = [
    """ Neither am
        I """
    ]
    """ I am a
    comment """
    

    Good luck :)

     

Log in to post a comment.