[PATCH] formatter: ditch namedtuple in favor of attr

Gregory Szorc gregory.szorc at gmail.com
Sun May 6 00:19:25 EDT 2018


On Sat, May 5, 2018 at 7:54 PM, Yuya Nishihara <yuya at tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1525327696 -32400
> #      Thu May 03 15:08:16 2018 +0900
> # Node ID bebe0c7559fa5015d636a73be9fba988911ff760
> # Parent  9ae8a72dec358d33c96725e1f94c631e869deb80
> formatter: ditch namedtuple in favor of attr
>

Queued. Many thanks for getting rid of namedtuple usage!


>
> diff --git a/mercurial/formatter.py b/mercurial/formatter.py
> --- a/mercurial/formatter.py
> +++ b/mercurial/formatter.py
> @@ -107,7 +107,6 @@ baz: foo, bar
>
>  from __future__ import absolute_import, print_function
>
> -import collections
>  import contextlib
>  import itertools
>  import os
> @@ -117,6 +116,9 @@ from .node import (
>      hex,
>      short,
>  )
> +from .thirdparty import (
> +    attr,
> +)
>
>  from . import (
>      error,
> @@ -413,8 +415,11 @@ class templateformatter(baseformatter):
>          baseformatter.end(self)
>          self._renderitem('docfooter', {})
>
> -templatespec = collections.namedtuple(r'templatespec',
> -                                      r'ref tmpl mapfile')
> + at attr.s(frozen=True)
> +class templatespec(object):
> +    ref = attr.ib()
> +    tmpl = attr.ib()
> +    mapfile = attr.ib()
>
>  def lookuptemplate(ui, topic, tmpl):
>      """Find the template matching the given -T/--template spec 'tmpl'
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180505/b473a6b0/attachment.html>


More information about the Mercurial-devel mailing list