Skip to content

Autocompletion per PEP 526 Type Annotations Not Working For List[x] where x is int, str, etc... #2446

Closed

Description

@j9ac9k

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)

screen shot 2018-08-24 at 3 07 22 pm

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).

screen shot 2018-08-24 at 3 46 04 pm

Steps to reproduce:

  1. Create new python file

  2. Specify any Python 3.6+ interpretter

  3. 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>

Activity

  1. brettcannon commented on Aug 27, 2018

    @brettcannon
    Member

    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.

  2. egabrum commented on Oct 11, 2018

    @egabrum

    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:

    • Microsoft Python Analysis Engine (any Python interpreter).
    • Jedi as engine and Python 3.7.0
  3. egabrum commented on Oct 11, 2018

    @egabrum

    Ogi Moore (@j9ac9k) In my case, looks like a: List works, but not a: List[int]

  4. j9ac9k commented on Oct 11, 2018

    @j9ac9k
    Author

    egabrum that's the case I'm seeing too.

  5. MikhailArkhipov commented on Oct 15, 2018

    @MikhailArkhipov

    image

  6. j9ac9k commented on Oct 15, 2018

    @j9ac9k
    Author

    Mikhail Arkhipov (@MikhailArkhipov) would it work if you just did a. (and await auto-complete), ...or in other words, does it recognize that a is a list?

  7. jakebailey commented on Oct 15, 2018

    @jakebailey
    Member

    I'm not sure that the generic type List requires more than that it can be indexed (__getitem__) and iterated (__iter__), versus also including things like append or copy: https://docs.python.org/3/library/typing.html#typing.List

    (However, it behaving differently between a: List and a: List[str] doesn't seem right.)

  8. j9ac9k commented on Oct 15, 2018

    @j9ac9k
    Author

    I'm not sure that the generic type List requires more than that it can be indexed (__getitem__) and iterated (__iter__), versus also including things like append or copy: https://docs.python.org/3/library/typing.html#typing.List

    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, copy and so on.

  9. jakebailey commented on Oct 15, 2018

    @jakebailey
    Member

    You caught me just as I was editing my comment to strike that out. 🙂 Using List or list works fine.

    After reading through typing.py in the typing repo, it looks like List is defined as:

    class List(list, MutableSequence[T], extra=list):

    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 for List[T]. Since this is a language server thing, we'll probably be investigating more over on microsoft/python-language-server#260.

  10. j9ac9k commented on Oct 15, 2018

    @j9ac9k
    Author

    FWIW I think jedi is 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.

  11. MikhailArkhipov commented on Nov 5, 2018

    @MikhailArkhipov
  12. j9ac9k commented on May 3, 2019

    @j9ac9k
    Author

    I think this issue can be closed now? Last I checked this was working as intended.

  13. egabrum commented on May 4, 2019

    @egabrum

    I think this issue can be closed now? Last I checked this was working as intended.

    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)

  14. j9ac9k commented on May 4, 2019

    @j9ac9k
    Author

    egabrum I think that's a jedi issue?

  15. egabrum commented on May 4, 2019

    @egabrum

    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?

  16. j9ac9k commented on May 4, 2019

    @j9ac9k
    Author
  17. brettcannon commented on May 10, 2019

    @brettcannon
    Member

    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).

  18. locked as resolved and limited conversation to collaborators on Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions