-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
bpo-8840: Improve docstrings for truncate() #6011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,10 +342,12 @@ def tell(self): | |
| return self.seek(0, 1) | ||
|
|
||
| def truncate(self, pos=None): | ||
| """Truncate file to size bytes. | ||
| """Resize stream to at most 'pos' bytes. | ||
|
|
||
| Size defaults to the current IO position as reported by tell(). Return | ||
| the new size. | ||
| 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| """ | ||
| self._unsupported("truncate") | ||
|
|
||
|
|
@@ -1670,10 +1672,12 @@ def tell(self): | |
| return os.lseek(self._fd, 0, SEEK_CUR) | ||
|
|
||
| def truncate(self, size=None): | ||
| """Truncate the file to at most size bytes. | ||
| """Resize stream to at most 'size' bytes. | ||
|
|
||
| Size defaults to the current file position, as returned by tell(). | ||
| The current file position is changed to the value of size. | ||
| 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. | ||
| """ | ||
| self._checkClosed() | ||
| self._checkWritable() | ||
|
|
@@ -1778,7 +1782,13 @@ def write(self, s): | |
| self._unsupported("write") | ||
|
|
||
| def truncate(self, pos=None): | ||
| """Truncate size to pos, where pos is an int.""" | ||
| """Resize stream to at most 'pos' characters. | ||
|
|
||
| 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. | ||
| """ | ||
| self._unsupported("truncate") | ||
|
|
||
| def readline(self): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).