__getslice__ incorrectness

Juergen A. Erhard jae at ilk.de
Wed Dec 1 18:20:11 EST 1999


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The implementation of the __getslice__ method is obvious incorrect.
The language reference states:

     Called to implement evaluation of self[i:j]. The returned object
     should be of the same type as self. Note that missing i or j in
     the slice expression are replaced by zero or sys.maxint,
     respectively, and no further transformations on the indices is
     performed. The interpretation of negative indices and indices
     larger than the length of the sequence is up to the method.

But when I do

  class X:
      def __getslice__(self, a, b):
          return (a,b)

  x=X()
  x[:-1]

an AttributeError: __len__ is raised.  Hmm...  So I add a

   def __len__(self):
       return 10

and now

  x[:-1]

returns (0, 9).  But it should return (0, -1), according to the quoted
passage.  ("[...] The interpretation of negative indices [...] is up
to the method.")

Will this be fixed (it's a lot better the way it's documented than the
way it's implemented ;-)

Bye, J

- -- 
Jürgen A. Erhard      eMail: jae at ilk.de      phone: (GERMANY) 0721 27326
              My WebHome: http://Juergen_Erhard.tripod.com
               GTK - Free X Toolkit (http://www.gtk.org)
             pros do it for money -- amateurs out of love.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.5 and Gnu Privacy Guard <http://www.gnupg.org/>

iEYEARECAAYFAjhFrSkACgkQN0B+CS56qs2bbQCghl9VnCH197zp7dT0sxjnBpLo
YfUAoJ5cYUS01alpjzO50PBmorGt4P9a
=VAJK
-----END PGP SIGNATURE-----




More information about the Python-list mailing list