Why is __getslice__ still implemented?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Bronger

    #1

    Why is __getslice__ still implemented?

    Hallöchen!

    According to <http://docs.python.org/ref/sequence-methods.html>,
    __getslice__ is deprecated. At the moment, I derive an own class
    from unicode and want to implement my own slicing. I found that I
    have to override __getslice__ since __getitem__ isn't called when I
    have something like my_instance[a:b] in my code.

    According to
    <news:mailman.7 438.1102640455. 5135.python-list@python.org >, this may
    have efficiency reasons, however, I agree with
    news:1102645919 .114898.139820@ f14g2000cwb.goo glegroups.com that this
    is quite confusing. It forces people to implement a deprecated
    function after all. I think the docs should say that you still have
    to override __getslice__ when subclassing from a built-in type,
    unless I really don't understand the issue correctly.

    Tschö,
    Torsten.

    --
    Torsten Bronger, aquisgrana, europa vetus
    Jabber ID: bronger@jabber. org
    (See http://ime.webhop.org for ICQ, MSN, etc.)
  • James Stroud

    #2
    Re: Why is __getslice__ still implemented?

    Torsten Bronger wrote:
    Hallöchen!
    >
    According to <http://docs.python.org/ref/sequence-methods.html>,
    __getslice__ is deprecated. At the moment, I derive an own class
    from unicode and want to implement my own slicing. I found that I
    have to override __getslice__ since __getitem__ isn't called when I
    have something like my_instance[a:b] in my code.
    >
    According to
    <news:mailman.7 438.1102640455. 5135.python-list@python.org >, this may
    have efficiency reasons, however, I agree with
    news:1102645919 .114898.139820@ f14g2000cwb.goo glegroups.com that this
    is quite confusing. It forces people to implement a deprecated
    function after all. I think the docs should say that you still have
    to override __getslice__ when subclassing from a built-in type,
    unless I really don't understand the issue correctly.
    >
    Tschö,
    Torsten.
    >
    Which version of python are you using?

    chernev 20% /sw/bin/python
    Python 2.5 (r25:51908, Oct 10 2006, 03:45:47)
    [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
    Type "help", "copyright" , "credits" or "license" for more information.
    pyclass Bob(object):
    .... def __getitem__(sel f, *args):
    .... print args
    ....
    pyb = Bob()
    pyb[4:21:2]
    (slice(4, 21, 2),)
    pyb[5:18:21,2:9:2,8 ,14:4]
    ((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)

    Comment

    • Torsten Bronger

      #3
      Re: Why is __getslice__ still implemented?

      Hallöchen!

      James Stroud writes:
      [...]
      >
      Which version of python are you using?
      2.4
      chernev 20% /sw/bin/python
      Python 2.5 (r25:51908, Oct 10 2006, 03:45:47)
      [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
      Type "help", "copyright" , "credits" or "license" for more information.
      pyclass Bob(object):
      This should be Bob(unicode).
      ... def __getitem__(sel f, *args):
      ... print args
      ...
      pyb = Bob()
      pyb[4:21:2]
      (slice(4, 21, 2),)
      pyb[5:18:21,2:9:2,8 ,14:4]
      ((slice(5, 18, 21), slice(2, 9, 2), 8, slice(14, 4, None)),)
      Tschö,
      Torsten.

      --
      Torsten Bronger, aquisgrana, europa vetus
      Jabber ID: bronger@jabber. org
      (See http://ime.webhop.org for ICQ, MSN, etc.)

      Comment

      • Steven Bethard

        #4
        Re: Why is __getslice__ still implemented?

        Torsten Bronger wrote:
        Hallöchen!
        >
        According to <http://docs.python.org/ref/sequence-methods.html>,
        __getslice__ is deprecated. At the moment, I derive an own class
        from unicode and want to implement my own slicing. I found that I
        have to override __getslice__ since __getitem__ isn't called when I
        have something like my_instance[a:b] in my code.
        >
        According to
        <news:mailman.7 438.1102640455. 5135.python-list@python.org >, this may
        have efficiency reasons, however, I agree with
        news:1102645919 .114898.139820@ f14g2000cwb.goo glegroups.com that this
        is quite confusing. It forces people to implement a deprecated
        function after all. I think the docs should say that you still have
        to override __getslice__ when subclassing from a built-in type,
        unless I really don't understand the issue correctly.
        Yes, you do still need to implement __getslice__ if you're subclassing
        a class (like unicode or list) which provides it. The __getslice__
        method can't be removed entirely for backwards compatibility reasons
        (though it is being removed in Python 3000). If you have a specific
        suggestion for what doc should be updated and how, that would be
        helpful. Please post it to:

        http://sourceforge.net/tracker/?grou...70&atid=105470

        (It doesn't need to be a real patch. Plain text is fine as long as you
        indicate where in the documentation it needs to go.)

        Steve

        Comment

        • Torsten Bronger

          #5
          Re: Why is __getslice__ still implemented?

          Hallöchen!

          Steven Bethard writes:
          Torsten Bronger wrote:
          >
          >[...]
          >>
          >[...] It forces people to implement a deprecated function after
          >all. I think the docs should say that you still have to override
          >__getslice__ when subclassing from a built-in type, unless I
          >really don't understand the issue correctly.
          >
          [...] If you have a specific suggestion for what doc should be
          updated and how, that would be helpful. Please post it to:
          >
          http://sourceforge.net/tracker/?grou...70&atid=105470
          Done.

          Tschö,
          Torsten.

          --
          Torsten Bronger, aquisgrana, europa vetus
          Jabber ID: bronger@jabber. org
          (See http://ime.webhop.org for ICQ, MSN, etc.)

          Comment

          • Steven Bethard

            #6
            Re: Why is __getslice__ still implemented?

            Torsten Bronger wrote:
            Hallöchen!
            >
            Steven Bethard writes:
            >
            >Torsten Bronger wrote:
            >>
            >>[...]
            >>>
            >>[...] It forces people to implement a deprecated function after
            >>all. I think the docs should say that you still have to override
            >>__getslice_ _ when subclassing from a built-in type, unless I
            >>really don't understand the issue correctly.
            >[...] If you have a specific suggestion for what doc should be
            >updated and how, that would be helpful. Please post it to:
            >>
            > http://sourceforge.net/tracker/?grou...70&atid=105470
            >
            Done.
            Thanks!

            STeVe

            Comment

            Working...