question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support type checking when using type hints

See original GitHub issue

Environment 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

  1. No error shown when using type hints and wrong parameters are passed to a function
  2. 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 of int, str.

screenshot_20180725_215026

Expected behavior

Squiggly lines will be shown and errors will be reported when parameters of wrong types are passed

Steps to reproduce:

  1. Enable the new language server (i.e. set "python.jediEnabled": false)
  2. Write a simple function that uses type hints (like the one in the screenshot)
  3. 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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
johnhargrovecommented, Sep 16, 2018

As someone learning Python, and a longtime VS Code user, I found the lack of support for this to be very surprising.

1reaction
tuhinkarmakarcommented, Sep 8, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found