为什么Pycharm不知道要传递给继承的Python数据类'\uu init\的参数?

2024-06-16 12:28:23 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么Pycharm不知道在dataclasses的情况下传递给子类的init哪些参数

关于这个问题的评论之后的附加信息:我正在使用Pycharm2018.3.4 Communityedition with Python 3.7.3

我用Python编写了以下代码:

from dataclasses import dataclass


@dataclass
class A():
    r: int
    s: int

@dataclass
class B(A):
    t: int

    @staticmethod
    def agg(r: int, s: int, t: int):
        record: B = B(r,s,t)
        return record

b: B = B.agg(1,22,333)
print(b)

从而产生以下输出:

B(r=1, s=22, t=333)

然而,当涉及数据类时,Pycharm无法理解哪些参数应该传递给B的init。 当您编写自己的init方法时,Pycharm工作得很好。你知道吗

我做错什么了? 如何让Pycharm显示正确的帮助?


Pycharm显示要提供给初始化的参数列表

Pycharm shows the list of parameters to provide to __init__


Pycharm不显示要提供给初始化的参数列表

Pycharm doesn't show the list of parameters to provide to __init__


Tags: 信息列表参数init评论情况record子类