Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-41109: subclasses of pathlib.Path and pathlib.PurePath now call the subclass's __init__() and __new__() functions when returning new objects #21920

Closed
wants to merge 22 commits into from

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