• Login
Community
  • Login

Colouring of Python code dubious

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
python
4 Posts 2 Posters 357 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Andrew Bauer
    last edited by Jan 7, 2025, 7:50 PM

    I have been using Notepad++ since the days of Python 2. I have always found the colouring applied to Python code sensible and intuitive … until recently. For example, why is the variable within “civil_dawn_done = []” coloured orange and in italics, whereas within “civil_dusk_done = []” plain black (which I assume is correct)?

    A bit further “.append” is highlighted with orange italics. Why?

    I fully approve when text (raw or not) within triple apostrophes is highlighted orange. That’s very useful. But again - one of my config variables (PV_nsa within “config.PV_nsa”) is highlighted orange italics. Why?

    Is there a reference guide as to the intended meaning of colouring and font applied to Python 3 code?

    P 1 Reply Last reply Jan 7, 2025, 8:13 PM Reply Quote 0
    • P
      PeterJones @Andrew Bauer
      last edited by Jan 7, 2025, 8:13 PM

      @Andrew-Bauer ,

      It’s not specifically the variable names you showed, because they work right for me here:

      ace78cef-bb9e-4d14-82f9-f48ce6830fc9-image.png

      It’s actually in how you are starting the file, as in my example here:

      265014ab-53d7-484a-a03b-7bbd3e8649ad-image.png

      There is a known bug in the “Lexilla” library that Notepad++ uses for syntax highlighting, where if the first line of a python file starts with an identifier, it will mis-categorize the identifier as a decorator (which is supposed to be for things like the @property decorator):
      49126abe-71f7-4564-8ca5-cc5d9a06f638-image.png

      Until the Lexilla library is fixed, Notepad++ cannot fix the problem. But in general, Python code usually starts with a #!shebang or # other comment or at least an import statement like I showed in my first example, so putting a shebang/comment/import before your first identifier should fix the civil_dawn_done problem.

      A bit further “.append” is highlighted with orange italics.

      I assume you mean like:
      db6add7f-5a2c-4af9-951e-6bd5ae9a2747-image.png

      That’s the ATTRIBUTE styling, which is applied to attributes and methods. If you don’t like that color, you can change Settings > Style Configurator > Language: Python > Style: ATTRIBUTE to set whatever color/bold/italic/underline you want for method calls and attributes.

      Is there a reference guide as to the intended meaning of colouring and font applied to Python 3 code?

      Not really. The Lexilla code just picked names for the styles that made sense to the author of that portion of Lexilla based on their understanding of Python2/Python3, and Notepad++ mostly just replicated that naming scheme into the Style Configurator.

      Though I’m not an expert Python programmer, most of the Style names in the Style Configurator overlap pretty well with the Python concept that it’s supposed to be representing, in my opinion. For example, DECORATOR matches the Python standard term “decorator” , and IDENTIFIER is used throughout programming as the name of a variable.

      A 1 Reply Last reply Jan 8, 2025, 4:52 PM Reply Quote 3
      • A
        Andrew Bauer @PeterJones
        last edited by Jan 8, 2025, 4:52 PM

        @PeterJones Many thanks for your prompt reply. I didn’t include any screenshots, however my code begins with the expected #!shebang…

        6f440047-2f17-4496-8c13-c271acdd264b-image.png

        Currently this Python module has 10,792 lines of code, and on line 4072 I saw the unexpected orange italic highlighting, which made no sense to me.

        4a6db2b4-87ea-4c46-9db3-92757ffd4a2b-image.png

        All variables within the external ‘config.py ’ module are highlighted, so this appears normal expected behaviour however it is called, e.g.:

        6f6f05cf-9733-4556-92b2-ceb7311522ec-image.png

        In addition, all numbers are orange+upright, which is good.

        So I only really question what’s going on in line 4072 (and I think it wasn’t orange+italic in some older versions of Notepad++).

        May I add that working with Notepad++ has been a very positive experience for me.

        P 1 Reply Last reply Jan 8, 2025, 5:15 PM Reply Quote 0
        • P
          PeterJones @Andrew Bauer
          last edited by Jan 8, 2025, 5:15 PM

          Currently this Python module has 10,792 lines of code, and on line 4072 I saw the unexpected orange italic highlighting, which made no sense to me.

          4a6db2b4-87ea-4c46-9db3-92757ffd4a2b-image.png

          As part of the same bug report, it was mentioned in one of the replies on the issue , that ending a Python comment with a . triggers the attribute formatting on the next line.

          This is because it’s looking for . followed by 0-or-more-whitespace (which includes newline) followed by what would otherwise be an identifier, and if it finds that, then instead of identifier, it treats the word as an attribute/method instead. So, to get around that bug, either remove the ... at the end of your comment, or put some other (non-whitespace) character after the ... - maybe use : instead of ...

          1 Reply Last reply Reply Quote 4
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors