0

When I attempt to import a module from a local package (from core import config), VSCode's syntax highlighting isn't working. When hovering over config, it shows "config: Any" (the editor should show "config: module"), indicating it's not recognizing the module for some reason. It has no syntax highlighting, and VSCode doesn't provide autocomplete for any parts of the config module.

from core.config import something works, but that's not what I need to do. For some reason, VSCode autocomplete suggests importing the module from itself, like this :

from core.config import config

This fixes the syntax highlighting, but that code is actually wrong throws an error when the script is run in the Python interpeter.

Here's the file structure I'm using.

I don't want to change my code or add any files-I only want a solution with VSCode config or something similar. Note that jedi completely ignores modules.

New contributor
Иван Чернецов is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • What file are you importing from? Is from core import config in your init.py? That could affect where VSCode sees the module. Commented Nov 15 at 18:01
  • @Rumi-SEMustFollowtheCC-SA it happens in any file i tried importing these in init.py, but that doesnt affect anything at all Commented Nov 15 at 23:43

2 Answers 2

0

Try Below Solutions:

  1. Switching to the Dark+ Theme could fix the syntax which was highlighting not being enabled, or disabling the dark reader extension.

    1. Ctrl + Shift + P

    2. Type Preferences: Color Theme

    3. Select either Dark Modern or Dark+

  2. Try plugin id evgeniypeshkov.syntax-highlighter (Syntax Highlighter).

  3. Go through

    1. File > Preferences > Settings

    2. Search for python.languageServer

    3. Change the setting as required: It should be set to Default or Pylance though for some reason switched over to Jedi

      enter image description here

    4. Restart Visual Studio Code

  4. It might be that Catalina installation didn't remove your Python installation.

    1. Open the command palette (Command + Shift + P)

    2. Type Python: Select Linter and select pylint

    3. Select the Install with Conda option

    4. Restart VS Code.

Sign up to request clarification or add additional context in comments.

1 Comment

apparently the problem is deeper, vscode doesnt just highlight modules improperly, it doesnt understands what im even trying to import because it shows type hint "Any" and i cant go to definition
0

Problem was caused by other folder with same name, for some reason VS Code can distinguish modules only by names. To solve this, i just deleted other /core directory and it does work properly now,

New contributor
Иван Чернецов is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.