python-3.x - 如何抑制“类型没有预期的属性”
问题描述
所以我有这个方法可以创建一个类的实例。
def process_item(self, json_item, msg_type):
"""
Creates an item instance with the 'json_item' from the redis queue.
Then the instance is used to create and send the alarm and ping request.
At the end, the instance is deleted.
:param msg_type: Type of message (Alarm or ping)
:param json_item: The item from the redis queue in json format
:return: None
"""
item = Item(json_item) # Creates an item instance with the json data.
if msg_type == 'alarm':
self.create_alarm_request(item) # Here appears the warning
elif msg_type == 'ping':
self.create_ping_request(item) # Here appears the warning
else:
self.logger.error("Unexpected error")
del item
这是课程:
import json
class Item(object):
def __init__(self, item):
"""
Generates the object attributes from the json item in the arguments.
The key is used as attribute name and value as attribute value
:param item: Item in json format from redis queue
"""
self.__dict__ = json.loads(item)
所以代码工作得很好,但是 PyCharm 给了我这个警告:
类型“项目”没有预期的属性
我能做些什么来解决/抑制这个警告?
解决方案
推荐阅读
- php - 为什么 Laravel 5.6 应用程序中的最新方法不起作用?
- java - 关于 Sedgewick 和 Wayne 的算法中的 numerOfSelfLoops(Graph G) p.523,
- javascript - 如何将输入标签设置为启用?
- python-3.x - 这种硬币找零算法是如何工作的?
- abap - ATC 检查 - prio 3 消息 - “字符串中缺少文本元素”
- java - 两个如何比较两个数据库表之间的数据以报告java中的完全匹配和不匹配的记录
- python - 从列表构建的正则表达式行为异常
- c# - ASP.NET Core 2 Web 应用程序对 .NET 标准库的参考
- python - trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff]
- html - 无法更改标题的背景颜色