On 21Oct2022 16:55, Stefan Ram <r...@zedat.fu-berlin.de> wrote:
Robert Latest <boblat...@yahoo.com> writes:
return super().format_field( value, format_string )
Why do you prefer super().format_field() over plain format()? The doc says:
"format_field() simply calls format()." So I figured I might do the same.

 I am not aware of any reason not to call "format" directly.

Stefan's code implements it's own format_field and falls back to the original format_field(). That's standard subclassing practice, and worth doing reflexively more of the time - it avoids _knowing_ that format_field() just calls format().

So I'd take Stefan's statement above to imply that calling format() directly should work.

My own habit would be to stick with the original, if only for semantic reasons. Supposing you switched from subclassing Formatter to some other class which itself subclasses Formatter. (Yes, that is probably something you will never do.) Bypassing the call to super().format_field(...) prevents shoehorning some custom format_fields from the changed superclass. Which you'd then need to debug.

That's all.

Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to