1

Going through the book "Python Crash Course" by Eric Matthes, I receive a warning in my vscode implementation. The warning says "Parameters differ from overridden 'update' method pylint(arguments-differ))"

I have a class that inherits from the Sprite class from pygame module. In that class, I use the update method. I double checked my implementation with what's written in the book. I cannot see that I made a mistake. Reading up the update method update() on the pygame documentation, I came to the conclusion that the method expects two input arguments, but I kind of give none to them. Hence the warning? From the documentation:

*update() call the update method on contained Sprites update(*args, *kwargs) -> None Calls the update() method on all Sprites in the Group. The base Sprite class has an update method that takes any number of arguments and does nothing.

My question is: Should I be worried about the warning? I mean, 0 arguments comply with the statement any number of arguments. See below class 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, 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)
Alex
  • 57
  • 5
  • 4
    The warning won't affect the code execution. You can probably change your method signature to `def update(self, *args, **kwargs)` to remove the warning. – Mike67 Nov 08 '20 at 19:37
  • @Alex -I ran the code you provided and it did not show any warning messages. So it is recommended that you use the latest version of VScode and Python extensions and try to reload VSCode. – Jill Cheng Nov 09 '20 at 08:35
  • @JillCheng I'm using vscode 1.51.1 and checked my extensions for updates. vscode says that all extensions are up-to-date. – Alex Nov 14 '20 at 10:35
  • @JillCheng One more thing. I am using pylint. Are you using it as well? Thank you, – Alex Nov 14 '20 at 12:58
  • @Alex -Yes, I installed and used pylint, and it is recommended that you try different language services. ["python.languageServer"]. – Jill Cheng Nov 16 '20 at 02:07

0 Answers0