-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
bpo-37376: pprint support for SimpleNamespace #14318
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-37376: pprint support for SimpleNamespace #14318
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general.
Only needed to document this change:
- Add the
versionchangeddirective in thepprintmodule documentation. - Add a news entry in
Misc/NEWS.d(useblurb). - Add an entry in the What's New document.
- Add your name in
Misc/ACKSif it is not there yet.
|
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 |
8ee8ca1 to
68ff595
Compare
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @serhiy-storchaka: please review the changes made to this pull request. |
Misc/NEWS.d/next/Library/2019-06-24-11-26-34.bpo-37376.SwSUQ4.rst
Outdated
Show resolved
Hide resolved
68ff595 to
2bd11f2
Compare
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @serhiy-storchaka: please review the changes made to this pull request. |
ericsnowcurrently
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Mostly LGTM. I've left a few comments.
Lib/test/test_pprint.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, code is almost always more readable when limited to one action per line. Among other things, it makes it much easier to understand what's happening (especially when parentheses are involved).
| self.assertEqual(pprint.pformat(types.SimpleNamespace()), "namespace()") | |
| formatted = pprint.pformat( | |
| types.SimpleNamespace()) | |
| self.assertEqual(formatted, "namespace()") |
Personally I like to separate the 3 parts (setup, actual-thing-to-test, assertions) with blank lines, for further readability, but that's more personal preference:
| self.assertEqual(pprint.pformat(types.SimpleNamespace()), "namespace()") | |
| ns = types.SimpleNamespace() | |
| formatted = pprint.pformat(ns) | |
| self.assertEqual(formatted, "namespace()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that adding an empty line after every line of code will make the code more readable. Empty lines should be used for separating logical sections of the code.
This code is consistent with the code in this file and looks clear to me. I do not think that any changes are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed most of @ericsnowcurrently's suggestions, but without the empty lines and without textwrap.dedent to be consistent with the rest of the file and I think it has made the test more clear.
Lib/test/test_pprint.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As before, I recommend one action per line.
| self.assertEqual(pprint.pformat(n, width=60), """\ | |
| formatted = pprint.pformat(ns, width=60) | |
| self.assertEqual(formatted, """\ |
...and separating the key sections of the test.
| self.assertEqual(pprint.pformat(n, width=60), """\ | |
| formatted = pprint.pformat(ns, width=60) | |
| self.assertEqual(formatted, """\ |
|
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 |
2bd11f2 to
7d3fbba
Compare
|
I have made the requested changes; please review again. @serhiy-storchaka I ended up removing the |
|
Thanks for making the requested changes! @ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for a SimpleNamespace subclass.
|
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 |
7d3fbba to
b701a7a
Compare
|
I have made the requested changes; please review again. @serhiy-storchaka ofc it was because of subclassing. Glad you're here to review! :D |
|
Thanks for making the requested changes! @ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Carl. LGTM, just fix an indentation in docs.
Doc/library/pprint.rst
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Added support for pretty-printing :class:`types.SimpleNamespace`. | |
| Added support for pretty-printing :class:`types.SimpleNamespace`. |
ericsnowcurrently
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working to resolve our various comments!
Other than one small thing, LGTM.
Lib/pprint.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this check is for the sake of subclasses then I'd recommend being explicit about it:
| if cls_name == "SimpleNamespace": | |
| if type(object) is _types.SimpleNamespace: |
|
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 |
a584309 to
49fa618
Compare
|
I have made the requested changes; please review again. @ericsnowcurrently I attempted to make it more clear what the class-name-if-statement is about. Thank you very much to the both of you for the fast, high quality responses. It was a good experience :-) |
|
Thanks for making the requested changes! @ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request. |
ericsnowcurrently
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm approving this, but also leaving one last comment. :) (feel free to ignore)
Thanks again for doing this.
Lib/pprint.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this. It's more clear now (as a reader).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And better. Checking the class by comparing the class name to a string is a bit wonky :D Thanks for pointing out, what I was actually doing.
Lib/pprint.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding a comment here. That helps. :) FWIW, the following might be more clear:
# The SimpleNamespace repr has "namespace" instead of the class name, so
# we do the same here. For subclasses we just use the class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried improving it, should be clear now
49fa618 to
8867ef7
Compare
https://bugs.python.org/issue37376