Skip to content

Better error message if Generic.__init_subclass__ is not called #139905

Closed

Description

@JelleZijlstra

Bug report

Bug description:

This code (from https://discuss.python.org/t/type-object-cls-has-no-attribute-parameters/104276/4 ):

class Base:
    def __init_subclass__(cls) -> None:
        pass

class Sub[T](Base): pass

class SubSub(Sub[object]): pass

Fails with an inscrutable error about cls.__parameters__ not existing, because super().__init_subclass__() was not called.

Let's produce a clearer error message in this case so it's easier to debug for the next person.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added a commit that references this issue on Oct 11, 2025
  2. added 2 commits that reference this issue on Oct 11, 2025
  3. added 2 commits that reference this issue on Oct 11, 2025
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions