On Sun, 13 Feb 2022 at 03:15, Paul Moore <p.f.mo...@gmail.com> wrote:
>
> On Sat, 12 Feb 2022 at 16:02, Chris Angelico <ros...@gmail.com> wrote:
> >
> > On Sun, 13 Feb 2022 at 02:57, Eric V. Smith <e...@trueblade.com> wrote:
> > > See Paul’s example, copied above. Maybe the code isn’t expecting it.
> > >
> >
> > There wasn't an actual example, just a hypothetical one. I have never
> > once seen something in real usage where you interpolate environment
> > variables into a path, without expecting the environment variables to
> > be paths.
> >
> > It's different with URLs, but pathlib doesn't handle URLs, it handles paths.
>
> My example was not intended to illustrate that having slashes within
> variables wasn't reasonable, but rather that concatenating a string to
> a variable without an intervening slash *could* be confusing. But
> equally it might not be:
>
> backup = os.path.expandvars("${ORIGFILE}.bak")
>
> The point I was trying to make is that thinking of expandvars as
> acting on strings is straightforward, whereas thinking of the operands
> as paths can lead to expectations that might be wrong. I'm arguing
> that we should not link expandvars with paths, even though
> historically it's part of os.path.
>

That's fair, but I don't know of any situation where ORIGFILE would
come from an environment variable but be required to be a file name
without a path. For instance, if you have an env var saying "put the
backup over here", then it most certainly could be used the way you
describe, but then the normal expectation would be for it to allow a
full path.

Much more common, for the expansion you're describing, would be for
ORIGFILE to come from elsewhere in the code, so expandvars is
irrelevant.

ChrisA
_______________________________________________
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/LLZNFYWVBXV7PMFHH2BMJIHCJBANWAIH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to