[issue41109] subclasses of pathlib.PurePosixPath never call __init__ or __new__
Jeffrey Kintscher
report at bugs.python.org
Fri Aug 7 21:36:03 EDT 2020
Jeffrey Kintscher <websurfer at surf2c.net> added the comment:
The workaround is to override _init(), which I agree is not desirable.
This is the relevant code in PurePath, which is the super class of PurePosixPath:
@classmethod
def _from_parsed_parts(cls, drv, root, parts, init=True):
self = object.__new__(cls)
self._drv = drv
self._root = root
self._parts = parts
if init:
self._init()
return self
...
def _init(self):
# Overridden in concrete Path
pass
To me, the clean way to get the desired behavior seems like it would be to have _init() call self.__init__().
def _init(self):
# Overridden in concrete Path
self.__init__()
This fixes p.parent, but GithubPath() ends up calling GithubPath.__init__() twice – the first time by PurePath.__new__() calling PurePath._init() and the second time by the GithubPath object creation.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41109>
_______________________________________
More information about the Python-bugs-list
mailing list