-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Automatic formatting for Album & Item #1269
Conversation
Cut the need to format manually (and often incorrectly) when logging by implementing the __format__ magic method (see PEP 3101) on LibModel (the parent class of Album & Item). Based on a discussion in PR beetbox#1262
Code now relies on `format()` for items and albums displaying/logging. `ui.print_()` calls `unicode()` or `str()` on the strings so for most usages calling `ui.print_(obj)` replaces `ui.print_(obj, lib, None)`. Where there is a special format `ui.print_(format(obj, fmt))` is fine, but when `fmt` can be None then one has to call `ui.print_(ui.format_(obj, fmt))` -- which is what `ui.print_obj` now does.
if not spec: | ||
spec = beets.config[self._format_config_key].get(unicode) | ||
result = self.evaluate_template(spec) | ||
if isinstance(spec, bytes): |
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.
Is this necessary? I would have guessed that evaluate_template
would always return a Unicode—is that incorrect?
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.
Ah, I get it—you're supporting formatting with both bytes and Unicode templates. Sorry for being slow. Perhaps a comment to this effect would make it clearer?
Looks great. This simplifies a lot of logging and listing statements, which is awesome to have. I have a few comments inline. I conceptually like making |
Modulo these last two tiny behavioral tweaks (do we need |
Delete `ui.format_` and then `ui.print_obj`. Simply ensure that when there is no format it defaults to '' = default format = config option.
Since this raises problems the best is probably to maintain the base behaviour: expect byte strings or unicodes.
Since |
Awesome. I'll merge this now & write a changelog entry. |
Automatic formatting for Album & Item
Cut the need to format manually (and often incorrectly) when logging by implementing the
__format__
magic method.In
beets.ui
,_pick_format
print_obj
print_
format_
(likeformat
but the format spec can beNone
)Next steps are:
-p
(path) and-f
(format) top-level options that can be used in all situations (future PR, raises option name conflicts problems)list_format_{item,album}
toformat_{item,album}
? (can be this PR, + we should keep the current names for retro-compatibility in any case)This started by a discussion on PR #1262.