Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm - Type hints are not installed

I keep getting this warning in PyCharm 2018.3.5: "Type hints are not installed".

enter image description here

If I click 'Install', a log message like this appears:

6:11 PM Packages installed successfully: Installed packages: 'djangorestframework-stubs'

But then the warning reappears in a few minues. How to fix it? If it matters, I have a remote Docker Compose interpreter configured for the project, which is otherwise working fine.

like image 662
Eugene Yarmash Avatar asked Mar 13 '19 15:03

Eugene Yarmash


People also ask

How do I turn on hints in Pycharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Color Scheme | Language Defaults, then select Inline hints.

How do you add a hint in Python?

Here's how you can add type hints to our function: Add a colon and a data type after each function parameter. Add an arrow ( -> ) and a data type after the function to specify the return data type.

Should you add type hints in Python?

Type hints help you build and maintain a cleaner architecture. The act of writing type hints forces you to think about the types in your program. While the dynamic nature of Python is one of its great assets, being conscious about relying on duck typing, overloaded methods, or multiple return types is a good thing.

Does Python check type hints?

With Python 3.5, type hints officially became part of the language (PEP 484). Using a linter or code-checking tool, developers can check the consistency of variables and their types across a code base, and perform static analyses of code that would previously have been difficult or impossible.


1 Answers

I created a ticket in PyCharm's bug tracker about this problem: https://youtrack.jetbrains.com/issue/PY-34624

What basically happens:

  1. PyCharm finds djangorestframework installed and proposes to install a stub package for it as djangorestframework-stubs is missing
  2. You click Install
  3. PyCharm starts the container and installs djangorestframework-stubs there
  4. PyCharm stops the container
  5. Now djangorestframework-stubs is gone
  6. Repeat from 1.
like image 66
Pavel Karateev Avatar answered Nov 03 '22 01:11

Pavel Karateev