Skip to content

How to Resolve Python Error "TypeError: NoneType object is not callable"

Fix the Python TypeError: 'NoneType' object is not callable error by identifying why a variable holds None instead of a function, method, or callable object, and applying targeted solutions like checking assignments, avoiding name shadowing, and correcting function calls.

The TypeError: 'NoneType' object is not callable is a common runtime error in Python. It means you attempted to use the function call operator (()) on a variable or expression that holds the value None. Since None represents the absence of a value and is not a function, class, or other callable object, Python raises this error.

This guide explains the frequent causes of this error, such as unintentional None assignments or name conflicts, and provides clear solutions.

Understanding the Error: Callables vs. None

  • Callables: In Python, objects that can be "called" using parentheses () are known as callables. This includes functions (defined with def or lambda), methods (functions bound to objects), classes (calling a class creates an instance), and objects implementing the __call__ method.
  • None: As established previously, None is Python's special object representing nothingness or the absence of a value. It belongs to NoneType. None is not callable.

The TypeError occurs because the expression immediately preceding the parentheses () evaluates to None at runtime, and you can not "call" None.

The Primary Cause: Calling None with Parentheses ()

The direct cause is applying the call operator () to something that resolves to None.

value = None

try:
    result = value() # Trying to call None as if it were a function
except TypeError as e:
    print(e)

Common Scenarios Leading to None Values

Your variable didn't start as None, but ended up holding None before the call attempt. This happens for several reasons:

  • Function Implicitly Returning None: Functions without an explicit return statement automatically return None.
  • Variable Explicitly Assigned None: Simple assignment: my_variable = None.
  • In-Place Methods Returning None: Methods like list.sort(), list.append(), list.reverse() modify the object directly and return None. Assigning their result gives you None.
  • Function Conditionally Returning None: A function might return a value only if certain conditions are met, implicitly returning None otherwise.

Specific Error Patterns and Solutions

Calling a Variable That Holds None

  • Cause: The variable you are trying to call was assigned None at some point before the call.

  • Solution:

    1. Trace and Fix Assignment: Find where the variable becomes None and correct the logic so it holds the intended callable (function/class) instead.
    2. Check Before Calling: Add an if variable is not None: check before attempting the call.
    my_action = None # Intended to hold a function later, maybe
    
    
    if my_action is not None:
        print("Action is defined, calling it...")
        my_action()
    else:
        print("Action is None, can not call.") # This path is taken if my_action remains None

Calling a Function's Return Value (Which is None)

  • Cause: You call a function that returns None, and then immediately try to call that result again with another set of parentheses ().
  • Error Scenario:
    def setup_config():
        print("Configuring...")
    
    try:
        result = setup_config()()
    except TypeError as e:
        print(e)
  • Solution: Remove the extra, erroneous set of parentheses. Call the function only once.
    def setup_config():
        print("Configuring...")
    
    result = setup_config() # result will be None, but no error occurs here
    print(f"Result of setup_config: {result}") # Output: Result of setup_config: None

Name Shadowing (Variable vs. Function)

  • Cause: You define a function and later create a variable with the exact same name, assigning None (or any non-callable) to it. The variable name "shadows" the function name.

  • Error Scenario:

    def process_data():
        print("Processing...")
        return True
    
    process_data = None # ⚠️ Variable assignment shadows the function
    
    try:
        result = process_data()
    except TypeError as e:
        print(e)

    Output:

    'NoneType' object is not callable
  • Solution: Rename either the function or the variable to avoid the name collision.

    def process_data():
        print("Processing...")
        return True
    
    process_data_result = None # ✅ Use a different variable name
    
    result = process_data()
    print(f"Function call successful, result: {result}")

    Output:

    Processing...
    Function call successful, result: True

Name Shadowing (Attribute vs. Method in a Class)

  • Cause: A class defines an instance attribute and a method with the same name. Accessing the name usually resolves to the attribute, preventing the method from being called. If the attribute holds None, you get the NoneType error when trying to call it.

  • Error Scenario:

    class Greeter:
        def __init__(self, message=None):
            self.message = message # Attribute holding None initially
    
        def message(self): # Method
            return "Default Greeting"
    
    g = Greeter() # self.message attribute is None
    
    try:
        greeting = g.message()
    except TypeError as e:
        print(e)

    Output:

    'NoneType' object is not callable
  • Solution: Rename the attribute or the method so they have distinct names.

    class GreeterFixed:
        def __init__(self, message_text=None):
            self.message_text = message_text # ✅ Renamed attribute
    
        def get_message(self):  # ✅ Renamed method
            return self.message_text or "Default Greeting"
    
    g_fixed = GreeterFixed()
    print(g_fixed.get_message())        # Output: Default Greeting
    
    g_fixed_custom = GreeterFixed("Custom Hello")
    print(g_fixed_custom.get_message()) # Output: Custom Hello

    Output:

    Default Greeting
    Custom Hello

Passing func() Instead of func as an Argument

  • Cause: When passing a function as an argument to another function (e.g., for callbacks or higher-order functions), you accidentally call the function (func()) instead of passing the function object (func) itself. If func() returns None, the receiving function gets None instead of the expected callable.

  • Error Scenario:

    def run_callback(callback_func):
        print("Running callback...")
        callback_func() # Expects callback_func to be callable
    
    def my_action():
        print("Action executed!")
    
    try:
        run_callback(my_action())
    except TypeError as e:
        print(e)

    Output:

    Action executed!
    Running callback...
    'NoneType' object is not callable
  • Solution: Pass the function object itself, without calling it.

    def run_callback(callback_func):
        print("Running callback...")
        callback_func()
    
    def my_action():
        print("Action executed!")
    
    run_callback(my_action)

    Output:

    Running callback...
    Action executed!

Debugging the Error

  1. Identify the Call: Look at the line in the traceback where the error occurs. Pinpoint the exact variable or expression immediately followed by ().

  2. Check Value/Type: Print the value and type of that variable/expression just before the call attempt:

    print(f"DEBUG: Value is {repr(variable_being_called)}")
    print(f"DEBUG: Type is {type(variable_being_called)}")

    If the value is None and the type is <class 'NoneType'>, you've found the immediate problem.

  3. Trace Back: Determine why the variable holds None. Was it explicitly assigned? Was it the result of a function that returned None (check function definitions)? Was there name shadowing?

Conclusion

The TypeError: 'NoneType' object is not callable signals an attempt to execute None as if it were a function using parentheses ().

To fix this error:

  1. Ensure the variable you are calling actually holds a function, method, or other callable object, not None.
  2. Trace back to find where the None value originated (missing return, conditional returns, explicit assignment, result of in-place methods like sort()). Correct that source logic.
  3. Check for name shadowing where a variable might be hiding a function/method of the same name (or vice-versa). Rename to resolve conflicts.
  4. Verify you aren't calling a function twice (func()()) if the first call returns None.
  5. When passing functions as arguments, pass the function object (func), not the result of calling it (func()) unless that result is itself intended to be callable.
  6. Optionally, add checks (if variable is not None:) before attempting a call if the variable might legitimately be None sometimes.

By ensuring you only attempt to call actual callable objects, you can prevent this common TypeError.

Navigation