Merge pull request #6558 from gavento/patch-1

Make EncodedFile.write() return the return value from inner write()
This commit is contained in:
Daniel Hahler 2020-01-25 11:04:12 +01:00 committed by GitHub
commit 6f2943c7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 1 deletions

View File

@ -256,6 +256,7 @@ Tim Hoffmann
Tim Strazny
Tom Dalton
Tom Viner
Tomáš Gavenčiak
Tomer Keren
Trevor Bekolay
Tyler Goodlet

View File

@ -0,0 +1 @@
Make capture output streams ``.write()`` method return the same return value from original streams.

View File

@ -424,7 +424,7 @@ class EncodedFile:
raise TypeError(
"write() argument must be str, not {}".format(type(obj).__name__)
)
self.buffer.write(obj)
return self.buffer.write(obj)
def writelines(self, linelist):
data = "".join(linelist)

View File

@ -1492,3 +1492,8 @@ def test_typeerror_encodedfile_write(testdir):
result_with_capture.stdout.fnmatch_lines(
["E * TypeError: write() argument must be str, not bytes"]
)
def test_stderr_write_returns_len(capsys):
"""Write on Encoded files, namely captured stderr, should return number of characters written."""
assert sys.stderr.write("Foo") == 3