[Django] #28810: Use the Python 3-esque str.format logging formatting style over '%'

53 views
Skip to first unread message

Django

unread,
Nov 17, 2017, 2:10:32 AM11/17/17
to django-...@googlegroups.com
#28810: Use the Python 3-esque str.format logging formatting style over '%'
------------------------------------------------+------------------------
Reporter: Chris Lamb | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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}``.

--
Ticket URL: <https://code.djangoproject.com/ticket/28810>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 17, 2017, 2:11:18 AM11/17/17
to django-...@googlegroups.com
#28810: Use the Python 3-esque str.format logging formatting style over '%'
-------------------------------------+-------------------------------------

Reporter: Chris Lamb | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Lamb):

PR https://github.com/django/django/pull/9359

--
Ticket URL: <https://code.djangoproject.com/ticket/28810#comment:1>

Django

unread,
Nov 17, 2017, 6:00:25 PM11/17/17
to django-...@googlegroups.com
#28810: Use the Python 3-esque str.format logging formatting style over '%'
-------------------------------------+-------------------------------------

Reporter: Chris Lamb | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> 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}``.

New description:

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}`.

--

Comment (by Tim Graham):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28810#comment:2>

Django

unread,
Nov 17, 2017, 6:45:26 PM11/17/17
to django-...@googlegroups.com
#28810: Use the Python 3-esque str.format logging formatting style over '%'
-------------------------------------+-------------------------------------

Reporter: Chris Lamb | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Lamb):

Replying to [comment:2 Tim Graham]:


> I'm not sure why you say "Python 3-esque str.format" in the description.
`str.format()` was added in Python 2.6.

I should have used a better suffix than "esque" — it's more that Python 3
code does tend to *prefer* `str.format` over `%`-style interpolation
simply as a correlation with it being more modern/newer in general. ie. if
it's "new enough" for Python 3, it's probably going to be using
newer/nicer features. It's therefore somewhat surprising to see the
reverse, hence this proposed change.

> there's a consensus against using mandating `str.format()` usage
everwhere in Django and prohibiting the `%s` syntax.

As it happens, I would be against such a total mandate and a widespread
change *within* Django, but this is more of a user-exposed thing so a
different, separate argument IMHO.

--
Ticket URL: <https://code.djangoproject.com/ticket/28810#comment:3>

Django

unread,
Nov 18, 2017, 7:12:59 PM11/18/17
to django-...@googlegroups.com
#28810: Use str.format()-style logging formatting instead of '%'
-------------------------------------+-------------------------------------

Reporter: Chris Lamb | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28810#comment:4>

Django

unread,
Nov 18, 2017, 7:15:30 PM11/18/17
to django-...@googlegroups.com
#28810: Use str.format()-style logging formatting instead of '%'
-------------------------------------+-------------------------------------
Reporter: Chris Lamb | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"3af305e8b8a89f4b0e5874cd601568ab8dcd7334" 3af305e8]:
{{{
#!CommitTicketReference repository=""
revision="3af305e8b8a89f4b0e5874cd601568ab8dcd7334"
Fixed #28810 -- Replaced '%' style logging formatting with str.format()
style.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28810#comment:5>

Reply all
Reply to author
Forward
0 new messages