TypePython Error

TypeError

TypeError: function() got an unexpected keyword argument 'x'

Traceback

terminal
Traceback (most recent call last):
  File "main.py", line 4, in <module>
    create_user(name="Alice", emial="[email protected]")  # typo
TypeError: function() got an unexpected keyword argument 'x'

What causes this error

A keyword argument was passed that does not match any parameter in the function signature. Typos, API changes, or incorrect argument forwarding are common triggers.

How to fix it

Check the function's parameter names and fix the typo. Consult the library documentation for the correct API. Use IDE autocompletion to avoid typos in keyword arguments.

Code that causes this error

Broken
def create_user(name, email):
    return {"name": name, "email": email}

create_user(name="Alice", emial="[email protected]")  # typo

Fixed code

Fixed
def create_user(name, email):
    return {"name": name, "email": email}

create_user(name="Alice", email="[email protected]")

About TypeError

This error is raised when a function is called with a keyword argument that does not match any parameter name. This happens when there is a typo in the argument name, when the function signature changed between versions of a library, or when passing keyword arguments to a function that uses `*args` but not `**kwargs`. The error message specifies the unexpected keyword, making the typo easy to spot.

In class inheritance, this can occur when __init__ signatures do not align between parent and child classes and keyword arguments are forwarded with `super().__init__(**kwargs)`. When designing APIs, accepting `**kwargs` provides flexibility but makes it harder to catch typos — consider using explicit parameters with clear names instead.

Common scenarios

1

Performing operations between incompatible types like strings and integers

2

Calling methods that return None and chaining operations on the result

3

Passing the wrong number or type of arguments to a function

4

Using bracket notation on objects that do not support indexing

Related errors