Part of the problem is that the Path
class implements some conditional logic in __new__
that doesn't really lend itself to subclassing. Specifically:
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
This sets the type of the object you get back from Path(...)
to either PosixPath
or WindowsPath
, but only if cls is Path
, which will never be true for a subclass of Path
.
That means within the __new__
function, cls won't have the
_flavourattribute (which is set explicitly for the
*WindowsPath and *PosixPath
classes), because your Pl
class doesn't have a _flavour
attribute.
I think you would be better off explicitly subclassing one of the other classes, such as PosixPath
or WindowsPath
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…