GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-21861: Improve _io.FileIO.__repr__ by beezz · Pull Request #14774 · python/cpython Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dc62f03 to
0a02fcb
Compare
|
What about other |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
8109726 to
47ed9a3
Compare
|
@serhiy-storchaka Thanks for your comment. I added remaining classes from the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (self->fd < 0) | ||
| return PyUnicode_FromFormat("<_io.FileIO [closed]>"); | ||
| return PyUnicode_FromFormat( | ||
| "<%s [closed]>", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would it be good to have a test for different cases? Something like below in test_fileio.py to ensure C and Python implementations behave the same.
def test_custom_repr(self): class CustomFileIO(self.FileIO): pass custom_file_io = CustomFileIO(TESTFN, 'w') custom_file_io.close() self.assertIn("CustomFileIO", repr(custom_file_io))
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR definitely needs tests such as the one proposed here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@taleinat @tirkarthi thanks for comments. I added some tests as suggested.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@beezz, thanks for this PR! Please link your user on bugs.python.org to your GitHub user so that our CLA bot can recognize that you've signed our CLA. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@beezz, please address the review comments. Thank you! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
47ed9a3 to
bd9440e
Compare
bd9440e to
3b80300
Compare
Instead of hardcoding the class name in the __repr__ string, resolve the actuall one which makes the __repr__ more subclass friendly.
3b80300 to
996fb04
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I think this is almost ready to go.
I have just one significant request regarding the tests (see inline comment).
Also a couple of minor style suggestions and some nitpicking about the NEWS entry, but those aren't critical.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| class SubTextIOWrapper(self.TextIOWrapper): | ||
| pass | ||
|
|
||
| clsname = 'SubTextIOWrapper' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it would be simpler and clearer to just hard-code the class name in the strings below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| custom_file_io = CustomFileIO(TESTFN, 'w') | ||
|
|
||
| self.assertIn( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This check is overly specific: it is testing the implementation's details (the specific formatting, including the order of the values) rather than the intent (that certain values are included).
I suggest something like:
r = repr(custom_file_io) self.assertIn(clsname, r) self.assertIn(custom_file_io.name, r) self.assertIn(custom_file_io.mode, r) self.assertIn("closefd=True", r)
This is also true for the similar assertion below, and for those in the TextIOWrapper test as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,2 @@ | |||
| Remove the hardcoded classes names from ``_io`` module classes' ``__repr__`` in | |||
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think that simply mentioning FileIO and TextIOWrapper would be clearer than "_io module classes'.
Also I think phrasing this positively would be better, but this is a matter of style:
Use the object's actual class name in :meth:`_io.FileIO.__repr__` and :meth:`_io.TextIOWrapper.__repr__`, to make these methods subclass friendly.
(For more info about the inline markup used above, see the devguide.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Also, @beezz, please avoid rebasing and force-pushing branches which already have an open PR. It is much better, for various reasons, to simply merge the base branch into the PR branch and push the merged branch (this doesn't require force pushing, which is a good sign!). We always squash PR branches before merging them, so the end result is the same either way. For more details on the recommended PR workflow, see this section of devguide. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Superseded by #30824 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.