Message372297
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. |
|
Date |
User |
Action |
Args |
2020-06-25 02:51:23 | conchylicultor | set | recipients:
+ conchylicultor |
2020-06-25 02:51:23 | conchylicultor | set | messageid: <1593053483.35.0.664517914864.issue41109@roundup.psfhosted.org> |
2020-06-25 02:51:23 | conchylicultor | link | issue41109 messages |
2020-06-25 02:51:22 | conchylicultor | create | |
|