如何抑制“类型没有预期的属性”

问题描述 投票:0回答:1

所以我有这个方法来创建类的实例。

    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 给了我这个警告:

类型“Item”没有预期的属性


我可以做什么来解决/抑制此警告?
python-3.x pycharm
1个回答
0
投票
# noinspection PyTypeChecker

将其放在 PyCharm 标记的代码行上方。我知道它晚了 3.5 年以上,但其他人可能会发现它有用。

© www.soinside.com 2019 - 2024. All rights reserved.