FAQ
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 <module>
test = PPath("dir", "test.txt")
File "/anaconda/lib/python3.4/pathlib.py", line 907, in __new__
self = cls._from_parts(args, init=False)
File "/anaconda/lib/python3.4/pathlib.py", line 589, in _from_parts
drv, root, parts = self._parse_args(args)
File "/anaconda/lib/python3.4/pathlib.py", line 582, in _parse_args
return cls._flavour.parse_parts(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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150501/53e1438f/attachment.html>

Search Discussions

  • Ryan Gonzalez at May 2, 2015 at 8:30 pm
    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 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 <module>
    test = PPath("dir", "test.txt")
    File "/anaconda/lib/python3.4/pathlib.py", line 907, in __new__
    self = cls._from_parts(args, init=False)
    File "/anaconda/lib/python3.4/pathlib.py", line 589, in _from_parts
    drv, root, parts = self._parse_args(args)
    File "/anaconda/lib/python3.4/pathlib.py", line 582, in _parse_args
    return cls._flavour.parse_parts(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/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-dev/attachments/20150502/32580ecf/attachment.html>
  • Guido van Rossum at May 3, 2015 at 4:45 pm
    It does sound like subclassing Path should be made easier.


    On Sat, May 2, 2015 at 1:30 PM, Ryan Gonzalez 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 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 <module>
    test = PPath("dir", "test.txt")
    File "/anaconda/lib/python3.4/pathlib.py", line 907, in __new__
    self = cls._from_parts(args, init=False)
    File "/anaconda/lib/python3.4/pathlib.py", line 589, in _from_parts
    drv, root, parts = self._parse_args(args)
    File "/anaconda/lib/python3.4/pathlib.py", line 582, in _parse_args
    return cls._flavour.parse_parts(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>
  • Ned Deily at May 5, 2015 at 9:18 pm
    In article
    <caab4jgkqylh4epgs2tnty1rmaddig4wrojzx9ek8zepxtwq9-a@mail.gmail.com>,
      Christophe Bal wrote:
    In this post
    <http://stackoverflow.com/questions/29850801/simple-subclassing-pathlib-path-d
    oes-not-work/29854141#29854141>,
    I have noticed a problem with the following code. [...]
    This breaks the sub-classing from Python point of view. In the post
    <http://stackoverflow.com/questions/29850801/simple-subclassing-pathlib-path-d
    oes-not-work/29854141#29854141>,
    I give a hack to sub-class Path but it's a bit Unpythonic.

    In article
    <cap7+vjlkrtavb8bp34wwtdkx0ra+opb1tz+9ojkkwlqwtupruq@mail.gmail.com>,
      Guido van Rossum wrote:
    It does sound like subclassing Path should be made easier.

    Christophe, if you want to pursue this, you should open an issue for it
    on the Python bug tracker, bugs.python.org. Otherwise, it will likely
    be forgotten here.


    --
      Ned Deily,
      nad at acm.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-dev @
categoriespython
postedMay 1, '15 at 7:30p
activeMay 5, '15 at 9:18p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2017 Grokbase