Why doesn't my Python interpreter show type of data?

142 views Asked by At

screenshot of the error When I move my mouse pointer on the variable sum, why doesn't the Python interpreter show me the data type in VS Code? And also I don't know this problem is for VS Code or Python interpreter.

I uninstalled python extension and pylint and installed them again.

2

There are 2 answers

0
julaine On

It does show the data-type, look at the last line, the datatype here is Literal[35].

You were probably expecting something like int, so why doesn't it show int? Your function-definition looks like this: def sum_number(num1, num2):. There is no explicit type-annotation, so the type-checker may infer it as Any. But in this case the type-checker is smart enough to understand that your specific invocation of the function will return the integer-value 35. It does not generalize that to int since it uses the most specific type it can find.

8
JialeDu On

Without explicit annotations, pylance does not actively display the data type, for example, Defining a variable does not show int.

enter image description here

But it will determine and display the data type when it is called.

enter image description here

For your code, change it so that it displays the data type in either of the following forms

enter image description here

enter image description here