~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_py.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-13 18:00:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4755.
  • Revision ID: john@arbash-meinel.com-20091013180016-y9ciypkm8lor58fx
Implement StaticTuple.from_sequence()

This allows casting from something that *might* be a StaticTuple
into something that is definitely a StaticTuple, without having to
create a new instance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    def intern(self):
52
52
        return _interned_tuples.setdefault(self, self)
53
53
 
 
54
    @staticmethod
 
55
    def from_sequence(seq):
 
56
        """Convert a sequence object into a StaticTuple instance."""
 
57
        if isinstance(seq, StaticTuple):
 
58
            # it already is
 
59
            return seq
 
60
        return StaticTuple(*seq)
 
61
 
 
62
 
54
63
 
55
64
# Have to set it to None first, so that __new__ can determine whether
56
65
# the _empty_tuple singleton has been created yet or not.