[Python-Dev] expanduser('~other') reliability and future

37 views
Skip to first unread message

Barney Gale

unread,
Apr 28, 2021, 12:51:19 PM4/28/21
to python-dev

There’s been a bit of discussion on the reliability of getting other users' home directories via os.path.expanduser(), mostly on issue42998.

In msg390503, Serhiy Storchaka pointed out that ntpath only makes an educated guess of other user’s home directories.

In msg390535, Eryk Sun supplied an improved ntpath implementation that makes use of winreg and ctypes.

In msg391970, Steve Dower pointed out that, if retrieving another user’s home directory on Windows is unlikely to be made reliable, we should look at deprecating this functionality in expanduser()

From a bit of googling, Python seems to be an outlier in having a function to retrieve another user’s home directory. I am encouraged by Eryk’s patch, but a little out of my depth with Windows stuff.

Any views on this? Is expanduser(‘~other’) fixable and worth fixing? If not, should we deprecate this functionality? Or something else?

Barney

Senthil Kumaran

unread,
Apr 28, 2021, 12:54:37 PM4/28/21
to Barney Gale, python-dev
On Wed, Apr 28, 2021 at 05:44:06PM +0100, Barney Gale wrote:
> From a bit of googling, Python seems to be an outlier in having a function to
> retrieve another user’s home directory.

> Any views on this? Is expanduser(‘~other’) fixable and worth fixing? If not,
> should we deprecate this functionality? Or something else?

+1 to deprecate this functionality. This does not seem to be common usecase to
be present in stdlib, and reliablity across platform seems difficult.

--
Senthil

_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/CGVRT4A7XUOEVWHZY3ZX32CABD7OKR2A/
Code of Conduct: http://python.org/psf/codeofconduct/

Guido van Rossum

unread,
Apr 28, 2021, 1:06:23 PM4/28/21
to Senthil Kumaran, Barney Gale, python-dev
On UNIX-oid platforms (e.g. BSD, Linux, Mac), ~user/ should be reasonably reliable, after all the shell does it. On Windows, only ~/ can be relied upon -- the rest is "best effort". I'd be okay with deprecating ~user/ on Windows, but on UNIX-oid it should not be deprecated IMO.

(Spoken as an old UNIX nerd who's currently using Windows 10.)
--
--Guido van Rossum (python.org/~guido)

Antoine Pitrou

unread,
Apr 28, 2021, 1:53:17 PM4/28/21
to pytho...@python.org
On Wed, 28 Apr 2021 10:05:32 -0700
Guido van Rossum <gu...@python.org> wrote:
> On UNIX-oid platforms (e.g. BSD, Linux, Mac), ~user/ should be reasonably
> reliable, after all the shell does it. On Windows, only ~/ can be relied
> upon -- the rest is "best effort". I'd be okay with deprecating ~user/ on
> Windows, but on UNIX-oid it should not be deprecated IMO.
>
> (Spoken as an old UNIX nerd who's currently using Windows 10.)

Agreed with Guido.

Best regards

Antoine.


>
> On Wed, Apr 28, 2021 at 9:57 AM Senthil Kumaran <sen...@uthcode.com> wrote:
>
> > On Wed, Apr 28, 2021 at 05:44:06PM +0100, Barney Gale wrote:
> > > From a bit of googling, Python seems to be an outlier in having a
> > function to
> > > retrieve another user’s home directory.
> >
> > > Any views on this? Is expanduser(‘~other’) fixable and worth fixing? If
> > not,
> > > should we deprecate this functionality? Or something else?
> >
> > +1 to deprecate this functionality. This does not seem to be common
> > usecase to
> > be present in stdlib, and reliablity across platform seems difficult.
> >
> > --
> > Senthil
> >
> > _______________________________________________
> > Python-Dev mailing list -- pytho...@python.org
> > To unsubscribe send an email to python-d...@python.org
> > https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
> > https://mail.python.org/archives/list/pytho...@python.org/message/CGVRT4A7XUOEVWHZY3ZX32CABD7OKR2A/
> > Code of Conduct: http://python.org/psf/codeofconduct/
> >
>
>



_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/CVPSAHX2XJDX27I2PSASOTQF4MD6PX22/

Terry Reedy

unread,
Apr 28, 2021, 6:07:23 PM4/28/21
to pytho...@python.org
On 4/28/2021 1:05 PM, Guido van Rossum wrote:
> On UNIX-oid platforms (e.g. BSD, Linux, Mac), ~user/ should be
> reasonably reliable, after all the shell does it. On Windows, only ~/
> can be relied upon -- the rest is "best effort". I'd be okay with
> deprecating ~user/ on Windows, but on UNIX-oid it should not be
> deprecated IMO.
On all systems, IDLE uses expanduser('~') and expanduser(path). On Mac,
it uses
expanduser('~/Library/Preferences/.GlobalPreferences.plist'). So I
presume deprecating ~something only on Windows should not affect IDLE.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/ZWXDZ23TUXFRB4WFTCC6LRVK36CJO4XR/
Reply all
Reply to author
Forward
0 new messages