Is isinstance always "considered harmful"?

Jordan Rastrick jrastrick at student.usyd.edu.au
Mon May 16 11:13:08 EDT 2005


Leif K-Brooks wrote:

> Regardless of the various issues surrounding isinstance(), you have a
> difference in functionality. Since you're just storing a reference in
> the case of another LinkedList instead of copying it, mutating the
> LinkedList will be different from mutating another iterable type
which
> has been passed to extend:

Oops, didn't think of that. Good point.

> >>> linkedlist1 = LinkedList()
> >>> list1 = [1, 2, 3]
> >>> linkedlist2 = LinkedList([4, 5, 6])
> >>> linkedlist1.extend(list1)
> >>> linkedlist1.extend(linkedlist2)
> >>> linkedlist1
> LinkedList([1, 2, 3, 4, 5, 6])
> >>> list1.append(4)
> >>> linkedlist1 # Notice how there's still only one 4
> LinkedList([1, 2, 3, 4, 5, 6])
> >>> linkedlist2.append(7)
> >>> linkedlist1 # Notice how there's now a 7
> LinkedList([1, 2, 3, 4, 5, 6, 7])

Out of curiousity, is this code real? Where does the LinkedList() class
come from?




More information about the Python-list mailing list