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 givenCommon 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
- Open the function named in the error and read its parameter list.
- Update the failing call to pass the right count, using keywords for keyword-only params.
- 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
Python "AttributeError: module X has no attribute Y" in CIFix "AttributeError: module X has no attribute Y" in CI - the imported module loaded but the name you accesse…
Python "cannot import name X from partially initialized module" (circular) in CIFix "ImportError: cannot import name X from partially initialized module Y (most likely due to a circular imp…
Python "ModuleNotFoundError: No module named X" import in CIFix "ModuleNotFoundError: No module named X" in CI - the import target is not installed in the active environ…