Opened 8 years ago
Last modified 8 years ago
#28810 closed Cleanup/optimization
Use the Python 3-esque str.format logging formatting style over '%' — at Version 2
| Reported by: | Chris Lamb | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Other) | Version: | 1.11 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
We currently use the %(foo)s style in Django and in docs. This "smells" quite Python 2.x when there is a str.format variety that uses, eg. {foo}.
Change History (2)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
| Description: | modified (diff) |
|---|
I'm not sure why you say "Python 3-esque str.format" in the description. str.format() was added in Python 2.6. I see that logging support for that style (by using style='{') was added in Python 3.2.
I'm not opposed to the change, as it seems like a slight readability enhancement, although generally I think there's a consensus against using mandating str.format() usage everwhere in Django and prohibiting the %s syntax. I think there was a ticket but I can't find it at the moment.
My only concern with the proposal is whether it could break backwards compatibility. I see an update to ServerFormatter.uses_server_time() was required. I'm not sure if it's likely that user code may make similar assumptions about the format string.
PR https://github.com/django/django/pull/9359