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 steven.daprano
Recipients pitrou, sbstp, steven.daprano
Date 2017-07-18.12:34:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500381274.98.0.101553634553.issue30957@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.4, 3.5 and 3.6 are in feature-freeze, so this enhancement can only apply to 3.7.

You say that pathlib.Path "can't be subclassed", but then immediately show an example of subclassing it:

>>> class MyPath(pathlib.Path):
...   pass
... 

Which works fine. If you run:

issubclass(MyClass, pathlib.Path)

it returns True. Unfortunately, it looks like your subclass broke one of the class invariants, but you don't find out until you try to instantiate it:

>>> p = MyPath('/home')
Traceback (most recent call last):
  ...
AttributeError: type object 'MyPath' has no attribute '_flavour'


_flavour is a private attribute, and is not documented, so I don't think subclassing is supported. If that is the case:

- the documentation should say that subclassing is not supported;
- or the Path class should actively prohibit subclassing (will 
  probably require a metaclass);
- or both.

If subclassing is supported, then I think there ought to be a better way than this:


py> class MyPath(pathlib.Path):
...     _flavour = pathlib.Path('.')._flavour
...
py> MyPath('.')
MyPath('.')
History
Date User Action Args
2017-07-18 12:34:35steven.dapranosetrecipients: + steven.daprano, pitrou, sbstp
2017-07-18 12:34:34steven.dapranosetmessageid: <1500381274.98.0.101553634553.issue30957@psf.upfronthosting.co.za>
2017-07-18 12:34:34steven.dapranolinkissue30957 messages
2017-07-18 12:34:34steven.dapranocreate