Search code examples
pycharm

Pycharm Syntax Highlighting not working properly for variables


I am using the newest Pycharm Professional Release 2023.3.2 (same issue with 2023.3.1)

If i define a variable within a function, the highlighting for this variable works. If i define it outside a function, it does not work. I've tried several color schemes (dark, monokai, and community ones) and none of them highlight the variable outside a function.

Is this expected or am i missing something?.. According to the color scheme preview, these variables should get highlighted.

[highlighting1

Preview:

preview


Solution

  • It is the expected behavior of PyCharm.

    In the preview, x represents a local variable. enter image description here Notice that when I select Local variables in the settings, a rectangle surrounds x. (This description might seem awkward, but that's how it works).

    In your code, five is not a local variable.

    You can alter the color of global variables by enabling semantic highlighting. However, I think you cannot modify other settings for global variables. (See How to change variable name color?)