E-SE0009 — Decorator applied to a non-callable object

Error Type

Syntax Error

Phase

defining a problem with the decorator API

Python exception

TypeError (builtin)

Message

The decorator API can only be applied to a callable.

Possible fix: apply it directly to a function definition.

Cause

A value that is not callable was passed where the decorator API expects a function, for example by calling problem.update(...) or the decorator returned by jijmodeling.Problem.define(...) with something other than a function. A typical mistake is writing @problem.update("some name"): unlike jijmodeling.Problem.define, update takes no arguments of its own, so the string ends up where the function is expected.

problem = jm.Problem("My Problem")

@problem.update("My Problem")  # `update` receives the string, not the function
def build(problem: jm.DecoratedProblem):
    ...

Fix

Apply @problem.update without arguments, directly above the def. If you want to set the problem’s name, sense, or description, pass them to @jijmodeling.Problem.define(...) instead, which returns the actual decorator.

problem = jm.Problem("My Problem")

@problem.update
def build(problem: jm.DecoratedProblem):
    ...

# or, defining name and function together:
@jm.Problem.define("My Problem")
def myprob(problem: jm.DecoratedProblem):
    ...

When calling these APIs explicitly rather than with @-syntax, pass the function object itself, as in problem.update(build).