Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
bpo-26175: Fix SpooledTemporaryFile IOBase abstract#3249
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from2 commits
83d61523b69baa753b4fba70113efb28362bc9d0a9b588decab49dd14251b2119f4c084519b9c554aad6be094b3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -685,6 +685,9 @@ def __exit__(self, exc, value, tb): | ||
| def __iter__(self): | ||
| return self._file.__iter__() | ||
| def __del__(self): | ||
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. This shouldn't be added: deleting the SpooledTemporaryFile will null out the reference to the underline file, and therefor call its 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. I think if you inherit the default ContributorAuthor 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. I agree: the underlying file should not be explicitly deleted as this is not expected behaviour. I can imagine a situation where someone is deliberately holding a reference to the underlying file and they would not expect/want it to be closed until their own reference has fallen out of scope. I've changed the method to do nothing and added a docstring to reflect this. Thanks for your feedback 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 doc says: """This function operates exactly as TemporaryFile() does, except [irrelevant differences].""" And then, about TemporaryFile: """On completion of the context or destruction of the file object the temporary file will be removed from the filesystem.""" So it seems the underlying fileshould be deleted when the file object disappears. 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 point is that I think this implementation is correct. | ||
| return self._file.__del__() | ||
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. Hmm, calling the def__del__(self):ifnotself.closed:importwarningswarnings.warn('unclosed file %r'% (self,),ResourceWarning,stacklevel=2,source=self)self.close() (this is adapted from | ||
| def close(self): | ||
| self._file.close() | ||
| @@ -737,6 +740,12 @@ def newlines(self): | ||
| def read(self, *args): | ||
| return self._file.read(*args) | ||
| def readable(self): | ||
| return self._file.readable() | ||
| def readinto(self, b): | ||
| return self._file.readinto(b) | ||
| def readline(self, *args): | ||
| return self._file.readline(*args) | ||
| @@ -746,6 +755,9 @@ def readlines(self, *args): | ||
| def seek(self, *args): | ||
| self._file.seek(*args) | ||
| def seekable(self): | ||
| return self._file.seekable() | ||
| @property | ||
| def softspace(self): | ||
| return self._file.softspace | ||
| @@ -767,6 +779,9 @@ def write(self, s): | ||
| self._check(file) | ||
| return rv | ||
| def writable(self): | ||
| return self._file.writable() | ||
| def writelines(self, iterable): | ||
| file = self._file | ||
| rv = file.writelines(iterable) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -982,6 +982,35 @@ def test_basic(self): | ||
| f = self.do_create(max_size=100, pre="a", suf=".txt") | ||
| self.assertFalse(f._rolled) | ||
| def test_iobase_abstract(self): | ||
| # SpooledTemporaryFile should implement the IOBase abstract | ||
| iobase_abstract = ( | ||
| 'close', | ||
| 'closed', | ||
| 'fileno', | ||
| 'flush', | ||
| 'isatty', | ||
| 'read', | ||
| 'readable', | ||
| 'readinto', | ||
| 'readline', | ||
| 'readlines', | ||
| 'seek', | ||
| 'seekable', | ||
| 'tell', | ||
| 'truncate', | ||
| 'write', | ||
| 'writable', | ||
| 'writelines', | ||
| '__del__', | ||
| ) | ||
| f = self.do_create() | ||
| for attribute in iobase_abstract: | ||
| self.assertTrue( | ||
| hasattr(f, attribute), | ||
| '{} attribute missing'.format(attribute) | ||
| ) | ||
merwok marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| def test_del_on_close(self): | ||
| # A SpooledTemporaryFile is deleted when closed | ||
| dir = tempfile.mkdtemp() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fully implement `io.IOBase` abstract for `tempfile.SpooledTemporaryFile`. | ||
| Patch by Gary Fernie |