cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Subclass of `typing.Any` cannot be instantiated with arguments

Open Azureblade3808 opened this issue 1 year ago • 0 comments

Bug report

Bug description:

from typing import Any

class C(Any):
    def __init__(self, v): ...

C(0)   # TypeError: object.__new__() takes exactly one argument (the type to instantiate)

The fix should be easy. Just replace --

        return super().__new__(cls, *args, **kwargs)

with --

        return super().__new__(cls)

in typing.Any.__new__(...), as the superclass is object and its __new__ doesn't accept additional arguments.

CPython versions tested on:

3.12

Operating systems tested on:

Linux, Windows

Linked PRs

  • gh-117111

Azureblade3808 avatar Mar 21 '24 07:03 Azureblade3808