mypy icon indicating copy to clipboard operation
mypy copied to clipboard

IndexError: list index out of range

Open joshvoigts opened this issue 8 months ago • 6 comments

Crash Report

Mypy crashes when run on a python repo with mypy .

Traceback

error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.7.1
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5727, in accept
  File "mypy/nodes.py", line 2211, in accept
  File "mypy/checkexpr.py", line 5202, in visit_lambda_expr
  File "mypy/nodes.py", line 2204, in expr
IndexError: list index out of range

To Reproduce

Run mypy . on our private repo. It seems to fail on a particular python file giving -1 as the line number.

Your Environment

  • Mypy version used: 1.4.1 and 1.7.1 both seem to crash.
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
disallow_incomplete_defs = true

no_incremental = true

plugins = "sqlalchemy.ext.mypy.plugin"

warn_redundant_casts = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "flask_sqlalchemy"
ignore_missing_imports = true
  • Python version used: 3.9.11
  • Operating system and version: macos 14.2

joshvoigts avatar Dec 18 '23 17:12 joshvoigts

Any chance you can make a shareable repro? E.g. try removing stuff from the file until you get something small enough to redact that mypy still crashes on. Also worth checking if the crash reproduces without the sqlalchemy plugin.

hauntsaninja avatar Dec 25 '23 07:12 hauntsaninja

I spent a couple hours trying to reproduce this but was struggling. I think it does have something to do with the sqlalchemy plugin. If I remove @declared_mixin from any of the classes I'm mixing in it no longer seems to error. If I include the library that has the mixin in it directly in the project it also no longer seems to error which makes it tough to create a minimal example. I don't think I can spend too much more time on this, so feel free to close if it's not actionable.

joshvoigts avatar Dec 25 '23 16:12 joshvoigts

What if you keep @declared_mixin, but remove plugins = "sqlalchemy.ext.mypy.plugin" from your mypy configuration?

hauntsaninja avatar Dec 26 '23 04:12 hauntsaninja

Adding another config example, as we're running into this too while trying to upgrade to 3.11. We're trying 1.8 and also 1.7 to see if it works, but no dice.

/Users/me/Library/Caches/pypoetry/virtualenvs/backend-ZZ6YV39x-py3.11/lib/python3.11/site-packages/fastapi_users_db_sqlalchemy/__init__.py:-1: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.8.0
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5727, in accept
  File "mypy/nodes.py", line 2213, in accept
  File "mypy/checkexpr.py", line 5202, in visit_lambda_expr
  File "mypy/nodes.py", line 2206, in expr
IndexError: list index out of range
[mypy]
# We cannot use the pydantic.mypy plugin yet as it is not compatible with mypy 0.910
plugins = loguru_mypy, sqlalchemy.ext.mypy.plugin
exclude = alembic/versions/
follow_imports = normal
check_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_defs = True
namespace_packages = True
warn_unused_ignores = True
show_error_codes = True
local_partial_types = True

tyre avatar Jan 31 '24 18:01 tyre

It seems like this might be specific to sqlalchemy.ext.mypy.plugin, in which case you might be better off reporting to that project. They're probably also going to ask for a repro though

hauntsaninja avatar Jan 31 '24 21:01 hauntsaninja

this might be already filed with sqlalchemy here https://github.com/sqlalchemy/sqlalchemy/issues/10282

Hnasar avatar Feb 05 '24 21:02 Hnasar