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 conchylicultor
Recipients conchylicultor
Date 2020-06-25.02:51:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593053483.35.0.664517914864.issue41109@roundup.psfhosted.org>
In-reply-to
Content
I have a subclass GithubPath of PurePosixPath.

```
class GithubPath(pathlib.PurePosixPath):

  def __new__(cls, *args, **kwargs):
    print('New')
    return super().__new__(cls, *args, **kwargs)

  def __init__(self, *args, **kwargs):
    print('Init')
    super().__init__()
```

Calling `child.parent` create a new GithubPath but without ever calling __new__ nor __init__. So my subclass is never notified it is created.

```
p = GithubPath()  # Print "New", "Init"

p.parent  # Create a new GithubPath but bypass the constructors
```

The reason seems to be that parent calls _from_parts which create a new object through `object.__new__(cls)`: https://github.com/python/cpython/blob/cf18c9e9d4d44f6671a3fe6011bb53d8ee9bd92b/Lib/pathlib.py#L689


A hack is to subclass `_init` but it seems hacky as it relies on internal implementation detail.
History
Date User Action Args
2020-06-25 02:51:23conchylicultorsetrecipients: + conchylicultor
2020-06-25 02:51:23conchylicultorsetmessageid: <1593053483.35.0.664517914864.issue41109@roundup.psfhosted.org>
2020-06-25 02:51:23conchylicultorlinkissue41109 messages
2020-06-25 02:51:22conchylicultorcreate