Skip to content
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

pyinfo.py not compatible with Python 2 #12202

Closed
itoijala-huld opened this issue Feb 17, 2022 · 3 comments · Fixed by #12244
Closed

pyinfo.py not compatible with Python 2 #12202

itoijala-huld opened this issue Feb 17, 2022 · 3 comments · Fixed by #12244
Labels
bug mypy got something wrong good-first-issue

Comments

@itoijala-huld
Copy link

Bug Report

https://github.com/python/mypy/blob/master/mypy/pyinfo.py#L22
uses sys.base_prefix, but this does not exist in Python 2.

The code should check whether base_prefix exists, and if not return a copy of prefix instead.

To Reproduce

Use the options --py2 and --python-executable.
Mypy will try to execute pyinfo.py using the given interpreter, which will fail.

Actual Behavior

Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/conda/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/conda/lib/python3.9/site-packages/mypy/__main__.py", line 34, in <module>
    console_entry()
  File "/opt/conda/lib/python3.9/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 96, in main
    svf.nsvf.init_handler,
  File "mypy/main.py", line 173, in run_build
  File "mypy/build.py", line 180, in build
  File "mypy/build.py", line 212, in _build
  File "mypy/modulefinder.py", line 782, in compute_search_paths
  File "mypy/modulefinder.py", line 624, in get_prefixes
    import getopt
  File "/opt/conda/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/opt/conda/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['.../python2', '/opt/conda/lib/python3.9/site-packages/mypy/pyinfo.py', 'getprefixes']' returned non-zero exit status 1.

Running the command manually gives

Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/mypy/pyinfo.py", line 43, in <module>
    print(repr(getprefixes()))
  File "/opt/conda/lib/python3.9/site-packages/mypy/pyinfo.py", line 22, in getprefixes
    return sys.base_prefix, sys.prefix
AttributeError: 'module' object has no attribute 'base_prefix'

Your Environment

  • Mypy version used: 0.931
  • Python version used: 2.7.5, 2.7.17
@itoijala-huld itoijala-huld added the bug mypy got something wrong label Feb 17, 2022
@hauntsaninja
Copy link
Collaborator

Thanks for the report, want to make a PR?

@sobolevn
Copy link
Member

This stas says that less that 0.04% of downloads are for python2: https://pypistats.org/packages/mypy

Снимок экрана 2022-02-23 в 5 17 44

However, I am not sure how accurate this number is.

@JelleZijlstra
Copy link
Member

That's not very informative because mypy does not run on Python 2 (and I believe it never has). It still supports type checking Python 2, but to do that you need to download it using 3.6+ first.

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

Successfully merging a pull request may close this issue.

4 participants