Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Inheriting 'Base', which is not a class" in VS Code using SQLAlchemy declarative_base()

VS code screenshot

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 , String , Column

Base = declarative_base()

class Socio(Base):

    __tablename__ = 'socios'
    id = Column(Integer, autoincrement = True , primary_key = True)
    dni = Column(Integer , unique = True)
    nombre = Column(String(250))
    apellido= Column(String(250))

Why does this happen? How can I fix it?

like image 876
Gaston Palavecino Avatar asked Mar 07 '26 16:03

Gaston Palavecino


1 Answers

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"
],
like image 133
Charles Duffy Avatar answered Mar 09 '26 05:03

Charles Duffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!