{"record":{"id":"98362515cdc860bc","repo":"python/cpython","slug":"cls-name-takes-no-arguments","errorCode":null,"errorMessage":"{cls.__name__}() takes no arguments","messagePattern":"(.+?)\\(\\) takes no arguments","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Lib/_py_warnings.py","lineNumber":821,"sourceCode":"        stacklevel = self.stacklevel\n        if category is None:\n            arg.__deprecated__ = msg\n            return arg\n        elif isinstance(arg, type):\n            import functools\n            from types import MethodType\n\n            original_new = arg.__new__\n\n            @functools.wraps(original_new)\n            def __new__(cls, /, *args, **kwargs):\n                if cls is arg:\n                    _wm.warn(msg, category=category, stacklevel=stacklevel + 1)\n                if original_new is not object.__new__:\n                    return original_new(cls, *args, **kwargs)\n                # Mirrors a similar check in object.__new__.\n                elif cls.__init__ is object.__init__ and (args or kwargs):\n                    raise TypeError(f\"{cls.__name__}() takes no arguments\")\n                else:\n                    return original_new(cls)\n\n            arg.__new__ = staticmethod(__new__)\n\n            if \"__init_subclass__\" in arg.__dict__:\n                # __init_subclass__ is directly present on the decorated class.\n                # Synthesize a wrapper that calls this method directly.\n                original_init_subclass = arg.__init_subclass__\n                # We need slightly different behavior if __init_subclass__\n                # is a bound method (likely if it was implemented in Python).\n                # Otherwise, it likely means it's a builtin such as\n                # object's implementation of __init_subclass__.\n                if isinstance(original_init_subclass, MethodType):\n                    original_init_subclass = original_init_subclass.__func__\n\n                @functools.wraps(original_init_subclass)\n                def __init_subclass__(*args, **kwargs):","sourceCodeStart":803,"sourceCodeEnd":839,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_py_warnings.py#L803-L839","documentation":"Raised by the __new__ wrapper that warnings.deprecated installs when it decorates a class. When the class inherits object.__new__ and object.__init__ (i.e. the decorator must synthesize instantiation), passing any arguments to the constructor hits this TypeError, mirroring object.__new__'s own check. The deprecation wrapper cannot know which __init__ signature is legal, so it applies the same rule as the interpreter for argless classes.","triggerScenarios":"@warnings.deprecated('...') class Legacy: pass followed by Legacy(1) or Legacy(x=2); decorating a dataclass-like class that defines only class attributes and instantiating with args; subclasses that call super().__new__(cls, *args) with args while inheriting the wrapper.","commonSituations":"Deprecating a marker/empty class and forgetting call sites still pass arguments; deprecating a class whose real __init__ lives on a base that itself is decorated; copy/paste of instantiation call sites during migration off the deprecated class.","solutions":["Remove the arguments at call sites of the deprecated class (the class defines no __init__, so args were always invalid)","Define an explicit __init__ on the class (or its undecorated base) accepting the arguments before applying @deprecated","Apply @deprecated to a factory function instead of the argless class, so instantiation signature stays controlled"],"exampleFix":"// before\n@warnings.deprecated('use New')\nclass Old: pass\nOld(42)  # TypeError\n\n# after\n@warnings.deprecated('use New')\nclass Old:\n    def __init__(self, value=None): self.value = value\nOld(42)","handlingStrategy":"validation","validationCode":"@warnings.deprecated('use New')\nclass Old:\n    def __init__(self, value=None):\n        self.value = value\nOld(42)  # now legal","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define an explicit __init__ on decorated argless classes before shipping them","Grep call sites of a deprecated class for argument passing during migration","Prefer decorating a factory function when constructor args must stay flexible"],"tags":["warnings","deprecated","typeerror","constructor","stdlib"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}