{"record":{"id":"2a87a512a5285fc3","repo":"geekcomputers/Python","slug":"the-score-function-argument-must-be-a-callable-obj","errorCode":null,"errorMessage":"The score_function argument must be a callable object.","messagePattern":"The score_function argument must be a callable object\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Flappy Bird - created with tkinter/Tubes.py","lineNumber":40,"sourceCode":"        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\n\n        # Calcula a largura e altura da imagem","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Flappy Bird - created with tkinter/Tubes.py#L22-L58","documentation":"Tubes' constructor validates that score_function is callable because it invokes the callback each time the bird passes a tube. Passing a non-callable raises this TypeError before the thread starts.","triggerScenarios":"Passing score() (the return value) instead of score, a string, an int, or None as score_function.","commonSituations":"Calling the callback instead of referencing it; renaming the score method and passing a stale attribute; wiring a property/attribute that holds a value rather than a function.","solutions":["Pass the function reference without parentheses: Tubes(bg, bird, self.increase_score)","If the scorer is a method of another object, pass obj.increase_score","Use a lambda or partial when extra arguments are needed"],"exampleFix":"# before\ntubes = Tubes(bg, bird, self.increase_score())\n# after\ntubes = Tubes(bg, bird, self.increase_score)","handlingStrategy":"type-guard","validationCode":"if not callable(score_function):\n    raise TypeError('score_function must be a function reference')","typeGuard":"def is_callable(fn) -> bool:\n    return callable(fn)","tryCatchPattern":"try:\n    tubes = Tubes(bg, bird, self.increase_score)\nexcept TypeError as e:\n    print('score_function must be callable:', e)","preventionTips":["Pass function references, not calls: self.increase_score not self.increase_score()","Use functools.partial when binding extra args","Keep callback names in sync after renames"],"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"}