Closed
Description
I'll patch the .sh script that can magically reproduce this, if i try to change too much how things are installed the error goes away. @bryanforbes is working on this.
#!/bin/sh
# Save this in the root of the sqlalchemy2-stubs project and run it
rm -rf .venv .mypy_cache repro_crash mypy_repro_crash
python -m venv .venv
source .venv/bin/activate
pip install -U -e .
pip install -e /home/classic/dev/sqlalchemy
pip install -U git+https://github.com/python/mypy
mkdir repro_crash
touch repro_crash/__init__.py
tee repro_crash/base.py << EOF > /dev/null
from sqlalchemy.orm import declarative_base
Base = declarative_base()
EOF
tee repro_crash/one.py << EOF > /dev/null
from sqlalchemy import (
Column,
Integer,
String,
)
from .base import Base
class One(Base):
__tablename__ = 'one'
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
EOF
tee mypy_repro_crash.ini << EOF > /dev/null
[mypy]
plugins = sqlalchemy.ext.mypy.plugin
incremental = True
EOF
mypy --config=mypy_repro_crash.ini --show-traceback --pdb repro_crash/one.py
tee repro_crash/one.py << EOF > /dev/null
from sqlalchemy import (
Column,
Integer,
String,
)
from .base import Base
class One(Base):
__tablename__ = 'one'
id = Column(Integer, primary_key=True)
EOF
mypy --config=mypy_repro_crash.ini --show-traceback --pdb repro_crash/one.py
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
zzzeek commentedon Mar 26, 2021
this all has to do with the classdef I'm making from DynamicClassDefContext, it does not seem to be made available on a re-run within the semantic analysis phase. other forms of declarative that dont use "Base = declarative_base()" seem to still work so at least the explicit Base approaches can be used as a workaround.
zzzeek commentedon Mar 26, 2021
@registry.mapped
should be fine as well, I would think.zzzeek commentedon Mar 27, 2021
OK the mixin thing is actually a huge problem too. This is concerning. if a mixin is in a different file, it seems when I look at it as a superclass, cls.defs.body is empty. this is bad. i notice in dropbox's plugin, all kinds of features that I have working great like inheritance, real args in the
__init__
, aren't even there, and ...this behavior makes me really worried that it can't be done.sqla-tester commentedon Mar 27, 2021
Mike Bayer has proposed a fix for this issue in the master branch:
Adjust for mypy incremental behaviors https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2680
zzzeek commentedon Mar 27, 2021
I have made a lot of progress with mixins, but in order to intercept them when they're in a file all by themselves and then to know theyre going to have mapping things on them, we need to identify them, otherwise we have to scan every attribute on every class that comes in. So I think proposing a decorator like
@sqlalchemy.orm.declarative_mixin
will be necessary.zzzeek commentedon Mar 27, 2021
also in the above gerrit, ive added a new way to get the ".info" on a class that is coming from another file, we can just access the symbol table for it by looking it up. however when we get just the syms we don't have the right hand expression to infer a type. so this might decrease what we can do for type inference.
Add declarative_mixin
Add declarative_mixin