skip to Main Content

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

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search