Eric V. Smith <e...@trueblade.com> added the comment:

The fact that it's never been needed in the years that dataclasses and attrs 
have existed tell me it's kind of a niche requirement.

This does not seem like the ugliest code I've ever seen:

        if hasattr(super(), "__post_init__"):
            super().__post_init__()

or the probably more efficient, but more lines of code:

        try:
            post_init = super().__post_init__
        except AttributeError:
            pass
        else:
            post_init()

As always with calling super functions, the whole hierarchy needs to cooperate. 
Say you had a dataclass:

@dataclass
class Base:
    def __post_init__(self, some_arg):
        pass

How would an arbitrary derived class know how to call this? It can't. There has 
to be knowledge of the base class's requirements already. Surely knowing 
"__post_init__ must be called with some_arg" isn't too different from "I know 
__post_init__ doesn't exist". I don't think adding ways to make the "always 
call super" pattern easier is a good idea.

I'm still unconvinced, but I'll hold off on making a decision to see if there's 
more support. Maybe taking it to python-ideas would be worthwhile.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46757>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to