Sorry, you also need this: calibre.utils.formatter_functions.py.
And no, the second version isn't suboptimal. The issue for me is that the behavior can seem "magic", but sometimes that is what one wants.
EDIT: Removed attachment now that the files are in the official calibre source.