Content-Length: 293292 | pFad | https://github.com/python/cpython/issues/139905

40 Better error message if `Generic.__init_subclass__` is not called · Issue #139905 · python/cpython · GitHub
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









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/139905

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy