Skip to content

Subclass of typing.Any cannot be instantiated with arguments #117110

Description

@Azureblade3808

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

Activity

  1. added a commit that references this issue on Mar 29, 2024
  2. added 2 commits that reference this issue on Mar 29, 2024
  3. added 2 commits that reference this issue on Mar 29, 2024
  4. added a commit that references this issue on Apr 17, 2024
  5. SantiiRepair commented on Mar 16, 2025

    @SantiiRepair

    Hey, but when I do it, I get a TypeError

    if TYPE_CHECKING:
        from ebinexpy.source import Ebinex
    else:
        Ebinex = Any

    TypeError: Any cannot be instantiated

  6. sobolevn commented on Mar 16, 2025

    @sobolevn
    Member

    In runtime Any cannot be called, that's correct :)

  7. SantiiRepair commented on Mar 16, 2025

    @SantiiRepair

    In runtime Any cannot be called, that's correct :)

    ahhhhh got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions