Skip to content

__getitem__() doesn't capture all slices if class inherits from list, tuple or str #47704

Closed

Description

@johnf
mannequin
BPO 3454
Nosy @amauryfa
Files
  • getitem_problem.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-07-27.21:17:57.817>
    created_at = <Date 2008-07-27.19:58:01.650>
    labels = ['interpreter-core', 'performance']
    title = "__getitem__() doesn't capture all slices if class inherits from list, tuple or str"
    updated_at = <Date 2008-07-27.21:17:57.775>
    user = 'https://bugs.python.org/johnf'

    bugs.python.org fields:

    activity = <Date 2008-07-27.21:17:57.775>
    actor = 'amaury.forgeotdarc'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-07-27.21:17:57.817>
    closer = 'amaury.forgeotdarc'
    components = ['Interpreter Core']
    creation = <Date 2008-07-27.19:58:01.650>
    creator = 'johnf'
    dependencies = []
    files = ['10992']
    hgrepos = []
    issue_num = 3454
    keywords = []
    message_count = 1.0
    messages = ['70329']
    nosy_count = 2.0
    nosy_names = ['amaury.forgeotdarc', 'johnf']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue3454'
    versions = ['Python 2.5']

    Activity

    1. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      performancePerformance or resource usage
      on Jul 27, 2008
    2. amauryfa commented on Jul 27, 2008

      @amauryfa
      Contributor

      When executing self[i:j], the __getslice__(self,i,j) method is called
      first, if it exists. See
      http://docs.python.org/ref/sequence-methods.html

      Yes, the __(get|set|del)slice__ methods are deprecated since 2.0, but
      for compatibility the built-in types must keep defining them. You may
      want to override them as well if your class inherit from such a type.

      With python 3.0 the __getslice__ slots were removed, and __getitem__ is
      called in all cases.

    3. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions