Autocompletion per PEP 526 Type Annotations Not Working For List[x] where x is int, str, etc...
See original GitHub issueEnvironment 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>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:17 (4 by maintainers)
Top Results From Across the Web
PEP 484 – Type Hints - Python Enhancement Proposals
For example, here is a simple function whose argument and return type are declared in the annotations: def greeting(name: str) -> str: return...
Read more >Writing Good Code - Python Like You Mean It
A function signature that has been annotated with type-hints def count_vowels(x: str) -> int: """Returns the number of vowels contained in `in_string`""" ...
Read more >Mypy Documentation - Read the Docs
This chapter introduces some core concepts of mypy, including function annotations, the typing module, stub files, and more. If you're looking for a...
Read more >Support Python 3.6 PEP 526 Syntax for Variable Annotations
Support Python 3.6 PEP 526 Syntax for Variable Annotations ... False positive "is not used" for uninitialized variables with PEP 526 type annotation....
Read more >[Python-Dev] Please reject or postpone PEP 526
There are still plenty of issues to iron out w.r.t. PEP 484 types. I ... def __init__(self, damage: int, captain: str = None):...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can replicate this.
@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.
https://github.com/Microsoft/python-language-server/pull/321