Skip to content

bpo-8840: Improve docstrings for truncate()#6011

Closed
akuchling wants to merge 3 commits into
python:masterfrom
akuchling:issue8840
Closed

bpo-8840: Improve docstrings for truncate()#6011
akuchling wants to merge 3 commits into
python:masterfrom
akuchling:issue8840

Conversation

@akuchling
Copy link
Copy Markdown
Contributor

@akuchling akuchling commented Mar 7, 2018

A patch that updates the docstrings for various truncate() methods in the io module.

https://bugs.python.org/issue8840

Copy link
Copy Markdown
Contributor

@SylvainDe SylvainDe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, iI find truncate more explicit that re-size but I may be wrong on that.

Comment thread Lib/_pyio.py Outdated

def truncate(self, size=None):
"""Truncate the file to at most size bytes.
"""Resize stream to at most 'pos' bytes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be size, not pos.

@akuchling
Copy link
Copy Markdown
Contributor Author

Patch updated with suggested changes.

Comment thread Lib/_pyio.py
The position in the stream is left unchanged. The size
defaults to the current IO position as reported by tell(). If
the stream's size is increased, the contents of the new file
area are undetermined. Returns the new size.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents depend on the platform according to the main RST documentation.

IMO it is okay to leave out this level of detail from docstrings.

Comment thread Lib/_pyio.py

def truncate(self, pos=None):
"""Truncate file to size bytes.
"""Resize stream to at most 'pos' bytes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most truncate methods, I don’t think the “at most” wording should be added. It should also be okay to remove it from FileIO.truncate. These methods are supposed to either resize to exactly the specified size, or raise an exception.

The odd one out is be BytesIO.truncate, which currently does not expand the size (https://bugs.python.org/issue27261).

@csabella
Copy link
Copy Markdown
Contributor

@akuchling, any interest in trying to get this one wrapped up? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants