On Sat, 2 Oct 2021 at 13:22, Aaron Stacy <aaron.r.st...@gmail.com> wrote:
>
> I’d like to propose an enhancement to the wonderful pathlib module: make Path 
> instances iterable, where the iterator returns subpaths.
>
> This would be functionally very similar to Path(some_directory).rglob(ā€˜*’).

... which is of course the major argument against this - it's already
very easy to do this, so adding *yet another* way of iterating over
the contents of a directory (we have Path.iterdir, Path.[r]glob,
os.walk, os.scandir, os.listdir, ...) is just making things even more
confusing.

The counter-argument is "there should be one obvious way" - we
definitely don't only have *one* way, at the moment, but none of them
are "obvious". My big problem is that I don't think that making Path
instances iterable is "obvious", either. What if the path is a file,
not a directory? Why are we doing a recursive traversal, not just
doing iterdir?

If you want an "obvious" (IMO - this is all very subjective, and I'm
not Dutch ;-)) approach, I'd argue that Path.iterdir(recursive=True)
would be a more reasonable place for this functionality. But I know
that Guido doesn't like functions that behave differently based on an
argument that is typically always supplied as a literal value, so
maybe my intuition isn't correct.

There's also a lot of design decisions around things like whether to
follow symlinks, how permission problems should be handled, etc.
Clearly we could just say that we do what rglob("*") does, but then
we're back to why we need something else that just does what
rglob("*") does...

I have some sympathy with the idea that rglob("*") isn't very
discoverable, and os.walk is over-complex, but I'm not convinced this
proposal is the right solution, either.

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

Reply via email to