Repository navigation
Autocompletion per PEP 526 Type Annotations Not Working For List[x] where x is int, str, etc... #2446
Copy link
Copy link
Closed
Labels
area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
Environment data
- VS Code version: 1.26.1
- Extension version (available under the Extensions sidebar): 2018.7.1
- OS and version: macOS 10.13.6
- Python version (& distribution if applicable, e.g. Anaconda): 3.7.0 (pyenv, miniconda)
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda, pyenv
- Relevant/affected Python packages and their versions: NA
Actual behavior
Type hinting not working for some PEP 526 style annotations (in my case List[?] does not work)
Expected behavior
Type hinting to recognize variable type annotations in the function declaration. Screenshot below of what I would expect from above (note in the function declaration I did not specify the type in the list).
Steps to reproduce:
-
Create new python file
-
Specify any Python 3.6+ interpretter
-
fill out
from typing import List def foo(a: List[int]): a.# now wait for auto-complete
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Starting Microsoft Python language server.
[Info - 3:56:19 PM] Created Microsoft.PythonTools.Interpreter.Ast.AstPythonInterpreter instance from Microsoft.PythonTools.Interpreter.Ast.AstPythonInterpreterFactory
Initializing for /Users/ogi/.pyenv/versions/miniconda3-latest/bin/python
[Info - 3:57:41 PM] Found 198 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (1, 2) after filtering
[Info - 3:57:42 PM] Found 334 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (1, 7) after filtering
[Info - 3:57:43 PM] Found 1 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (1, 14) after filtering
[Info - 3:57:44 PM] Found 119 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (1, 21) after filtering
[Info - 3:57:45 PM] Found 119 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (1, 21) after filtering
[Info - 3:57:47 PM] Found 199 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (3, 2) after filtering
[Info - 3:57:50 PM] Found 182 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (3, 13) after filtering
[Info - 3:57:52 PM] Found 182 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (3, 18) after filtering
[Info - 3:57:54 PM] Found 204 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (4, 6) after filtering
[Info - 3:57:54 PM] Found 2 completions for file:///Users/ogi/Academic/CS532/demo/test.py at (4, 7) after filtering
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)
workbench.main.js:sourcemap:1397 INFO no standard startup: panel is active
workbench.main.js:sourcemap:4188 Overwriting grammar scope name to file mapping for scope source.swift.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/swift/syntaxes/swift.tmLanguage.json.
New grammar file: file:///Users/ogi/.vscode/extensions/Kasik96.swift-0.0.3/syntaxes/swift.tmLanguage
e.register @ workbench.main.js:sourcemap:4188
workbench.main.js:sourcemap:1398 ERR Illegal argument: character must be non-negative: Error: Illegal argument: character must be non-negative
at Object.t.illegalArgument (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:95:675)
at new e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:472:92)
at e.translate (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:473:725)
at getPrecedingRange (/Users/ogi/.vscode/extensions/njpwerner.autodocstring-0.2.3/src/extension.ts:55:39)
at processEnter (/Users/ogi/.vscode/extensions/njpwerner.autodocstring-0.2.3/src/extension.ts:41:17)
at activateOnEnter (/Users/ogi/.vscode/extensions/njpwerner.autodocstring-0.2.3/src/extension.ts:35:9)
at context.subscriptions.push.vs.workspace.onDidChangeTextDocument.changeEvent (/Users/ogi/.vscode/extensions/njpwerner.autodocstring-0.2.3/src/extension.ts:23:34)
at e.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:98:218)
at e.$acceptModelChanged (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:728:571)
at e._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:671:983)
at e._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:671:701)
at e._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:670:767)
at e._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:670:536)
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:669:452
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:672:575
at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:96:903
at e.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:98:218)
at a (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:162:713)
at Socket._socketDataListener (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:162:932)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at Pipe.onread (net.js:594:20)
2workbench.main.js:sourcemap:1398 ERR Cannot read property 'map' of null: TypeError: Cannot read property 'map' of null
at asCompletionResult (/Users/ogi/.vscode/extensions/ms-python.python-2018.7.1/node_modules/vscode-languageclient/lib/protocolConverter.js:145:51)
at <anonymous>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug


Activity
brettcannon commentedon Aug 27, 2018
I can replicate this.
Mikhail Arkhipov (@MikhailArkhipov) can't quite decide if I want to make this a P1 since a decent amount of type hints will be a generic like this, but it also doesn't crash the language server or prevent it from working otherwise.
egabrum commentedon Oct 11, 2018
Ogi Moore (@j9ac9k) I can reproduce on VSC 1.28.0 and Python 2018.9.0
Autocompletion with type annotation only works for me if I use Python 3.6.6 as interpreter and Jedi as Intellisense engine. NOTE THAT IT WORKS WITH Python 3.6.6 :-???
It does NOT work with:
egabrum commentedon Oct 11, 2018
Ogi Moore (@j9ac9k) In my case, looks like
a: Listworks, but nota: List[int]j9ac9k commentedon Oct 11, 2018
egabrum that's the case I'm seeing too.
MikhailArkhipov commentedon Oct 15, 2018
j9ac9k commentedon Oct 15, 2018
Mikhail Arkhipov (@MikhailArkhipov) would it work if you just did
a.(and await auto-complete), ...or in other words, does it recognize thatais a list?jakebailey commentedon Oct 15, 2018
I'm not sure that the generic type
Listrequires more than that it can be indexed (__getitem__) and iterated (__iter__), versus also including things likeappendorcopy: https://docs.python.org/3/library/typing.html#typing.List(However, it behaving differently between
a: Listanda: List[str]doesn't seem right.)j9ac9k commentedon Oct 15, 2018
If you look at my second screenshot in the original post, you can see that not specifying the type of the list does result in autocomplete suggesting
append,copyand so on.jakebailey commentedon Oct 15, 2018
You caught me just as I was editing my comment to strike that out. 🙂 Using
Listorlistworks fine.After reading through
typing.pyin the typing repo, it looks likeListis defined as:Which implies that it's being treated as a subclass of
list, so the analysis we do should have probably also shown those methods. There's likely something we need to fix forList[T]. Since this is a language server thing, we'll probably be investigating more over on microsoft/python-language-server#260.j9ac9k commentedon Oct 15, 2018
FWIW I think
jediis behaving the same way (or something weird and unique on my system)Anyway if there is anything else I can help with testing, please let me know.
MikhailArkhipov commentedon Nov 5, 2018
microsoft/python-language-server#321
j9ac9k commentedon May 3, 2019
I think this issue can be closed now? Last I checked this was working as intended.
egabrum commentedon May 4, 2019
For me, it still doesn't work with Jedi and Python 3.7 (It does work when I switch to Python 3.6.6, for some reason)
j9ac9k commentedon May 4, 2019
egabrum I think that's a jedi issue?
egabrum commentedon May 4, 2019
Ogi Moore (@j9ac9k) Possibly. Is there a way to figure out whether it is purely a Jedi problem, or the interaction with VSCode, or the version that VSCode uses?
j9ac9k commentedon May 4, 2019
brettcannon commentedon May 10, 2019
Ogi Moore (@j9ac9k) thanks for validating the fix!
egabrum you can check if Jedi works as expected by setting
"python.jediEnabled": true. If it doesn't work you can open a separate issue (on us or Jedi itself).