Skip to content

bpo-32820: __format__ method for ipaddress #5627

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

Merged
merged 27 commits into from
Sep 12, 2019
Merged

bpo-32820: __format__ method for ipaddress #5627

merged 27 commits into from
Sep 12, 2019

Conversation

ewosborne
Copy link
Contributor

@ewosborne ewosborne commented Feb 11, 2018

This is my first time contributing anything on github. I've tried to RTFM and follow the instructions, but may well have mucked it up entirely.

This is a small patch to return the binary representation of an IPv4 or IPv6 address. I find this handy when I put together training material on subnetting and stuff like that. I wanted to implement index as part of this but issue 15559 disallows that. I debated over whether to include the '0b' but decided to leave it in to make it unambiguous, and I wasn't sure what to call it so I went with bits(). Could be bitstring(), padded_bitstring(), or anything else.

https://bugs.python.org/issue32820

@the-knights-who-say-ni
Copy link

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 our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@ewosborne
Copy link
Contributor Author

I signed the CLA earlier today.

@ewosborne ewosborne changed the title bpo-32820: bits method and test_bits bpo-32820: __format__ method for ipaddress Feb 13, 2018
("#_x" ,"0x0000_0000_0000_0000_0000_0000_0102_0304"),
]
for (fmt, txt) in pairs:
res = format(addr, fmt)
Copy link

Choose a reason for hiding this comment

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

Missing an assertion here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - remove the whole 'res = ...' line. Cut and paste leftover.

@ewosborne
Copy link
Contributor Author

ewosborne commented Feb 15, 2018 via email

Copy link
Contributor

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

__format__ should error with ValueError("Invalid format specifier") if it receives an invalid format string like {:abcden}

@ewosborne
Copy link
Contributor Author

ewosborne commented Feb 24, 2018 via email

Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

These comments are mostly style issues, but a couple of code suggestions as well. Mostly looks good, though.

@bedevere-bot
Copy link

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.

And if you don't make the requested changes, you will be put in the comfy chair!

@ewosborne
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@zware: please review the changes made to this pull request.

@csabella csabella requested a review from zware May 31, 2019 12:06
Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

This looks good to me!

(And then I see another whitespace nit :). Will merge after CI is happy again.)

@zware zware merged commit f9c95a4 into python:master Sep 12, 2019
@bedevere-bot
Copy link

@zware: Please replace # with GH- in the commit message next time. Thanks!

@zware
Copy link
Member

zware commented Sep 12, 2019

GitHub refused to merge this with the fixed commit message that I entered, then automatically merged with the default message when I clicked "Try again". Thank you, GitHub.

Either way, thanks for the patch, @ewosborne!

DinoV pushed a commit to DinoV/cpython that referenced this pull request Sep 12, 2019
* bits method and test_bits

* Cleaned up assert string

* blurb

* added docstring

* Faster method, per Eric Smith

* redoing as __format__

* added ipv6 method

* test cases and cleanup

* updated news

* cleanup and NEWS.d

* cleaned up old NEWS

* removed cut and paste leftover

* one more cleanup

* moved to regexp, moved away from v4- and v6-specific versions of __format__

* More cleanup, added ipv6 test cases

* more cleanup

* more cleanup

* cleanup

* cleanup

* cleanup per review, part 1

* addressed review comments around help string and regexp matching

* wrapped v6 test strings. contiguous integers: break at 72char. with underscores: break so that it looks clean.

*  's' and '' tests for pv4 and ipv6

* whitespace cleanup

* Remove trailing whitespace

* Remove more trailing whitespace

* Remove an excess blank line
@ewosborne ewosborne deleted the fix-issue-32820 branch July 30, 2020 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants