TypeError
TypeError: function() missing 1 required positional argument: 'x'
Traceback
Traceback (most recent call last):
File "main.py", line 4, in <module>
greet("Alice")
TypeError: function() missing 1 required positional argument: 'x'What causes this error
A function was called without providing all required positional arguments. Missing self in method calls, forgotten arguments, or incorrect argument counts trigger this error.
How to fix it
Check the function signature and provide all required arguments. For methods, ensure you are calling on an instance (self is passed automatically). Add default values to optional parameters.
Code that causes this error
def greet(name, greeting):
return f"{greeting}, {name}!"
greet("Alice")Fixed code
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Alice"))About TypeError
This error is raised when a function is called without providing all required positional arguments. Every parameter in a function signature that does not have a default value must be supplied by the caller. This error commonly appears when forgetting to pass an argument, when calling an instance method without the proper instance (so `self` consumes the first argument), or when subclassing and forgetting to pass arguments to the parent class.
The error message specifies the missing argument name, making it easy to identify which parameter was not supplied. In object-oriented code, a common variant is calling an unbound method — for example, calling `MyClass.method(arg)` instead of `instance.method(arg)`, where `self` takes the place of `arg` and the actual argument is missing.
Common scenarios
Performing operations between incompatible types like strings and integers
Calling methods that return None and chaining operations on the result
Passing the wrong number or type of arguments to a function
Using bracket notation on objects that do not support indexing