Skip to content

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

@JelleZijlstra

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

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