Fix contracts of `pathlib.Path` and `os` fs actions
Merged
JA
2mo ago+522+522+012345678901234567890123456789-114-114-012345678901234567890123456789
Fix filesystem call contracts for Path and os; fixes #993.
In detail:
- Add
Path.replace()and keywordtarget=support; bothPathmethods return the destinationPath, preserving relative spelling. os.rename()andos.replace()still returnNone.- Support
Path.unlink(missing_ok=True)andPath.stat(follow_symlinks=True)keyword arguments. - Validate
Path.mkdir()modes consistently withos.mkdir().
Side node: This adds dedicated effects RenamePath, ReplacePath, RenameOs and ReplaceOs. We arguably want to decouple effect-caller Path.rename -> RenamePath from each effect. E.g. here we would only need two effects, e.g. DropResult and IntoPath.
Summary by cubic
Fixes the filesystem call contracts for pathlib.Path and os to match CPython, addressing #993.
Path.rename()and the newPath.replace()return the destinationPath, preserving relative spelling;os.rename()andos.replace()still returnNone. Invalid targets raise the sameTypeErrorwording as theosfunctions.- Adds
target=keyword support,Path.unlink(missing_ok=True)(suppressesFileNotFoundErroronly when requested; other exceptions propagate), andPath.stat(follow_symlinks=True). Path.mkdir()now validatesmodeas a C integer likeos.mkdir()and accepts__index__objects.- Path method arity errors now count the bound receiver, matching CPython.