Skip to content

Conversation

websurfer5
Copy link
Contributor

@websurfer5 websurfer5 commented Aug 19, 2020

Several pathlib.Path and pathlib.PurePath return new Path and PurePath objects. A subclass of one of those classes returns objects that are instances of the subclass, but the subclass's new() and init() functions are not called. A subclass has to override Path._init() or PurePath._init() to perform custom initialization for these returned objects in addition to its init() function.

This patch reworks the Path and PurePath object creation processes to ensure that the new() and init() functions in subclasses get called. It moves the object creation process from PurePath._from_parts() and PurePath._from_parsed_parts() to PurePath.init() and Path.init(), and marks the two functions with deprecation warnings.

https://bugs.python.org/issue41109

@terryjreedy
Copy link
Member

@barneygale Does #102789 supersede this? (Should this be closed?)

@barneygale
Copy link
Contributor

@barneygale Does #102789 supersede this? (Should this be closed?)

Yes you're right it does, thanks!

@websurfer5 thanks for your work on this. We came to a similar solution in the end by the looks of things!

@barneygale barneygale closed this Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants