[Python-Dev] Sub-claasing pathlib.Path seems impossible (original) (raw)
Guido van Rossum guido at python.org
Sun May 3 18:45:26 CEST 2015
- Previous message (by thread): [Python-Dev] Sub-claasing pathlib.Path seems impossible
- Next message (by thread): [Python-Dev] Sub-claasing pathlib.Path seems impossible
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
It does sound like subclassing Path should be made easier.
On Sat, May 2, 2015 at 1:30 PM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
http://stackoverflow.com/a/29880095/2097780
My favorite thing about Python is that it's so easy to be evil. ;)
On Fri, May 1, 2015 at 2:30 PM, Christophe Bal <projetmbc at gmail.com> wrote: Hello.
In this post <http://stackoverflow.com/questions/29850801/simple-subclassing-pathlib-path-does-not-work/29854141#29854141>, I have noticed a problem with the following code. from pathlib import Path class PPath(Path): def init(self, *args, **kwargs): super().init(*args, **kwargs)
test = PPath("dir", "test.txt")
This gives the following error message.
Traceback (most recent call last): File "/Users/projetmbc/test.py", line 14, in test = PPath("dir", "test.txt") File "/anaconda/lib/python3.4/pathlib.py", line 907, in new self = cls.fromparts(args, init=False) File "/anaconda/lib/python3.4/pathlib.py", line 589, in fromparts drv, root, parts = self.parseargs(args) File "/anaconda/lib/python3.4/pathlib.py", line 582, in parseargs return cls.flavour.parseparts(parts)AttributeError: type object 'PPath' has no attribute 'flavour' This breaks the sub-classing from Python point of view. In the post <http://stackoverflow.com/questions/29850801/simple-subclassing-pathlib-path-does-not-work/29854141#29854141>, I give a hack to sub-class Path but it's a bit Unpythonic. Christophe BAL *Enseignant de mathématiques en Lycée *et développeur Python amateur --- *French math teacher in a "Lycée" **and **Python *amateur developer
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com
-- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150503/94b3c35f/attachment-0001.html>
- Previous message (by thread): [Python-Dev] Sub-claasing pathlib.Path seems impossible
- Next message (by thread): [Python-Dev] Sub-claasing pathlib.Path seems impossible
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]