Can autocompletion for inheritance in vscode auto-import types python?

Viewed 404

When using autocompletion for python in vscode in the case of overriding children methods, the autocompletion works nicely and writes all the types hints from the parent method.

However there are some typing hints that require imports. Is it possible to setup automatic import for that in vscode, such that when autocompletion is used for that case, the types are auto-imported ?

See before autocompletion

before autocompletion

And after autocompletion, types are missing

after autocompletion

1 Answers

With extension My Code Actions you can setup code actions to add imports based on the diagnostic messages (squiggles).

Add this to your settings.json

"my-code-actions.actions": {
    "[python]": {
      "import {{diag:$1}}": {
        "diagnostics": ["\"(.*?)\" is not defined"],
        "text": "import {{diag:$1}}\n",
        "where": "afterLast",
        "insertFind": "^(import |from \\w+ import )"
      }
    }
  }
Related