FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-37376: pprint support for SimpleNamespace by carlbordum · Pull Request #14318 · python/cpython · GitHub

Repository navigation

bpo-37376: pprint support for SimpleNamespace - #14318

Merged
miss-islington merged 1 commit into
python:masterfrom
carlbordum:pprint-simplenamespace
Jun 26, 2019
Merged

miss-islington merged 1 commit into
python:masterfrom
carlbordum:pprint-simplenamespace

Conversation

carlbordum commented Jun 23, 2019 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM in general.

Only needed to document this change:

  • Add the versionchanged directive in the pprint module documentation.
  • Add a news entry in Misc/NEWS.d (use blurb).
  • Add an entry in the What's New document.
  • Add your name in Misc/ACKS if it is not there yet.

Comment thread Lib/pprint.py Outdated

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

serhiy-storchaka added the type-feature A feature request or enhancement label Jun 23, 2019
carlbordum force-pushed the pprint-simplenamespace branch 2 times, most recently from 8ee8ca1 to 68ff595 Compare June 24, 2019 09:53

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

Copy link
Copy Markdown

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

Comment thread Doc/library/pprint.rst Outdated
Comment thread Misc/ACKS Outdated
carlbordum force-pushed the pprint-simplenamespace branch from 68ff595 to 2bd11f2 Compare June 24, 2019 14:56

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

Copy link
Copy Markdown

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

Comment thread Doc/library/pprint.rst Outdated
Comment thread Doc/library/pprint.rst Outdated

ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for working on this! Mostly LGTM. I've left a few comments.

Comment thread Lib/test/test_pprint.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Suggested change
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:

Suggested change
self.assertEqual(pprint.pformat(types.SimpleNamespace()), "namespace()")
ns = types.SimpleNamespace()
formatted = pprint.pformat(ns)
self.assertEqual(formatted, "namespace()")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread Lib/test/test_pprint.py Outdated
Comment thread Lib/test/test_pprint.py Outdated
Comment thread Lib/test/test_pprint.py Outdated
Comment thread Lib/test/test_pprint.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As before, I recommend one action per line.

Suggested change
self.assertEqual(pprint.pformat(n, width=60), """\
formatted = pprint.pformat(ns, width=60)
self.assertEqual(formatted, """\

...and separating the key sections of the test.

Suggested change
self.assertEqual(pprint.pformat(n, width=60), """\
formatted = pprint.pformat(ns, width=60)
self.assertEqual(formatted, """\

Comment thread Lib/pprint.py Outdated
Comment thread Lib/pprint.py Outdated
Comment thread Lib/pprint.py Outdated
Comment thread Lib/pprint.py Outdated
Comment thread Lib/pprint.py Outdated

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@serhiy-storchaka I ended up removing the write = stream.write optimization. If you do think it is worth it in this case, please let me know and I'll bring it back (properly this time, as pointed out by @ericsnowcurrently).

Copy link
Copy Markdown

Thanks for making the requested changes!

@ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Add a test for a SimpleNamespace subclass.

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

carlbordum force-pushed the pprint-simplenamespace branch from 7d3fbba to b701a7a Compare June 25, 2019 18:42

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@serhiy-storchaka ofc it was because of subclassing. Glad you're here to review! :D

Copy link
Copy Markdown

Thanks for making the requested changes!

@ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you Carl. LGTM, just fix an indentation in docs.

Comment thread Doc/library/pprint.rst Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Added support for pretty-printing :class:`types.SimpleNamespace`.
Added support for pretty-printing :class:`types.SimpleNamespace`.

ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for working to resolve our various comments!

Other than one small thing, LGTM.

Comment thread Lib/pprint.py Outdated

ericsnowcurrently Jun 25, 2019 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If this check is for the sake of subclasses then I'd recommend being explicit about it:

Suggested change
if cls_name == "SimpleNamespace":
if type(object) is _types.SimpleNamespace:

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

carlbordum force-pushed the pprint-simplenamespace branch 2 times, most recently from a584309 to 49fa618 Compare June 26, 2019 16:40

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown

Thanks for making the requested changes!

@ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request.

ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. I'm approving this, but also leaving one last comment. :) (feel free to ignore)

Thanks again for doing this.

Comment thread Lib/pprint.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for updating this. It's more clear now (as a reader).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread Lib/pprint.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Tried improving it, should be clear now

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL