Ensure stubs packages are not installed
Verify if the api is typed
Describe the typing issue
When mypy is configured to follow import but suppress error messages (eg: with --follow-imports=silent), any @declared_attr in a module imported will crash mypy >= 1.4.0.
To Reproduce
# example.py
from sqlalchemy import Column, String
from sqlalchemy.orm import Mapped, declared_attr, declarative_mixin
@declarative_mixin
class Foo:
@declared_attr
def bar(cls) -> Mapped[str]:
return Column(String)
# example2.py
from example import Foo
Error
example.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.5.1
Traceback (most recent call last):
File "mypy/checkexpr.py", line 5141, in accept
File "mypy/nodes.py", line 2207, in accept
File "mypy/checkexpr.py", line 4633, in visit_lambda_expr
File "mypy/nodes.py", line 2200, in expr
IndexError: list index out of range
example.py:-1: : note: use --pdb to drop into pdb
Versions
- OS: linux
- Python: 3.11.3
- SQLAlchemy: 2.0.20 & 1.4.49
- Type checker: mypy >= 1.4.0 (for some reason, it works with mypy 1.3.1)
Additional context
The error happens in mypy at this line. This is because the Block passed when creating the LambdaExpr here is empty.
Ensure stubs packages are not installed
sqlalchemy-stubsandsqlalchemy2-stubsare not compatible with v2)Verify if the api is typed
Describe the typing issue
When mypy is configured to follow import but suppress error messages (eg: with
--follow-imports=silent), any@declared_attrin a module imported will crash mypy >= 1.4.0.To Reproduce
Error
Versions
Additional context
The error happens in mypy at this line. This is because the
Blockpassed when creating theLambdaExprhere is empty.