I'm in a slightly tricky situation with a list subclass.
The list class I'm using has overridden __iter__
and __getitem__
in order to return something slightly different from what's actually stored internally (this is because this requires processing time which was wanted to be only done when the item is first directly accessed)
My issue comes up in the following use case. Let's say, for the use of this example, that the overridden methods turn the internal values into strings.
>>> myList = MyList([1, 2, 3])
>>> standardList = list(["a", "b", "c"])
>>>
>>> for item in myList:
>>> print item
"1"
"2"
"3"
>>> newList = standardList + myList
>>> for item in newList:
>>> print item
"a"
"b"
"c"
1
2
3
So what I'm after here is how the values are pulled from myList
when standardList + myList
is run, so that I can ensure that newList
has had the relevant modifications made.
Incidentally, I'm well aware that I could get this working if I overrode MyList.__add__
and then did myList + standardList
, but this is in a module that is used elsewhere, and I'd rather ensure that it works the right way in both directions.
Thanks