Skip to content

Subclass definitions should be validated against superclass __init_subclass__ definitions #1541

@AlexWaygood

Description

@AlexWaygood

Summary

The Bar definition here fails at runtime, but we currently don't catch the error:

class Foo:
    def __init_subclass__(cls, arg: int): ...
    
class Bar(Foo): ...
>>> class Bar(Foo): ...
... 
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    class Bar(Foo): ...
TypeError: Foo.__init_subclass__() missing 1 required positional argument: 'arg'

In order for it to succeed, it would need to be something like

class Foo:
    def __init_subclass__(cls, arg: int): ...
    
class Bar(Foo, arg=42): ...

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    runtime semanticsAccurate modeling of how Python's semantics work at runtime

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions