Steven D'Aprano added the comment:

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('.')

----------
nosy: +pitrou, steven.daprano
versions:  -Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30957>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to