Skip to content

mypy plugin fails in incremental mode #6147

Closed
@zzzeek

Description

@zzzeek
Member

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


Activity

added
bugSomething isn't working
SQLA mypy pluginmypy plugin issues only. general pep-484 issues should be "typing"
on Mar 26, 2021
added this to the 1.4.x milestone on Mar 26, 2021
zzzeek

zzzeek commented on Mar 26, 2021

@zzzeek
MemberAuthor

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

zzzeek commented on Mar 26, 2021

@zzzeek
MemberAuthor

@registry.mapped should be fine as well, I would think.

zzzeek

zzzeek commented on Mar 27, 2021

@zzzeek
MemberAuthor

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

sqla-tester commented on Mar 27, 2021

@sqla-tester
Collaborator

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

zzzeek commented on Mar 27, 2021

@zzzeek
MemberAuthor

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

zzzeek commented on Mar 27, 2021

@zzzeek
MemberAuthor

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.

added a commit that references this issue on Apr 3, 2021
added a commit that references this issue on Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SQLA mypy pluginmypy plugin issues only. general pep-484 issues should be "typing"bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@sqla-tester

        Issue actions

          mypy plugin fails in incremental mode · Issue #6147 · sqlalchemy/sqlalchemy