- # If the user asks for a slice, we'll be returning a list
- # of symbols.
- return [ self(idx) for idx in range(start, key.stop, step) ]
+ # This is the most common case so it would make sense to have
+ # this test first. But there are too many different "integer"
+ # classes that you have to check for.
+ return self._subscript_integer_(key)
+
+
+ def _subscript_integer_(self, n):
+ """
+ The subscript is a single integer, or something that acts like
+ one.
+ """
+ if n < 0:
+ # Cowardly refuse to create a variable named "a-1".
+ raise IndexError('Indices must be nonnegative')