Expose file size, mode, etc from `pathlib.Path.info`

  1. I am not sure it going to be obvious that Path.info is cached by design to many users. This will have to be documented in bold and then underlined 100 times.
  2. It’s adding a bit of entropy. There’s now p.is_dir() and p.info.is_dir() amongst other methods.
  3. Python is so terse, I’m not sure that s = p.stat() was really a big deal. It’s explicit and obvious. Was Path.stat(cache=True) considered?
  4. Internally, pathlib needs to be careful when it’s calling .info. Methods like copy and copy_info/from need to be clear why they are using a cached values.
  5. The “sugar” layer of taking the output of os.stat() and translating it to more digestible form/types (e.g., Datetime, Permissions, Mode) is a stellar addition.
  6. Currently, if you want the sugar-ized output of os.stat, but not the caching, you’re out of luck? I suspect people will start using Path.info for the sugar but not realizing it’s cached.
  7. For the case of follow_symlinks=False, don’t you have to repeatedly call p.info.exists(follow_symlinks=False); p.info.is_dir(follow_symlinks=False)? This isn’t particularly ergonomic?

It’s a bit too late, but I would have advocated for something that is more symmetric with info and stat and that is not cached by default.

  1. Path.stat(follow_symlinks=True, cache=False) to enable caching of stat call
  2. Path.info(follow_symlinks=True, cache=False) with info having a sugar-ized stat output as well as is_dir() and friends that that can be optionally cached.
4 Likes