Skip to content

Being unable to specify the API for instantiating an object is a deleterious restriction for Protocols #110788

Closed
@k98kurz

Description

@k98kurz

It makes no sense to be unable to specify the interface for instantiating a class object. The only way around this at the moment is to specify a class method that serves the literal same purpose as the __init__ method, then relying upon it instead of the normal mechanism for object instantiation.

This is one of the poorest design decisions in CPython in my opinion. It breaks introspection tools that seek to document the required __init__ API, and it breaks even the concept of checking if the required __init__ API is followed. As I said, the only way around this is to create a new class method that merely replicates what the built-in __init__ method is supposed to do.

def _no_init_or_replace_init(self, *args, **kwargs):

If there is some justification for this frustrating antipattern, please let me know. I do not see anything about this in PEP-544, though I only skimmed it looking for an answer and did not study it thoroughly.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions