This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients AlexWaygood, Gobot1234, JelleZijlstra, gvanrossum, kj
Date 2022-02-14.02:05:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644804326.76.0.480942442326.issue46743@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-02-14 02:05:26gvanrossumsetrecipients: + gvanrossum, JelleZijlstra, Gobot1234, kj, AlexWaygood
2022-02-14 02:05:26gvanrossumsetmessageid: <1644804326.76.0.480942442326.issue46743@roundup.psfhosted.org>
2022-02-14 02:05:26gvanrossumlinkissue46743 messages
2022-02-14 02:05:26gvanrossumcreate