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.

Robino
  • 4,530
  • 3
  • 37
  • 40
  • Hi Robino, I tried this code in my VS 2017(15.2) with python application, the result as yours. Research the python tutorial: https://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: https://1drv.ms/i/s!Atv5QNuFrncKgnC1jAYAnOtd4Fkn – Sara Liu - MSFT Jul 05 '17 at 08:09
  • @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 https://docs.python.org/3/library/typing.html. – Robino Jul 05 '17 at 15:01
  • Hi Robino, thank you for your correction and I have reported this question to the Python tools for Visual Studio support team in here: https://github.com/Microsoft/PTVS/issues/2773 and waiting for their confirmation, then I will update it in here. – Sara Liu - MSFT Jul 06 '17 at 03:27

1 Answers1

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.

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27
  • 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. – Robino Jul 10 '17 at 11:51
  • This was implemented [in this commit](https://github.com/microsoft/PTVS/commit/3c67e8bd30e7afea961fe9a00b282687fc98a2cb) – Nicolas Abril Sep 13 '19 at 17:45