mypy icon indicating copy to clipboard operation
mypy copied to clipboard

python3 runtests.py fails if python version == 3.11

Open aless10 opened this issue 2 years ago • 3 comments

Bug Report

Following the contributor guide I run the command python3 runtests.py and I got an error, based on the python version that I use in my virtualenv vs the one listed in the ini file (3.7).

To Reproduce

python3 runtests.py

Expected Behavior

No errors

Actual Behavior

run self: ['/Users/alessioizzo/alessio/mypy/venv/bin/python3', '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy']
mypy/config_parser.py:16: error: Cannot find implementation or library stub for module named "tomli"  [import]
        import tomli as tomllib
    ^
mypy/config_parser.py:16: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
mypy/modulefinder.py:22: error: Cannot find implementation or library stub for module named "tomli"  [import]
        import tomli as tomllib
    ^
Found 2 errors in 2 files (checked 169 source files)

FAILED: self

Your Environment

  • Mypy version used: latest from git clone
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files): mypy_self_check.ini
  • Python version used: 3.11
  • OS: macos Apple M1 Pro, Ventura 13.1

I guess that the solution can be to remove the python version from the ini file. I'm going to open a pull request for this one if this happens to be a bug.

aless10 avatar Jan 21 '23 11:01 aless10

I add that, removing the python version from the mypy_self_check.ini file, I got these errors

run self: ['/Users/alessioizzo/alessio/mypy/venv/bin/python3', '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy']
mypy/fastparse.py:844: error: Unused "type: ignore" comment
                parsed = parse_type_ignore_tag(ti.tag)  # type: ignore[attr-defined]
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/fastparse.py:1569: error: Left operand of "or" is always false  [redundant-expr]
            conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion)
                             ^~~~~~~~~~~~~~~~~~~~
mypy/fastparse.py:2013: error: Unused "type: ignore" comment
                            s.col_offset = s.value.col_offset  # type: ignore[attr-defined]
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/fastparse.py:2016: error: Unused "type: ignore" comment
                            s.col_offset = s.lower.col_offset  # type: ignore[attr-defined]
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 4 errors in 1 file (checked 169 source files)

FAILED: self

aless10 avatar Jan 21 '23 11:01 aless10

I've seen this as well. As a workaround, you can run pip install tomli.

We want to always type check in 3.7 mode to make sure we don't use any features from more recent Python versions.

The fix would be to install tomli in test-requirements.txt, I guess.

@aless10 Would you like to contribute a fix? It should be easy.

JukkaL avatar Jan 21 '23 14:01 JukkaL

Ok, but while running the runtests.py command, I got this error

run self: ['/Users/alessioizzo/alessio/mypy/venv/bin/python3', '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy']
mypy/fastparse.py:844: error: "TypeIgnore" has no attribute "tag"  [attr-defined]
                parsed = parse_type_ignore_tag(ti.tag)
                                               ^~~~~~
mypy/fastparse.py:1569: error: Unused "type: ignore" comment
            conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion)  # type: ignore[redundant-expr]
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/fastparse.py:2013: error: "Index" has no attribute "col_offset"  [attr-defined]
                            s.col_offset = s.value.col_offset
                            ^~~~~~~~~~~~
mypy/fastparse.py:2016: error: "Slice" has no attribute "col_offset"  [attr-defined]
                            s.col_offset = s.lower.col_offset
                            ^~~~~~~~~~~~
Found 4 errors in 1 file (checked 169 source files)

FAILED: self

I'd like also to fix this and update the README in order to explicit the fact that we want to use the 3.7 version. Is that ok? Thanks

aless10 avatar Jan 21 '23 14:01 aless10