On Thu, Aug 20, 2020 at 9:08 PM Ethan Furman <et...@stoneleaf.us> wrote:

> > But for a while is was painful to use, 'cause there was som much code
> > that still used strings for paths. That was made a lot better when we
> > introduced the __fspath__ protocol, and then updated the standard
> > library to use it (everywhere?).
>
> Unfortunately not [1].  The __fspath__ protocol is supported in
> locations where a path is expected as an argument (e.g. os.path.join());
> anywhere else it is not supported except by accident (meaning it could
> easily become actually unsupported in the future).
>

I guess this is why some folks though making PATH a subclass of str might
be a good idea in the first place.

So a new idea (very poorly thought out) -- make a StrPath that is both a
subclass of Path and a str -- so it could be used for things like __file__,
and code that expects a string will still work, and code that expects a
Path object will work as well. Since both Path and str are immutable, str
methods would return strings, and Path methods would return Path objects.

I haven't looked for name clashes yet, but does this seem possible?

-CHB


-- 
Christopher Barker, PhD

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

Reply via email to