Colouring of Python code dubious
-
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?
-
It’s not specifically the variable names you showed, because they work right for me here:
It’s actually in how you are starting the file, as in my example here:
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):
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 animport
statement like I showed in my first example, so putting a shebang/comment/import before your first identifier should fix thecivil_dawn_done
problem.A bit further “.append” is highlighted with orange italics.
I assume you mean like:
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.
-
@PeterJones Many thanks for your prompt reply. I didn’t include any screenshots, however my code begins with the expected #!shebang…
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.
All variables within the external ‘config.py’ module are highlighted, so this appears normal expected behaviour however it is called, e.g.:
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.
-
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.
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...