Patchwork formatter: ditch namedtuple in favor of attr

login
register
mail settings
Submitter Yuya Nishihara
Date May 6, 2018, 2:54 a.m.
Message ID <bebe0c7559fa5015d636.1525575286@mimosa>
Download mbox | patch
Permalink /patch/31276/
State Accepted
Headers show

Comments

Yuya Nishihara - May 6, 2018, 2:54 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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
Gregory Szorc - May 6, 2018, 4:19 a.m.
On Sat, May 5, 2018 at 7:54 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@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')
> +@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@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

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')
+@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'