On Fri, Feb 11, 2022 at 12:28 AM Serhiy Storchaka <storch...@gmail.com>
wrote:

> expandvars() does not operate on paths, it operates on strings and
> bytestrings. There is nothing path-specific here. Expanding environment
> variables consists of three distinct steps:
>

sure -- but it does live in os.paths now, the docs talk about paths, and it
is useful for paths -- so it seems a fine idea to have that functionality
in pathlib.

Note that there are two implementations of expandvars(): in posixpath
> and ntpath. You may want to apply Posix substitution on Windows and
> Windows substitution on Linux or macOS, so it cannot be tied to
> PosixPath or WindowsPath.
>

I'm a bit confused here: in os.path it's tied to posixpath or ntpath, so
what is it any different to tie it to PosixPath or WindowsPath?

Also, IIUC, it expands environment variable from the current environment --
so expanding an environment variable from a non-native system seems pretty
esoteric.

Perhaps the shlex module would more appropriate place for expandvars()
> than os.path, but what done is done.
>

How about we add it to shlex for the more general (and esoteric) cases, and
also add it to pathlib for the path cases? Yes, having essentially the same
thing in three places is not-good, but pathlib already duplicated much of
os.path, that's exactly the point.

ANd while we are at it, it could take a flag indicating what style of
envvar expnasion to use: % or $ or both.

"The easy things should be easy"

If a user wants to expand an environment variable in a path, there should
be an easy and obvious way to do that.

NOTE: I don't think anyone is suggesting that os.path be deprecated -- but
I do think it's a worthy goal to be able to do be able to do everything you
need to do with pathlib without having to reach back into os.path --
needing both is kind the worst of both worlds.

-CHB


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J3WQVY63Y5NLKGRLNMJZYMV3G5LUKO3K/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to