Ergonomics of new pathlib.Path.scandir()

Following feedback in another thread, I’m increasingly worried I’ve made a mistake by exposing this as an attribute that caches by default, rather than a method that returns a cached object only when requested. e.g. we could instead have def metadata(self, *, cached=False). Petr tried to warn me but I got hung up on the follow_symlinks details.

It will be pretty flipping awkward, but we could still switch to a metadata() method in 3.15 and soft-deprecate info, if people thought that was desirable.

I still think the method must not include a follow_symlinks arguments for the reasons I gave earlier. It probably shouldn’t perform filesystem access either - that’s a job for Info methods like path.metadata().is_dir().

4 Likes