3

问问大家一个关于类变量初始化引发的关于 IDE 错误提示的问题

 2 years ago
source link: https://www.v2ex.com/t/812436
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

问问大家一个关于类变量初始化引发的关于 IDE 错误提示的问题

  zhoudaiyu · 17 小时 16 分钟前 · 200 次点击
代码如下: 其实错误就是在变量初始化前就引用了变量。我的问题是:这种错误,IDE ( Pycharm )为啥不能提示出来呢?(没有甩锅的意思,就是从技术角度比较好奇)
1 条回复    2021-11-02 14:01:10 +08:00

Vegetable

Vegetable   17 小时 2 分钟前

如果你加上如下代码呢?

def __new__(cls, *args, **kwargs):
init = super().__new__(cls)
init._val_d = "default_val_d"
return init

这玩意想静态分析着实有点难

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK