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.

mypy with `--install-types` as an arg fails to install types because process is interactive

See original GitHub issue

I know this is not a problem with pre-commit per se. But as of mypy==0.902 warnings that stubs were not installed stared popping up while running pre-commit (see example)

dbt_sugar/core/ui/cli_ui.py:6: error: Library stubs not installed for "click" (or incompatible with Python 3.7)
dbt_sugar/core/ui/cli_ui.py:6: note: Hint: "python3 -m pip install types-click"
dbt_sugar/core/ui/cli_ui.py:8: error: Library stubs not installed for "yaml" (or incompatible with Python 3.7)
dbt_sugar/core/clients/yaml_helpers.py:7: error: Library stubs not installed for "yaml" (or incompatible with Python 3.7)
dbt_sugar/core/clients/yaml_helpers.py:7: note: Hint: "python3 -m pip install types-PyYAML"
dbt_sugar/core/clients/yaml_helpers.py:7: note: (or run "mypy --install-types" to install all missing stub packages)
dbt_sugar/core/clients/yaml_helpers.py:7: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

I was thinking that passing the --install-types as one of the arguments on my pre-commit config would do the trick but I get a failure which I think is due to the fact that --install-types requires a yes/no user input (as discussed here: https://github.com/python/mypy/issues/10600#issuecomment-857351152). Here’s the error message:

Installing missing stub packages:
/Users/bastienboutonnet/.cache/pre-commit/repochpm25o9/py_env-python3.8/bin/python -m pip install types-PyYAML types-click

Install? [yN] Traceback (most recent call last):
  File "/Users/bastienboutonnet/.cache/pre-commit/repochpm25o9/py_env-python3.8/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/bastienboutonnet/.cache/pre-commit/repochpm25o9/py_env-python3.8/lib/python3.8/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 133, in main
  File "mypy/main.py", line 1093, in install_types
EOFError: EOF when reading a line

(also happens when running pre-commit.ci on my public repo (https://github.com/bitpicky/dbt-sugar/pull/290)

Looks like there is a new flag which will be shipped as part of 910 but I was wondering if in the meantime there was a way to run pre-commit with install-types in a way to fake the yes answer? a bit like the comment above does with pipes.

If not I’ll turn off that check from mypy until they fix it but I thought maybe there’s a way?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
asottilecommented, Jun 24, 2021

the problem is types-all is a hack / workaround and would further differ from vanilla mypy

0reactions
asottilecommented, Nov 26, 2022

they’re all public, feel free to answer your own question

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to tackle pipeline slow down due to `mypy --install-types`
Currently I have to use the command mypy --install-types --non-interactive my_folder --config-file=mypy.ini .
Read more >
The mypy command line - mypy 0.991 documentation
If an expression of type Any appears anywhere in the module mypy will output an error unless the expression is immediately used as...
Read more >
Mypy Documentation - Read the Docs
Mypy is a static type checker for Python. Type checkers help ensure that you're using variables and functions in your code correctly.
Read more >
Mypy 0.981 Released - The Mypy Blog
Code like this will now generate an error, since the value of T cannot ... an explicit optional type (e.g. str | None)...
Read more >
Exhaustiveness Checking with Mypy | Haki Benita
Fail at compile time, not at run time. Mypy is an optional static type checker for Python. It's been around since 2012 and...
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