Pycharm visual warning about unresolved attribute reference(Pycharm 关于未解析属性引用的视觉警告)
问题描述
我有两个如下所示的类:
I have two classes that look like this:
class BaseClass(object):
def the_dct(self):
return self.THE_DCT
class Kid(BaseClass):
THE_DCT = {'vars': 'values'}
# Code i ll be running
inst = Kid()
print(inst.the_dct)
继承必须是这样的;第二类包含 THE_DCT
和第一类包含 def the_dct
.
Inheritance has to be this way; second class containing THE_DCT
and first class containing def the_dct
.
它工作得很好,但我的问题是我在 Pycharm(未解析的属性引用)中收到关于 BaseClass
中的 THE_DCT
的警告.
It works just fine, but my problem is that i get a warning in Pycharm (unresolved attribute reference), about THE_DCT
in BaseClass
.
- 它警告我有什么原因(比如为什么我应该避免它)?
- 有什么我应该做的不同的事情吗?
推荐答案
在 BaseClass
中你引用 self.THE_DCT
,但是当 PyCharm 查看这个类时,它看到THE_DCT
不存在.
Within BaseClass
you reference self.THE_DCT
, yet when PyCharm looks at this class, it sees that THE_DCT
doesn't exist.
假设您将其视为抽象类,PyCharm 不知道这是您的意图.它所看到的只是一个访问属性的类,该属性不存在,因此会显示警告.
Assuming you are treating this as an Abstract Class, PyCharm doesn't know that that is your intention. All it sees is a class accessing an attribute, which doesn't exist, and therefore it displays the warning.
虽然你的代码运行得非常好(只要你从不实例化BaseClass
),你真的应该把它改成:
Although your code will run perfectly fine (as long as you never instantiate BaseClass
), you should really change it to:
class BaseClass(object):
THE_DCT = {}
def the_dct(self):
return self.THE_DCT
这篇关于Pycharm 关于未解析属性引用的视觉警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Pycharm 关于未解析属性引用的视觉警告


- 计算测试数量的Python单元测试 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01