Skip to content

bpo-32820: __format__ method for ipaddress#5627

Merged
zware merged 27 commits into
python:masterfrom
ewosborne:fix-issue-32820
Sep 12, 2019
Merged

bpo-32820: __format__ method for ipaddress#5627
zware merged 27 commits into
python:masterfrom
ewosborne:fix-issue-32820

Conversation

@ewosborne

@ewosborne ewosborne commented Feb 11, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown
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
Comment thread Lib/test/test_ipaddress.py Outdated
("#_x" ,"0x0000_0000_0000_0000_0000_0000_0102_0304"),
]
for (fmt, txt) in pairs:
res = format(addr, fmt)

Copy link
Copy Markdown

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
Copy Markdown
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

ewosborne commented Feb 15, 2018 via email

Copy link
Copy Markdown
Contributor Author

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Contributor

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

ewosborne commented Feb 24, 2018 via email

Copy link
Copy Markdown
Contributor Author

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

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

Comment thread Lib/ipaddress.py Outdated
Comment thread Lib/ipaddress.py Outdated
Comment thread Lib/test/test_ipaddress.py
Comment thread Lib/test/test_ipaddress.py Outdated
Comment thread Lib/test/test_ipaddress.py Outdated
Comment thread Lib/ipaddress.py Outdated
Comment thread Lib/ipaddress.py Outdated
Comment thread Lib/ipaddress.py Outdated
@bedevere-bot

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.

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

@ewosborne

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

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
Comment thread Lib/ipaddress.py Outdated

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

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
Copy Markdown

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

@zware

zware commented Sep 12, 2019

Copy link
Copy Markdown
Member

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