Guido van Rossum <gu...@python.org> added the comment:
Thanks for the small example, I understand what you are trying to do now. I don't think it's possible in general, since you are blindly instantiating the type (self.__orig_class__.__args__[0]) without arguments. That doesn't work for all types. But that aside, the problem with implementing what you wish is that we would have to refactor class instantiation to break it in two parts, one part that calls __new__() and produces the instance, and one part that (if certain conditions are satisifed) calls __init__(). I now also understand the two code fragments you gave, and breaking the construction in those two parts is exactly what you are doing there. However. The "if certain conditions are satisfied" part is complex. For example, self.__origin__.__new__() could return an instance of a different type -- if that's not a subclass of self.__origin__, the call to __init__() will be skipped. There may also be other that happen between __new__() and __init__(), and other things may happen before __new__() or after __init__() that we would skip by simply calling __new__() followed by __init__() ourselves -- someone else should research this. And we may have the same issue in the C code in ga_call() in genericaliasobject.c. (I'm not sure if that's relevant.) I'm also not sure what static type checkers would make of this. But I presume you don't care about that. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46743> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com