Eric Osborne <e...@notcom.com> added the comment: I have pushed out new diffs.
* moved __format__ to _BaseAddress, where it should have been in the first place * redid format parser as regexp, as it was getting awfully complicated * added support for 'X' * added support for 's' by falling through to regular format() * added IPv6 to the test suite This was a decent-sized change, but all the tests pass so it looks OK to me. As per request, I defer importing re and compiling the necessary regexp until it's absolutely necessary. This is significantly slower than importing re and compiling the regexp when ipaddress is imported. localized compile and import In [4]: %timeit f'{a:#_b}' 7.05 µs ± 34.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) toplevel compile and import In [2]: %timeit f'{a:#_b}' 5.34 µs ± 17 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) Is this worth trying to get clever about? It doesn't matter in my use case, and I could make a reasonable argument either way. I'm tempted to leave it localized, as I can't imagine a case where formatting eleventy billion IP addresses as padded binary is all that time-sensitive. On the other hand, I'm also not sure how Pythonic it is to stick an import statement 20 lines deep in a dunder method, so I'm open to suggestions. eric ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32820> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com