[Python-ideas] Add a `dir_fd` parameter to `os.truncate`?

Steven D'Aprano steve at pearwood.info
Thu Apr 25 04:20:52 EDT 2019

On Fri, Apr 19, 2019 at 09:49:54PM +0200, Sebastian M. Ernst wrote:
> Hi everyone,
> many methods in `os` have a `dir_fd` parameter, for instance `unlink` [1]:
> ```python
> os.unlink(path, *, dir_fd=None)
> ```
> The `dir_fd` parameter [2] allows it to describe paths relative to
> directory descriptors. Otherwise, relative paths are relative to the
> current working directory.
> The implementation of `truncate` in `os` does not have this parameter [3]:
> ```python
> os.truncate(path, length)
> ```

> Why not add a convenience function or wrapper like above to the `os`
> module, which closes this gap and is more consistent with other methods?

I haven't seen any responses to your proposal, perhaps I missed 

The os module is supposed to be a thin wrapper around the os 
functionality, but your wrapper seems thin enough that I think it could 
and should just go into the os.truncate function itself, rather than 
adding a new function.


More information about the Python-ideas mailing list