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 Jeffrey.Kintscher
Recipients Jeffrey.Kintscher, conchylicultor, louis-vincent.boudre, pitrou
Date 2020-08-14.02:12:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1597371171.14.0.887450602721.issue41109@roundup.psfhosted.org>
In-reply-to
Content
The current implementation calls object.__new__(cls), where cls is the child class type, from within a class method (@classmethod).  This is fine for Path.__new__() and PurePath.__new__(), which are called by the child class's __new__(), because we don't want them to recursively call the child class's __new__() when the child class is created.  This all works as expected when the child class is instantiated outside of Path and PurePath, and the child's __init__() gets called as expected.  I don't see any point in making changes to this behavior.

When one of approximately 20 PurePath and Path functions and properties instantiate a new child class object the same way PurePath.__new__() and Path.__new__() do, the child class's __new__() and __init__() functions are not called.  This is the problem we are trying to solve.

My fix is to add normal functions (i.e. not decorated with @classmethod) to instantiate child class objects using

obj = type(self)()

This creates a child class instance, and the child's __new__() and __init__() functions get called.

Once I have finished re-plumbing Path and PurePath to use the new functions and created the necessary unit tests (to make sure I didn't break anything), I will also look at adding 
a proper __init__() function to the two classes instead of having __new__() initialize the member variables.  I didn't mean to imply that __init__() isn't useful.  It is required to allow the child class to initialize its own variable.  I just meant it isn't required to force calling __init__() and __new__() in the child class.
History
Date User Action Args
2020-08-14 02:12:51Jeffrey.Kintschersetrecipients: + Jeffrey.Kintscher, pitrou, conchylicultor, louis-vincent.boudre
2020-08-14 02:12:51Jeffrey.Kintschersetmessageid: <1597371171.14.0.887450602721.issue41109@roundup.psfhosted.org>
2020-08-14 02:12:51Jeffrey.Kintscherlinkissue41109 messages
2020-08-14 02:12:50Jeffrey.Kintschercreate