[PATCH hglib] hglib: Eliminate named tuples for Python 2.4 and 2.5 compatibility

Jeff Laughlin jmlaughlin at integrated-informatics.com
Tue Nov 29 08:22:30 CST 2011


We could do something like this

class Revision(tuple):
    @property
    def rev(self):
        return self[0]

    @property
    def node(self):
        return self[1]

    @property
    def tags(self):
        return self[2]

    @property
    def branch(self):
        return self[3]

    @property
    def author(self):
        return self[4]

    @property
    def desc(self):
        return self[5]
    


-----Original Message-----
From: Matt Mackall [mailto:mpm at selenic.com] 
Sent: Monday, November 28, 2011 18:41
To: Jeff Laughlin
Cc: mercurial-devel at selenic.com; Jason Humber
Subject: Re: [PATCH hglib] hglib: Eliminate named tuples for Python 2.4 and 2.5 compatibility

On Mon, 2011-11-28 at 11:06 -0500, Jeff Laughlin wrote:
> # HG changeset patch
> # User Jeff Laughlin <jmlaughlin at integrated-informatics.com>
> # Date 1321987954 18000
> # Node ID 317a25e6c619ed59c94d583f96d3763ccc8b47e4
> # Parent  3bbf6a3266f44ce822b19b0a857dd3a3cea1d515
> hglib: Eliminate named tuples for Python 2.4 and 2.5 compatibility.
> 
> Named tuples were not introduced until Python 2.6. Since Mercurial 
> advertises compatibility backwards with Python 2.4, it seems as though 
> hglib ought to be compatible as well. This patch replaces usage of the 
> revision named tuple in client.py with a Revision class. It passes all tests.

This is a pretty decent start on a solution, but I think the resulting object also needs to be tuple-like (ie by subclassing tuple) for compatibility. That'll give you __cmp__ for free, btw.

--
Mathematics is the supreme nostalgia of our time.





More information about the Mercurial-devel mailing list