D868: changelog: use attrs instead of namedtuple

sid0 (Siddharth Agarwal) phabricator at mercurial-scm.org
Sun Oct 1 10:36:04 UTC 2017


sid0 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  See http://www.attrs.org/en/stable/why.html#namedtuples for why attrs are
  better than namedtuples.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D868

AFFECTED FILES
  mercurial/changelog.py

CHANGE DETAILS

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -15,6 +15,9 @@
     hex,
     nullid,
 )
+from .thirdparty import (
+    attr,
+)
 
 from . import (
     encoding,
@@ -142,10 +145,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'))
+ at 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 +171,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__.



To: sid0, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list