-
Notifications
You must be signed in to change notification settings - Fork 52
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
Models must have a __format__
method
#1789
Comments
Python has an elaborate format spec mini-language, so we shouldn't be adding arbitrary keywords like this. Safer to start with just the standard |
The mini language suggests
The problem is that SMS template strings will now have that number 30 appearing everywhere, instead of reading it once from
|
Argument against using format_spec: i18n strings introduce a risk of translator error. We are less likely to have a typo in translating |
The base classes got default |
We have constructs like this in various places:
_("Something related to {entity}").format(entity=entity.title)
This is error prone because we may accidentally pass the object instead of the attribute, requiring careful audit. This can be avoided if the model implements
__format__
that reflexively returnsself.title
, or something else as per the format spec.Bonus: This will also make TemplateVarMixin for SMS templates obsolete, as the template can instead use something like
"{project:sms} has an update: {project:shorturl}"
and the__format__
method can return a truncated title or short URL based on the format spec.The text was updated successfully, but these errors were encountered: