Title: pathlib.Path: add `username` argument to `home()`
Type: enhancement Stage:
Components: Library (Lib) Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barneygale
Priority: normal Keywords:

Created on 2021-01-22 03:57 by barneygale, last changed 2021-01-22 04:11 by barneygale.

Messages (2)
msg385472 - (view) Author: Barney Gale (barneygale) * Date: 2021-01-22 03:57
The `pathlib.Path.home()` function looks like:

    def home(cls):
        """Return a new path pointing to the user's home directory (as
        returned by os.path.expanduser('~')).
        return cls(cls()._flavour.gethomedir(None))

If we add a `username=None` parameter and pass this to `gethomedir()` we can easily add a lookup of another user's home directory, so:

    import pathlib
    username = 'phil'
    pathlib.Path.home(username) == pathlib.Path('~' + username).expanduser()
msg385473 - (view) Author: Barney Gale (barneygale) * Date: 2021-01-22 04:11
I should add that this is part of a plan to spin out some `Path` methods into a new `UserPath` class. Notably, in this case, `UserPath.expanduser()` will call `self.home()` under-the-hood. This is done to reduce the surface area of abstract methods that subclasses of `UserPath` need implement. More discussion here:
Date User Action Args
2021-01-22 04:11:31barneygalesetmessages: + msg385473
2021-01-22 03:57:15barneygalecreate