bpo-22671: Clarify and test default read method implementations by CuriousLearner · Pull Request #4568 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation13 Commits2 Checks0 Files changed

Conversation

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

[ Show hidden characters]({{ revealButtonHref }})

CuriousLearner

@vstinner

This patch is by @vadmium . I take no credits for this.

In this case, you can specify the author when you do the Git commit. To modify the author of an existing author:

git commit --author='Martin Panter <vadmium+py@gmail.com>' --amend

@vstinner

I don't think that a NEWS entry is needed here: I added the "skip news" label.

@vadmium @CuriousLearner

@CuriousLearner

@vstinner I've updated the PR and marked @vadmium as the author for the commit. Let me know if there is any more help needed with this patch.

vstinner

Choose a reason for hiding this comment

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

The doc change LGTM, but I have requests on the newly added tests.

@@ -807,8 +807,8 @@ def test_multi_close(self):
self.assertRaises(ValueError, f.flush)
def test_RawIOBase_read(self):
# Exercise the default RawIOBase.read() implementation (which calls
# readinto() internally).
# Exercise the default limited RawIOBase.read() implementation (which

Choose a reason for hiding this comment

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

I dislike "limited", I would prefer to write read(n) for "limited", and read() for "unlimited".

)
for test in tests:
with self.subTest(test):
method, avail, request, result = test

Choose a reason for hiding this comment

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

Can you try to compute result from avail and request? result = min(avail, result, 5), no?

Choose a reason for hiding this comment

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

+1, we can do that. But I was thinking that expected_read_size when mentioned explicitly as it is done right now, would be better for future reference.

def test_BufferedIOBase_readinto(self):
# Exercise the default BufferedIOBase.readinto() and readinto1()
# implementations (which call read() or read1() internally).
class Reader(self.BufferedIOBase):

Choose a reason for hiding this comment

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

Can you add an init() method taking avail as a parameter?

Choose a reason for hiding this comment

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

Done

method, avail, request, result = test
reader = Reader()
reader.avail = bytes(range(avail))
buffer = bytearray((0x81,) * request)

Choose a reason for hiding this comment

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

Please use a constant instead of 0x81, like:

UNUSED_BYTE = 0x81

(define in this function, no need to declare it at the module scope.)

@CuriousLearner

@vstinner

Oh, GitHub merged the two commits into a single one and chose to use Sanyam Khurana as the author. Hopefully, I wrote both names in the commit message ;-) (I edited manually the commit message before merging.)

@miss-islington

Thanks @CuriousLearner for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Dec 11, 2017

@CuriousLearner @miss-islington

…onGH-4568)

Original patch written by Martin Panter, enhanced by Sanyam Khurana. (cherry picked from commit 1b74f9b)

@bedevere-bot

vstinner pushed a commit that referenced this pull request

Dec 11, 2017

@miss-islington @vstinner

) (#4796)

Original patch written by Martin Panter, enhanced by Sanyam Khurana. (cherry picked from commit 1b74f9b)