Define __copy__ and __deepcopy__ as identity functions on DomainSpecificString, so that copy.deepcopy() will work on them

This commit is contained in:
Paul "LeoNerd" Evans 2014-08-20 15:25:17 +01:00
parent 9c0e570496
commit e01bdf2432
1 changed files with 8 additions and 0 deletions

View File

@ -38,6 +38,14 @@ class DomainSpecificString(
def __iter__(self):
raise ValueError("Attempted to iterate a %s" % (type(self).__name__))
# Because this class is a namedtuple of strings and booleans, it is deeply
# immutable.
def __copy__(self):
return self
def __deepcopy__(self, memo):
return self
@classmethod
def from_string(cls, s, hs):
"""Parse the string given by 's' into a structure object."""