{"record":{"id":"511d9742a2ace8b4","repo":"geekcomputers/Python","slug":"the-birdargument-must-be-an-instance-of-bird","errorCode":null,"errorMessage":"The birdargument must be an instance of Bird.","messagePattern":"The birdargument must be an instance of Bird\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Flappy Bird - created with tkinter/Tubes.py","lineNumber":38,"sourceCode":"        self,\n        background,\n        bird,\n        score_function=None,\n        *screen_geometry,\n        fp=(\"tube.png\", \"tube_mourth\"),\n        animation_speed=50,\n    ):\n        # Verifica os parâmetros passados e lança um erro caso algo esteja incorreto\n        if not isinstance(background, Background):\n            raise TypeError(\n                \"The background argument must be an instance of Background.\"\n            )\n        if not len(fp) == 2:\n            raise TypeError(\n                \"The parameter fp should be a sequence containing the path of the images of the tube body and the tube mouth.\"\n            )\n        if not isinstance(bird, Bird):\n            raise TypeError(\"The birdargument must be an instance of Bird.\")\n        if not callable(score_function):\n            raise TypeError(\"The score_function argument must be a callable object.\")\n\n        Thread.__init__(self)\n\n        # Instância os parâmetros\n        self.__background = background\n        self.image_path = fp\n        self.__animation_speed = animation_speed\n        self.__score_method = score_function\n\n        # Recebe a largura e altura do background\n        self.__width = screen_geometry[0]\n        self.__height = screen_geometry[1]\n\n        # Recebe o tamanho do pássaro\n        self.__bird_w = bird.width\n        self.__bird_h = bird.height","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Flappy Bird - created with tkinter/Tubes.py#L20-L56","documentation":"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.","triggerScenarios":"Passing None, a mock, or a non-Bird object as the bird argument to Tubes; constructing Tubes before Bird exists.","commonSituations":"Initialization-order mistakes in the game bootstrap; tests passing stub birds; renaming the Bird class or importing a same-named class from another module.","solutions":["Create Bird first (with its Background) and pass that instance to Tubes","Check for shadowed imports if a Bird name resolves to a different class","In tests, patch Bird in the Tubes module or build real lightweight instances"],"exampleFix":"# before\ntubes = Tubes(bg, None, score_fn)\n# after\nbird = Bird(bg, game_over)\ntubes = Tubes(bg, bird, score_fn)","handlingStrategy":"type-guard","validationCode":"from Bird import Bird\nassert isinstance(bird, Bird)","typeGuard":"def is_bird(obj) -> bool:\n    return type(obj).__name__ == 'Bird'","tryCatchPattern":"try:\n    tubes = Tubes(bg, bird, score_fn)\nexcept TypeError as e:\n    print('bird must be a Bird instance:', e)","preventionTips":["Create Bird before Tubes","Pass real instances, not placeholders or None","Mock Bird in the Tubes module when unit testing"],"tags":["tkinter","typeerror","constructor-validation","flappy-bird"],"backgroundTag":"wrong-argument-type","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}