"Inheriting 'Base', Which Is Not A Class" In VS Code Using SQLAlchemy Declarative_base()
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)
class UserSchema(ma.SQLAlchemyAutoSchema): # noqa
class 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()"