bpo-27300: Add missing error= argument to tempfile classes#6696
Conversation
|
Since the order of parameters doesn't match the order of corresponding parameters of |
|
That's a good idea, I changed |
| try: | ||
| return _io.open(fd, mode, buffering=buffering, | ||
| newline=newline, encoding=encoding) | ||
| newline=newline, encoding=encoding, errors=errors) |
| def errors(self): | ||
| try: | ||
| return self._file.errors | ||
| except AttributeError: |
There was a problem hiding this comment.
Accessing self._file.errors might raise AttributeError because in this class _file is initially a StringIO or BytesIO instance. The workaround with catching AttributeError is maybe not optimal, but that's the way it's done for the other file attributes (like encoding, mode, ...).
There was a problem hiding this comment.
Yes, but StringIO has the errors attribute, and in the case of BytesIO the exception will be reraised.
There was a problem hiding this comment.
I wasn't even aware that StringIO has this attribute :). It does indeed work the same without the try.
| @@ -0,0 +1,2 @@ | |||
| The file classes in *tempfile* now accept an *errors* parameter that | |||
| complements the already existing *encoding*. | |||
There was a problem hiding this comment.
Add "Patch by yourname."
|
The existing properties Should I create a separate PR for that? |
|
It is good if clean up that code in this PR. |
The classes for temporary files in
tempfilehave anencodingparameter to specify the file encoding. They don't have anerrorparameter to specify what should happen on encoding errors. This is unusual, normally things withencodingalso haveerrors.This pull request adds the missing
errorsparameter. It is treated the same as the already existingencodingparameter: the parameter is simply handed through to the underlyingioclass.https://bugs.python.org/issue27300