python - "Inheriting ' 使用 SQLAlchemy declarative_base() 在 VS 代码中的基础 ', which is not a class"

标签 python python-3.x visual-studio-code sqlalchemy

VS code screenshot

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/

相关文章:

python-3.x - 为什么无法使用纯Python下载字幕?

python-3.x - 如何声明返回对象数组的函数?

python - 在 zlib 中编码并插入到 mysql

python - 如何在 Scapy 中抑制 "Sent $X packet"输出?

python-3.x - 尝试在 python 中下载多个文件并报告是否成功

javascript - 如何启用 VS Code HTML 错误检查/验证?

java - 如何向 VSCode Java 调试器提供启动选项参数

python - 如何禁用 Flask 中的线程?

python - 根据另一列中的值获取一列中的子字符串

javascript - 如何将异步命令发送到 VSCode 编辑器的扩展