Discuss / Python / 避开Pycharm的所有警告,就写成这样了

避开Pycharm的所有警告,就写成这样了

Topic source

风逝紫玄

#1 Created at ... [Delete] [Delete and Lock User]
 class Screen:
    def __init__(self, width, height):
        self.__width = width
        self.__height = height

    @property
    def width(self):
        return self.__width

    @width.setter
    def width(self, width):
        if not isinstance(width, float):
            raise ValueError("Variable 'width' must be float")
        self.__width = width

    @property
    def height(self):
        return self.__height

    @height.setter
    def height(self, height):
        if not isinstance(height, float):
            raise ValueError("Variable 'height' must be float")
        self.__height = height

    @property
    def resolution(self):
        return self.width * self.height


    screen = Screen(10.0, 10.0)
    # screen.width = 21.0
    # screen.height = 2.0
    print(screen.resolution)

  • 1

Reply