python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.42k stars 2.82k forks source link

SQLAlchemy 1.4 Python 3.9.5 KeyError: 'Mapped' #11011

Closed farbiondriven closed 2 years ago

farbiondriven commented 3 years ago

Bug Report

Mypy crashes with latest python and sqlalchemy version. Python version 3.8.5 was working fine.


app/db/engine.py:13: 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: 0.910
Traceback (most recent call last):
  File "mypy/semanal.py", line 4872, in accept
  File "mypy/nodes.py", line 1073, in accept
  File "mypy/semanal.py", line 2023, in visit_assignment_stmt
  File "mypy/semanal.py", line 2278, in apply_dynamic_class_hook
  File "/home/fabio/remark/DeviceManagement/.venv/lib/python3.9/site-packages/sqlalchemy/ext/mypy/plugin.py", line 128, in _dynamic_class_hook
    _add_globals(ctx)
  File "/home/fabio/remark/DeviceManagement/.venv/lib/python3.9/site-packages/sqlalchemy/ext/mypy/plugin.py", line 273, in _add_globals
    util.add_global(ctx, "sqlalchemy.orm.attributes", "Mapped", "__sa_Mapped")
  File "/home/fabio/remark/DeviceManagement/.venv/lib/python3.9/site-packages/sqlalchemy/ext/mypy/util.py", line 168, in add_global
    lookup_sym: SymbolTableNode = ctx.api.modules[module].names[
KeyError: 'Mapped'
app/db/engine.py:13: : note: use --pdb to drop into pdb

To Reproduce

from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm.decl_api import declarative_base
Base = declarative_base(metadata=MetaData())

Expected Behavior

(Write what you thought would happen.)

Actual Behavior

(Write what happened.)

Your Environment

JelleZijlstra commented 3 years ago

This looks like a bug in the mypy plugin that is shipped with SQLAlchemy. Could you report a bug to SQLAlchemy instead?

AlexWaygood commented 2 years ago

Closing due to lack of response from OP and the fact that this is probably a bug in the SQLAlchemy plugin rather than mypy