TypeError: Wrong Number of Arguments

TypeError: foo() takes 2 positional arguments but 3 were given

Quick Answer

You are passing more or fewer arguments than the function expects. For class methods, remember that self counts as the first argument. Check the function signature and match the argument count.

Why This Happens

Python enforces function signatures strictly. When you define def foo(a, b), calling foo(1, 2, 3) fails because there is no parameter for the third argument. A common variant is forgetting that instance methods receive self automatically.

The Problem

class Calculator:
    def add(self, a, b):
        return a + b

calc = Calculator()
result = calc.add(1, 2, 3)

The Fix

class Calculator:
    def add(self, a, b):
        return a + b

calc = Calculator()
result = calc.add(1, 2)

Step-by-Step Fix

  1. 1

    Check the function signature

    Look at the function definition to see how many parameters it expects.

  2. 2

    Count your arguments

    Count the actual arguments at the call site and match them to the parameters.

  3. 3

    Use *args for variable arguments

    If the function needs variable arguments, change the signature to use *args.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free