Support type checking when using type hints
See original GitHub issueEnvironment data
- VS Code version: 1.25.1
- Extension version: 2018.7.1
- OS and version: Kubuntu 18.04
- Python version: Python 3.7.0b3 64-bit
- Type of virtual environment used: N/A
- Relevant/affected Python packages and their versions: N/A
Actual behavior
- No error shown when using type hints and wrong parameters are passed to a function
- Code hint pop-up shows incorrect types. The type of the “wrong” parameter gets added to the type list. In the screenshot below, see how
b
is shown to have a type ofint, str
.
Expected behavior
Squiggly lines will be shown and errors will be reported when parameters of wrong types are passed
Steps to reproduce:
- Enable the new language server (i.e. set
"python.jediEnabled": false
) - Write a simple function that uses type hints (like the one in the screenshot)
- Call the function while passing parameters of invalid types
Logs
Starting Microsoft Python language server.
[Info - 21:57:00] Created Microsoft.PythonTools.Interpreter.Ast.AstPythonInterpreter instance from Microsoft.PythonTools.Interpreter.Ast.AstPythonInterpreterFactory
Initializing for /usr/bin/python3.7
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
[Info - 21:58:02] Found 198 completions for file:///home/<username>/Desktop/server.py at (6, 2) after filtering
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top Results From Across the Web
typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar...
Read more >Python Type Checking (Guide) - Real Python
In this guide, you'll look at Python type checking. ... In bigger projects, type hints help you understand how types flow through your...
Read more >Type hinting in PyCharm - JetBrains
PyCharm supports type hinting in function annotations and type comments using the typing module and the format defined by PEP 484.
Read more >Type hints cheat sheet - mypy 0.991 documentation
For most types, just use the name of the type x: int = 1 x: float = 1.0 x: bool = True x:...
Read more >Python Type Checking - TestDriven.io
Type hints enable static type checking tools. Code editors and IDEs use them as well, warning you when usage of a particular function...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As someone learning Python, and a longtime VS Code user, I found the lack of support for this to be very surprising.
Okay, I understand. I thought since VS Code shows type errors for TypeScript code, the same will be true for code written in Python as well.