Spit-balling: how about __filepath__ as a lazily-created-on-first-access pathlib.Path(__file__)?
Promoting os.path stuff to builtins just as pathlib is emerging as TOOWTDI makes me a bit uncomfortable. On Sun, May 6, 2018 at 8:29 PM, Nick Coghlan <ncogh...@gmail.com> wrote: > On 7 May 2018 at 12:35, Chris Angelico <ros...@gmail.com> wrote: >> >> On Mon, May 7, 2018 at 12:13 PM, Nick Coghlan <ncogh...@gmail.com> wrote: >> > So I have a different suggestion: perhaps it might make sense to propose >> > promoting a key handful of path manipulation operations to the status of >> > being builtins? >> > >> > Specifically, the ones I'd have in mind would be: >> > >> > - dirname (aka os.path.dirname) >> > - joinpath (aka os.path.join) >> >> These two are the basics of path manipulation. +1 for promoting to >> builtins, unless pathlib becomes core (which I suspect isn't >> happening). > > > pathlib has too many dependencies to ever make the type available as a > builtin: > > $ ./python -X importtime -c pass 2>&1 | wc -l > 25 > $ ./python -X importtime -c "import pathlib" 2>&1 | wc -l > 53 > > It's a good way of unifying otherwise scattered standard library APIs, but > it's overkill if all you want to do is to calculate and resolve some > relative paths. > >> >> > - abspath (aka os.path.abspath) >> >> Only +0.5 on this, as it has to do file system operations. It may be >> worthwhile, instead, to promote os.path.normpath, which (like the >> others) is purely processing the string form of the path. It'll return >> the same value regardless of the file system. > > > My rationale for suggesting abspath() over any of its component parts is > based on a few key considerations: > > - "make the given path absolute" is a far more common path manipulation > activitity than "normalise the given path" (most users wouldn't even know > what the latter means - the only reason *I* know what it means is because I > looked up the docs for abspath while writing my previous comment) > - __file__ isn't always absolute (especially in __main__), so you need to be > able to do abspath(__file__) in order to reliably apply dirname() more than > once > - it can stand in for both os.getcwd() (when applied to the empty string or > os.curdir) and os.path.normpath() (when the given path is already absolute), > so we get 3 new bits of builtin functionality for the price of one new > builtin name > - I don't want to read "normpath(joinpath(getcwd(), relpath))" when I could > be reading "abspath(relpath)" instead > > Cheers, > Nick. > > -- > Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia > > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Nathaniel J. Smith -- https://vorpus.org _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/