VS 代码显示“继承'Base',它不是一个类” 给出以下错误消息:
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))
为什么会这样?我该如何解决?
最佳答案
继承'Base',它不是一个类
实际上并不是一个错误。
相反,它是来自 Microsoft 的 Python 语言服务器的静态分析结果(这又严重依赖于 pylint
)用于此类分析。它并不总是准确的:如果一个类是由函数动态生成和返回的(就像这里的情况),静态检查工具可能无法正确理解它的类型。
如 microsoft/python-language-server#1390
中所述,可以通过以下设置更改禁用此功能:
"python.analysis.disabled": [
"inherit-non-class"
],
关于python - "Inheriting ' 使用 SQLAlchemy declarative_base() 在 VS 代码中的基础 ', which is not a class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57211894/