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 sbstp
Recipients sbstp
Date 2017-07-18.06:40:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500360011.44.0.112020885927.issue30957@psf.upfronthosting.co.za>
In-reply-to
Content
Because of the special way Path and PurePath are instantiated, they can't be inherited like a normal class. Here's an example of the issue:

>>> import pathlib
>>> class MyPath(pathlib.Path):
...   pass
... 
>>> p = MyPath('/home')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/pathlib.py", line 969, in __new__
    self = cls._from_parts(args, init=False)
  File "/usr/lib/python3.5/pathlib.py", line 651, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/usr/lib/python3.5/pathlib.py", line 644, in _parse_args
    return cls._flavour.parse_parts(parts)
AttributeError: type object 'MyPath' has no attribute '_flavour'

A solution is to get the concrete type of Path via type(Path()) and inherit the class it yields, but it isn't pretty or intuitive. Perhaps a declaration that directs to the proper class could be added to the module.

PlatformPath = WindowsPath if os.name == 'nt' else PosixPath
PurePlatformPath = ...
History
Date User Action Args
2017-07-18 06:40:11sbstpsetrecipients: + sbstp
2017-07-18 06:40:11sbstpsetmessageid: <1500360011.44.0.112020885927.issue30957@psf.upfronthosting.co.za>
2017-07-18 06:40:11sbstplinkissue30957 messages
2017-07-18 06:40:10sbstpcreate