Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

PEP hint does not work in Python 2.7 #1073

Description

Use python 3.6 interpreter ("Python 3.6.6" from Anaconda). It works

image

Use python 2.7 interpreter ("Python 2.7.16" from Anaconda). It does not work, no popup :(
if I do y = 3 then it deduces type to int and I see the popup completion again

Activity

  1. MikhailArkhipov commented on May 14, 2019

    @MikhailArkhipov
    Author

    This is b/c internally expression is extracted and parsed as annotation but since parser is created off current configuration it is 2.7 and hence is unable to parse type annotations. The fix is to always parse hints as 3.x.

  2. makzimus commented on May 14, 2019

    @makzimus

    I did a quick step through of the source, it's constructing the fragment x: int to pass to the parser which then fails this check:
    Parser.cs:918
    if (PeekToken(TokenKind.Colon) && (_stubFile || _langVersion >= PythonLanguageVersion.V36)) {
    It's explicitly checking the python version there.

    Using the Parser option StubFile causes it to succeed and the type is now correct in vscode, but I'm unsure if this is the correct fix.

  3. MikhailArkhipov commented on May 14, 2019

    @MikhailArkhipov
    Author

    The fix was to always parse annotation fragment as 3.6+ rather than as currently set Python.

  4. makzimus commented on May 14, 2019

    @makzimus

    I just scrolled up after I posted! Awesome, good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions