Skip to content
Latchkey

Python "TypeError: X takes N positional arguments but M were given" in CI

Python counted the arguments at the call site and they exceed what the function definition accepts. The mismatch is usually a stale call after a signature change, or a method that forgot the implicit self.

What this error means

A run fails with "TypeError: f() takes 2 positional arguments but 3 were given" pointing at the call line. It reproduces identically every run.

python
Traceback (most recent call last):
  File "app/service.py", line 41, in handle
    return transform(payload, opts, ctx)
TypeError: transform() takes 2 positional arguments but 3 were given

Common causes

The function signature changed but a caller did not

A parameter was removed or made keyword-only, yet a call site still passes the old positional argument.

A method is missing self or is called unbound

Defining a method without self, or calling it off the class rather than an instance, shifts the argument count by one.

How to fix it

Align the call with the current signature

  1. Open the function named in the error and read its parameter list.
  2. Update the failing call to pass the right count, using keywords for keyword-only params.
  3. Re-run to confirm the call now matches.
app/service.py
# transform takes (payload, opts); drop the extra positional
return transform(payload, opts)

Add self to instance methods

Instance methods must declare self as the first parameter and be called on an instance.

app/worker.py
class Worker:
    def run(self, payload):
        ...

How to prevent it

  • Update all call sites in the same change as a signature edit.
  • Use keyword arguments so positional drift cannot occur.
  • Run a type checker to catch arity mismatches before CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →