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.
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.
2
Answers
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 asAny
. But in this case the type-checker is smart enough to understand that your specific invocation of the function will return the integer-value35
. It does not generalize that toint
since it uses the most specific type it can find.Without explicit annotations, pylance does not actively display the data type, for example, Defining a variable does not show
int
.But it will determine and display the data type when it is called.
For your code, change it so that it displays the data type in either of the following forms