-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
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 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! |
I signed the CLA earlier today. |
Lib/test/test_ipaddress.py
Outdated
("#_x" ,"0x0000_0000_0000_0000_0000_0000_0102_0304"), | ||
] | ||
for (fmt, txt) in pairs: | ||
res = format(addr, fmt) |
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.
Missing an assertion here?
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.
Fixed - remove the whole 'res = ...' line. Cut and paste leftover.
The whole line
res = format(addr, fmt)
just shouldn't be there. I'll check in a fix tomorrow.
eric
…On Wed, Feb 14, 2018 at 6:44 PM Jon Parise ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Lib/test/test_ipaddress.py
<#5627 (comment)>:
> + ,"0b000000000000000000000000000000000"
+ "000000000000000000000000000000000"
+ "000000000000000000000000000000000"
+ "00001000000100000001100000100"),
+ ("#n" ,"0x00000000000000000000000001020304"),
+ ("#x" ,"0x00000000000000000000000001020304"),
+ ("#_b"
+ ,"0b0000_0000_0000_0000_0000_0000_0000_0000_"
+ "0000_0000_0000_0000_0000_0000_0000_0000_"
+ "0000_0000_0000_0000_0000_0000_0000_0000_"
+ "0000_0001_0000_0010_0000_0011_0000_0100"),
+ ("#_n" ,"0x0000_0000_0000_0000_0000_0000_0102_0304"),
+ ("#_x" ,"0x0000_0000_0000_0000_0000_0000_0102_0304"),
+ ]
+ for (fmt, txt) in pairs:
+ res = format(addr, fmt)
Missing an assertion here?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5627 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMbq2HkKRnqCww1ua5MQFEiB-Zfp0U3Pks5tU2_fgaJpZM4SBbQ_>
.
|
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.
__format__
should error with ValueError("Invalid format specifier")
if it receives an invalid format string like {:abcden}
Going through some changes on the discussion list, I'll address this
comment when I take care of those.
eric
|
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.
These comments are mostly style issues, but a couple of code suggestions as well. Mostly looks good, though.
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 And if you don't make the requested changes, you will be put in the comfy chair! |
I have made the requested changes; please review again |
Thanks for making the requested changes! @zware: please review the changes made to this pull request. |
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.
This looks good to me!
(And then I see another whitespace nit :). Will merge after CI is happy again.)
@zware: Please replace |
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! |
* 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
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