Skip to content Skip to sidebar Skip to footer

"inheriting 'base', Which Is Not A Class" In Vs Code Using Sqlalchemy Declarative_base()

VS Code shows 'Inheriting 'Base', which is not a class' as an error message given the below: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Integer

Solution 1:

Inheriting 'Base', which is not a class is not actually an error.

Rather, it's a static analysis result coming from Microsoft's Python language server (which in turn leans heavily on pylint) for this kind of analysis. It's not always accurate: If a class is dynamically generated and returned by a function (as is the case here), the static-checking tools may not properly understand its type.

As described in microsoft/python-language-server#1390, this feature can be disabled with the following settings change:

"python.analysis.disabled":["inherit-non-class"],

Solution 2:

As of VS Code 1.47, when using Marshmallow to serialize/deserialize SQLAlchemy objects and inheriting from marshmallow_sqlalchemy.SQLAlchemyAutoSchema, using the solution from the other answer:

"python.analysis.disabled":["inherit-non-class"],

does not seem to work anymore (i.e. you will still get a "ma.SQLAlchemyAutoSchema', which is not a class." warning). You can instead use the more generic #noqa comment on specific lines:

ma = Marshmallow(app)

classUserSchema(ma.SQLAlchemyAutoSchema):  # noqaclass Meta:
        model = Person
        sqla_session = db.session

Note though, that VS Code treats #noqa as a disable-all setting for that line.

Post a Comment for ""inheriting 'base', Which Is Not A Class" In Vs Code Using Sqlalchemy Declarative_base()"