Skip to content
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

bpo-22671: Clarify and test default read method implementations #4568

Merged
merged 2 commits into from
Dec 11, 2017

Conversation

CuriousLearner
Copy link
Member

@CuriousLearner CuriousLearner commented Nov 26, 2017

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

I've applied it on the top of the master branch.

https://bugs.python.org/issue22671

@vstinner
Copy link
Member

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
Copy link
Member

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

@CuriousLearner
Copy link
Member Author

@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.

Copy link
Member

@vstinner vstinner left a comment

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
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

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?

Copy link
Member

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)
Copy link
Member

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.)

@vstinner vstinner merged commit 1b74f9b into python:master Dec 11, 2017
@vstinner
Copy link
Member

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
Copy link
Contributor

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
…onGH-4568)

Original patch written by Martin Panter, enhanced by Sanyam Khurana.
(cherry picked from commit 1b74f9b)
@bedevere-bot
Copy link

GH-4796 is a backport of this pull request to the 3.6 branch.

vstinner pushed a commit that referenced this pull request Dec 11, 2017
) (#4796)

Original patch written by Martin Panter, enhanced by Sanyam Khurana.
(cherry picked from commit 1b74f9b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants