changelog: use attrs instead of namedtuple
authorSiddharth Agarwal <sid0@fb.com>
Sun, 01 Oct 2017 03:24:20 -0700
changeset 34399 e51c8ffa1ffa
parent 34398 765eb17a7eb8
child 34400 200eadbcf0b0
changelog: use attrs instead of namedtuple See http://www.attrs.org/en/stable/why.html#namedtuples for why attrs are better than namedtuples. Differential Revision: https://phab.mercurial-scm.org/D868
mercurial/changelog.py
--- a/mercurial/changelog.py	Sun Oct 01 04:14:16 2017 -0700
+++ b/mercurial/changelog.py	Sun Oct 01 03:24:20 2017 -0700
@@ -7,14 +7,15 @@
 
 from __future__ import absolute_import
 
-import collections
-
 from .i18n import _
 from .node import (
     bin,
     hex,
     nullid,
 )
+from .thirdparty import (
+    attr,
+)
 
 from . import (
     encoding,
@@ -142,10 +143,16 @@
         return appender(opener, name, mode, buf)
     return _delay
 
-_changelogrevision = collections.namedtuple(u'changelogrevision',
-                                            (u'manifest', u'user', u'date',
-                                             u'files', u'description',
-                                             u'extra'))
+@attr.s
+class _changelogrevision(object):
+    # Extensions might modify _defaultextra, so let the constructor below pass
+    # it in
+    extra = attr.ib()
+    manifest = attr.ib(default=nullid)
+    user = attr.ib(default='')
+    date = attr.ib(default=(0, 0))
+    files = attr.ib(default=[])
+    description = attr.ib(default='')
 
 class changelogrevision(object):
     """Holds results of a parsed changelog revision.
@@ -162,14 +169,7 @@
 
     def __new__(cls, text):
         if not text:
-            return _changelogrevision(
-                manifest=nullid,
-                user='',
-                date=(0, 0),
-                files=[],
-                description='',
-                extra=_defaultextra,
-            )
+            return _changelogrevision(extra=_defaultextra)
 
         self = super(changelogrevision, cls).__new__(cls)
         # We could return here and implement the following as an __init__.