Skip to content

mypy --install-types segfaults #10596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aphedges opened this issue Jun 8, 2021 · 4 comments · Fixed by #10599
Closed

mypy --install-types segfaults #10596

aphedges opened this issue Jun 8, 2021 · 4 comments · Fixed by #10599
Labels
bug mypy got something wrong crash priority-0-high

Comments

@aphedges
Copy link

aphedges commented Jun 8, 2021

Bug Report

When running mypy --install-types, mypy segfaults instead of completing successfully.

To Reproduce

  1. Install the following requirements with pip:
mypy==0.900
mypy-extensions==0.4.3
pip==21.1.2
PyYAML==5.4.1
setuptools==57.0.0
toml==0.10.2
typed-ast==1.4.3
typing-extensions==3.10.0.0
  1. Put the following code in test.py:
import yaml
  1. Run mypy test.py, which will display the following output:
test.py:1: error: Library stubs not installed for "yaml" (or incompatible with Python 3.7)
test.py:1: note: Hint: "python3 -m pip install types-PyYAML"
test.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
  1. Run mypy --install-types

Actual Behavior

mypy outputs the following:

Installing missing stub packages:
Segmentation fault: 11

When running python -X dev -m mypy --install-types, I get the following, more verbose output:

Installing missing stub packages:
Fatal Python error: Segmentation fault

Current thread 0x000000010e30cdc0 (most recent call first):
  File "/Users/ahedges/.pyenv/versions/mypy2/lib/python3.7/site-packages/mypy/__main__.py", line 11 in console_entry
  File "/Users/ahedges/.pyenv/versions/mypy2/lib/python3.7/site-packages/mypy/__main__.py", line 23 in <module>
  File "/Users/ahedges/.pyenv/versions/3.7.10/lib/python3.7/runpy.py", line 85 in _run_code
  File "/Users/ahedges/.pyenv/versions/3.7.10/lib/python3.7/runpy.py", line 193 in _run_module_as_main
Segmentation fault: 11

Your Environment

  • Mypy version used: 0.900
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.7.10
  • Operating system and version: macOS 10.15.7 (19H1030)
@JukkaL
Copy link
Collaborator

JukkaL commented Jun 8, 2021

This seem to be a problem with the binary wheels. As a workaround, you can uninstall mypy and reinstall without the binaries:

python3 -m pip install --no-binary :all: mypy

EDIT: See comment below for a better way to do it (replace :all: with mypy).

However, this results in much worse performance. We'll need a 0.901 hotfix release.

@emmatyping
Copy link
Member

Note that most people probably want --no-binary=mypy because they do want typed_ast, lxml, and others to use pre-compiled binaries. So I'd recommend

python3 -m pip install --no-binary=mypy mypy

JukkaL added a commit that referenced this issue Jun 8, 2021
This could result in a crash if the second evaluation results
in a shorter list, such as in this example (besides being incorrect
overall):

```
a = [s for s in f.readlines()]
```

`f.readlines()` was called twice, resulting in an empty list on
the second call. This caused the list object constructed in the
comprehension to have a NULL item, which is invalid.

This fixes `mypy --install-types` in compiled mode.

Fixes #10596.
@JukkaL
Copy link
Collaborator

JukkaL commented Jun 8, 2021

I just released mypy 0.901 that includes a fix to this issue.

@aphedges
Copy link
Author

aphedges commented Jun 8, 2021

@JukkaL, I can confirm this solves my problem. Thank you so much for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong crash priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants