TypeError
TypeError: object() takes no arguments
Traceback
Traceback (most recent call last):
File "main.py", line 5, in <module>
u = User("Alice")
TypeError: object() takes no argumentsWhat causes this error
Arguments were passed to an __init__ method that does not accept them. The most common cause is a misspelled __init__ (like _init_ or __int__), causing Python to use the default no-argument constructor.
How to fix it
Verify the __init__ method name is spelled correctly with double underscores: `__init__`. Ensure the method accepts `self` as the first parameter followed by your custom parameters.
Code that causes this error
class User:
def _init_(self, name): # wrong! single underscores
self.name = name
u = User("Alice")Fixed code
class User:
def __init__(self, name):
self.name = name
u = User("Alice")About TypeError
This error is raised when you pass arguments to an object that does not accept them, most commonly when a class's `__init__` method is missing or misspelled. The classic scenario is defining a class with a method named `_init_` (single underscore) or `__int__` instead of `__init__` (double underscores on both sides). Python uses the default `object.__init__()` which takes no arguments, and your custom constructor never runs.
This error also occurs when calling `object()` with arguments directly, or when a class intentionally has no constructor parameters but you try to pass some. The error message mentions 'object()' specifically when `__init__` is not defined, which is a strong clue that the constructor method name is misspelled.
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