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 louis-vincent.boudre
Recipients Jeffrey.Kintscher, conchylicultor, louis-vincent.boudre, pitrou
Date 2020-08-08.13:47:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596894457.45.0.691783286863.issue41109@roundup.psfhosted.org>
In-reply-to
Content
Path.__new__ should not call _from_parts because it breaks the specialization by directly using object.__new__.
This is why `_from_parts` has to be duplicated in each subclass's `__new__`.

My suggestion (first draft) is to do the parsing of arguments inside an `__init__` in the Path class hierarchy
and deprecate  `_from_parts`.

```
class PurePath:
   
     def __new__(cls, *args):
         if cls is PurePath:
             cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
         super().__new__(cls, *args) # Here we remove call to from_parts

     def __init__(self, *args):
         # We should have an __init__ in the hierarchy.
         drv, root, parts = self._parse_args(args)  # this would get the proper _flavour.
         self._drv = drv
         self._root = root
         self._parts = parts

     ...

class Path(PurePath):
     def __new__(cls, *args, **kwargs):
        if cls is Path:
            cls = WindowsPath if os.name == 'nt' else PosixPath

        # REMOVE THIS LINE: self = cls._from_parts(args, init=False) #

        if not self._flavour.is_supported:
            raise NotImplementedError("cannot instantiate %r on your system"
                                      % (cls.__name__,))
        return super().__new__(cls, *args, **kwargs) # Use super

```


I don't know what is the purpose of `_init` and if it could be replaced by an extra keyword argument in __init__.

The class method `_from_parts` would become deprecated since the argument parsing would be now handled by `__init__`.

By using __init__ and avoid the direct call to `object.__new__` we would respect class specialization and custom class could be implemented intuitively.
History
Date User Action Args
2020-08-08 13:47:37louis-vincent.boudresetrecipients: + louis-vincent.boudre, pitrou, Jeffrey.Kintscher, conchylicultor
2020-08-08 13:47:37louis-vincent.boudresetmessageid: <1596894457.45.0.691783286863.issue41109@roundup.psfhosted.org>
2020-08-08 13:47:37louis-vincent.boudrelinkissue41109 messages
2020-08-08 13:47:36louis-vincent.boudrecreate