How to Fix: TypeError: ‘NoneType’ object is not callable

3D illustration of a user trying to use a phone that has vanished, representing the 'NoneType object is not callable' error.

The NoneType object is not callable error means you are trying to “call” a variable (by putting () after it) as if it were a function, but the variable is actually None.

The Cause

This almost always happens when you think you have a function, but you actually have None. This can be for two main reasons.

1. A Function Forgot to return a Function

This is common in decorators or advanced code.

def my_decorator():
    # ... some logic ...
    # Whoops, forgot to return the wrapper function!
    pass

@my_decorator
def say_hello(): # 'say_hello' is now None
    print("Hello")

say_hello() # CRASH! TypeError: 'NoneType' object is not callable

2. A Variable You Think is a Function is None

You might misspell a variable name or, more commonly, a class method.

Problem Code:

my_list = [1, 2, 3]
# We want to sort the list, but we accidentally try to assign
# the .sort() method to a variable.
my_sorter = my_list.sort() # .sort() modifies IN-PLACE and returns None!

print(my_sorter) # Output: None
my_sorter()      # CRASH! 'NoneType' object is not callable

The Fix: Check your code! Find the variable you’re trying to call. print() its value just before the line that crashes. You’ll see that it’s None, and you can trace back why it’s not the function you were expecting.

Similar Posts

Leave a Reply