Message298584
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('.') |
|
Date |
User |
Action |
Args |
2017-07-18 12:34:35 | steven.daprano | set | recipients:
+ steven.daprano, pitrou, sbstp |
2017-07-18 12:34:34 | steven.daprano | set | messageid: <1500381274.98.0.101553634553.issue30957@psf.upfronthosting.co.za> |
2017-07-18 12:34:34 | steven.daprano | link | issue30957 messages |
2017-07-18 12:34:34 | steven.daprano | create | |
|