Type annotations describe what a function expects. With type checking enabled, Pylance can flag an incompatible argument while you edit.
Give the function the value it asks for. Changing the argument to a string makes this call match its declared parameter type.
Type diagnostics depend on python.analysis.typeCheckingMode.
02
02 / Hover information
Know what’s behind the name.
A short name can carry a lot of context. A hover can bring that context into view.
readings.py / TRACE THE TYPE
readings = [18.2, 20.5, 19.8]
average = sum(readings) / len(readings)
↳
averagefloat
Inferred from division. No annotation needed here.
Pylance infers many types from expressions. Hover over average to see the type that follows from this calculation, even without an explicit annotation.
The division expression produces a float. The editor carries that information forward wherever the value is used.
Illustrative type information, shown expanded.
03
03 / IntelliSense
Discover the next move.
A completion list is more than a way to type faster. It shows what your value can do.
message.py / AVAILABLE STRING MEMBERS
message = "hello, python"
message.
upper()→ str
lower()→ str
strip()→ str
AFTER ACCEPTING upper()
message.upper()
# "HELLO, PYTHON"
message is a string, so member suggestions include string methods. Type a dot after the variable to explore the available members.
Accept upper() to complete the expression. The resulting string is uppercase; the original message value stays the same.
Suggestions depend on the value’s type and your environment.
04
04 / Go to definition
Follow the name home.
A function call is an invitation to ask: where does this come from?
01 / THE CALLmain.py
from readings import mean
result = mean([18.2, 20.5])