Python3,Pygame Sprite.Group更新方法参数不同

问题描述

浏览Eric Matthes撰写的《 Python崩溃课程》一书,我在vscode实现中收到一条警告。警告显示为“ 参数与覆盖的'update'方法pylint(arguments-differ)) 不同”

我有一个从pygame模块的Sprite类继承的类。在该类中,我使用update方法。我用书中的内容仔细检查了我的实现。我看不到我做错了。阅读pygame文档上的更新方法update(),我得出的结论是该方法需要两个输入参数,但是我不给它们任何输入。因此,警告?从文档中:

* update() 在包含的Sprite上调用update方法 update(* args,* kwargs)->无 在组中的所有Sprite上调用update()方法。 Sprite基类具有一个update方法,该方法接受任意数量的参数,并且不执行任何操作。

我的问题是:我应该担心警告吗?我的意思是,0个参数符合任意数量的参数。参见下面的Bullet类:

"""Bullet module"""
import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
    """A class to manage bullets fired from the ship"""

    def __init__(self,ai_settings,screen,ship):
        """Create bullet object at the ship's current position"""
        super().__init__()
        self.screen = screen

        # Create a bullet rect at (0,0) and then set correct position
        self.rect = pygame.Rect(0,ai_settings.bullet_width,ai_settings.bullet_height)
        self.rect.centerx = ship.rect.centerx   # Align bullet with ship x position
        self.rect.top = ship.rect.top           # Align bullet with ship nose

        # Store the bullet's position as a decimal value
        self.y = float(self.rect.y)

        self.color = ai_settings.bullet_color
        self.speed_factor = ai_settings.bullet_speed_factor

    def update(self):
        """Move bullet on top of screen"""
        # Update the decimal position of the bullet.
        self.y -= self.speed_factor
        # Update the rect position.
        self.rect.y = self.y

    def draw_bullet(self):
        """Draw the bullet on screen"""
        pygame.draw.rect(self.screen,self.color,self.rect)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)