Intellisense not recognising type hinting for python 3
Asked Answered
T

1

7

I would like to use Visual Studio and see intellisense using type hints, for example in the function argument list, to workout the type of a variable.

enter image description here

This can be achieved through isinstance(param,type) statements, but I wonder if we can get it to work without these additional statements:

enter image description here

Note: I have tried Visual Studio with Python Tools for Visual Studio and also the early 2017 Visual Studio Preview, that has python support built in, but neither seem to appreciate type hints.

Tortola answered 4/7, 2017 at 9:3 Comment(3)
Hi Robino, I tried this code in my VS 2017(15.2) with python application, the result as yours. Research the python tutorial: docs.python.org/2/tutorial/classes.html and the function definitions (def statements) does not have the parameter syntax like (xxx:str), I suppose you used the wrong parameter. The result that you expected in the second screenshot is due to the statement “assert isinstance(bar,str)” and I tested it, directly use the statement to define another variable and it works as your expected, please check this screenshot: 1drv.ms/i/s!Atv5QNuFrncKgnC1jAYAnOtd4FknPill
@Sara-MSFT The code posted is error free. The syntax you see here is called "type hinting" and you can learn more about it here docs.python.org/3/library/typing.html.Tortola
Hi Robino, thank you for your correction and I have reported this question to the Python tools for Visual Studio support team in here: github.com/Microsoft/PTVS/issues/2773 and waiting for their confirmation, then I will update it in here.Pill
P
2

After confirmed, this result is by designed, please check this: Python 3.6: using type hints to describe a variable in the function argument list and the Quick Info of this variable display ‘unknown type’

Int19h: The result is as expected currently, because PTVS does not yet support type hints to drive code completion. The following issue is tracking that feature: #82.

Pill answered 7/7, 2017 at 8:30 Comment(2)
Thanks for the LMMSCTFY (Let Me Microsoft Communities That For You) answer. This question's answer may change over time so I may deselect "accept this answer" if this (hopefully) happens.Tortola
This was implemented in this commitAilsun

© 2022 - 2025 — McMap. All rights reserved.