[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

Serhiy Storchaka report at bugs.python.org
Sun Mar 8 00:37:54 EST 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

There are two reasons:

1. os.path.expanduser() returns the path unchanged when a home directory cannot be resolved, pathlib.Path.expanduser() raises an error. The latter behavior looks more robust, but we can't change os.path.expanduser().

2. os.path.expanduser() needs to split the path on components while pathlib.Path.expanduser() already has ready components. In some cases it may be more efficient.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39899>
_______________________________________


More information about the Python-bugs-list mailing list