{"record":{"id":"4c9f1a5671b195fb","repo":"geekcomputers/Python","slug":"the-gameover-method-argument-must-be-a-callable-ob","errorCode":null,"errorMessage":"The gameover_method argument must be a callable object.","messagePattern":"The gameover_method argument must be a callable object\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Flappy Bird - created with tkinter/Bird.py","lineNumber":39,"sourceCode":"    climbsUp = 0.0911458333\n\n    def __init__(\n        self,\n        background,\n        gameover_function,\n        *screen_geometry,\n        fp=\"bird.png\",\n        event=\"<Up>\",\n        descend_speed=5,\n    ):\n        # Verifica se \"background\" é uma instância de Background e se o \"gamerover_method\" é chamável\n\n        if not isinstance(background, Background):\n            raise TypeError(\n                \"The background argument must be an instance of Background.\"\n            )\n        if not callable(gameover_function):\n            raise TypeError(\"The gameover_method argument must be a callable object.\")\n\n        # Instância os parâmetros\n        self.__canvas = background\n        self.image_path = fp\n        self.__descend_speed = descend_speed\n        self.gameover_method = gameover_function\n\n        # Recebe a largura e altura do background\n        self.__width = screen_geometry[0]\n        self.__height = screen_geometry[1]\n\n        # Define a decida e subida do pássaro com base na altura do background\n        self.decends *= self.__height\n        self.decends = int(self.decends + 0.5)\n        self.climbsUp *= self.__height\n        self.climbsUp = int(self.climbsUp + 0.5)\n\n        # Invoca o método construtor de Thread","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Flappy Bird - created with tkinter/Bird.py#L21-L57","documentation":"Bird's constructor also validates that gameover_function is callable, since Bird must invoke it when the bird collides or falls. Passing a non-callable (e.g. a method result instead of the method, or None) raises this TypeError.","triggerScenarios":"Passing game_over() (called, returns None) instead of game_over; passing a string name of the method, None, or an object without __call__.","commonSituations":"Accidentally calling the callback at construction site; renaming the game-over method but passing the old attribute; defaulting the parameter to None in a refactor.","solutions":["Pass the function/method itself without parentheses: Bird(bg, self.game_over)","If it's a bound method of another object, pass obj.method_name, not obj.method_name()","If the callback may be absent, pass a no-op lambda: lambda: None"],"exampleFix":"# before\nbird = Bird(bg, self.game_over())\n# after\nbird = Bird(bg, self.game_over)","handlingStrategy":"type-guard","validationCode":"if not callable(gameover_function):\n    gameover_function = lambda: None","typeGuard":"def is_callable(fn) -> bool:\n    return callable(fn)","tryCatchPattern":"try:\n    bird = Bird(bg, game_over)\nexcept TypeError as e:\n    print('gameover_function must be callable:', e)","preventionTips":["Pass method references without parentheses","Never default callbacks to None when the constructor validates callability","Use lambdas for no-op callbacks"],"tags":["tkinter","typeerror","callable-validation","callback"],"backgroundTag":"callback-not-callable","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}