This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients christian.heimes, eric.smith, ewosborne, ncoghlan, serhiy.storchaka
Date 2018-02-13.14:45:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1518533126.13.0.467229070634.issue32820@psf.upfronthosting.co.za>
In-reply-to
Content
If you don't recognize the format string, you want to fall back to:

return super().__format__(fmt)

Since that will call object.__format__, it will generate an error if fmt is not the empty string, which is what it does currently for IP addresses.

As far as parsing the format specifier, you're on your own. _pydecimal.py has a version that parses something very similar (or maybe identical) to the mini-language used by float, int, str, etc. But I'm not sure you need to go that far. Since you can define any format spec you'd like, you're not constrained to the mini-language used by the built-in types (see datetime for an example, which just calls strftime). I think the _pydecimal.py approach of using a regex isn't bad, but you might want to delay loading re until __format__ is called.

Before you go too far down this path, I think this should probably be taken to python-ideas to hash out what the format spec for IP addresses would look like, or even if this is a good idea at all. I'm generally supportive of handling it through __format__().
History
Date User Action Args
2018-02-13 14:45:26eric.smithsetrecipients: + eric.smith, ncoghlan, christian.heimes, serhiy.storchaka, ewosborne
2018-02-13 14:45:26eric.smithsetmessageid: <1518533126.13.0.467229070634.issue32820@psf.upfronthosting.co.za>
2018-02-13 14:45:26eric.smithlinkissue32820 messages
2018-02-13 14:45:26eric.smithcreate