geekcomputers/Python · error · TypeError

The birdargument must be an instance of Bird.

Error message

The birdargument must be an instance of Bird.

What it means

Tubes' constructor validates that bird is an instance of Bird (note the typo 'birdargument' in the message). Tubes needs the Bird to detect collisions and position pipes relative to it, so a wrong type fails fast.

Source

Thrown at Flappy Bird - created with tkinter/Tubes.py:38

        self,
        background,
        bird,
        score_function=None,
        *screen_geometry,
        fp=("tube.png", "tube_mourth"),
        animation_speed=50,
    ):
        # Verifica os parâmetros passados e lança um erro caso algo esteja incorreto
        if not isinstance(background, Background):
            raise TypeError(
                "The background argument must be an instance of Background."
            )
        if not len(fp) == 2:
            raise TypeError(
                "The parameter fp should be a sequence containing the path of the images of the tube body and the tube mouth."
            )
        if not isinstance(bird, Bird):
            raise TypeError("The birdargument must be an instance of Bird.")
        if not callable(score_function):
            raise TypeError("The score_function argument must be a callable object.")

        Thread.__init__(self)

        # Instância os parâmetros
        self.__background = background
        self.image_path = fp
        self.__animation_speed = animation_speed
        self.__score_method = score_function

        # Recebe a largura e altura do background
        self.__width = screen_geometry[0]
        self.__height = screen_geometry[1]

        # Recebe o tamanho do pássaro
        self.__bird_w = bird.width
        self.__bird_h = bird.height

View on GitHub (pinned to 40f4cd2652)

Solutions

  1. Create Bird first (with its Background) and pass that instance to Tubes
  2. Check for shadowed imports if a Bird name resolves to a different class
  3. In tests, patch Bird in the Tubes module or build real lightweight instances

Example fix

# before
tubes = Tubes(bg, None, score_fn)
# after
bird = Bird(bg, game_over)
tubes = Tubes(bg, bird, score_fn)
Defensive patterns

Strategy: type-guard

Validate before calling

from Bird import Bird
assert isinstance(bird, Bird)

Type guard

def is_bird(obj) -> bool:
    return type(obj).__name__ == 'Bird'

Try / catch

try:
    tubes = Tubes(bg, bird, score_fn)
except TypeError as e:
    print('bird must be a Bird instance:', e)

Prevention

When it happens

Trigger: Passing None, a mock, or a non-Bird object as the bird argument to Tubes; constructing Tubes before Bird exists.

Common situations: Initialization-order mistakes in the game bootstrap; tests passing stub birds; renaming the Bird class or importing a same-named class from another module.

Related errors


AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27). Data as JSON: /api/errors/511d9742a2ace8b4. Report an issue: GitHub.