Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice obj with no start index is 0 instead of None sometimes #44636

Closed
jyzude mannequin opened this issue Feb 28, 2007 · 4 comments
Closed

slice obj with no start index is 0 instead of None sometimes #44636

jyzude mannequin opened this issue Feb 28, 2007 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@jyzude
Copy link
Mannequin

jyzude mannequin commented Feb 28, 2007

BPO 1671137
Nosy @rhettinger
Files
  • slicebug.py: Slice bug (with formatting preserved)
  • 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 2007-04-03.07:56:00.000>
    created_at = <Date 2007-02-28.18:58:39.000>
    labels = ['interpreter-core']
    title = 'slice obj with no start index is 0 instead of None sometimes'
    updated_at = <Date 2007-04-03.07:56:00.000>
    user = 'https://bugs.python.org/jyzude'

    bugs.python.org fields:

    activity = <Date 2007-04-03.07:56:00.000>
    actor = 'jyzude'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2007-02-28.18:58:39.000>
    creator = 'jyzude'
    dependencies = []
    files = ['2307']
    hgrepos = []
    issue_num = 1671137
    keywords = []
    message_count = 4.0
    messages = ['31385', '31386', '31387', '31388']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'jyzude']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1671137'
    versions = ['Python 2.6']

    @jyzude
    Copy link
    Mannequin Author

    jyzude mannequin commented Feb 28, 2007

    Slice objects returned by the slice ":42" return different slice objects depending on whether the entire slice operation is simple or extended. This bit of code explains it best:

    class SliceBug:
        def __getitem__(self, sliceArg):
            print sliceArg
    
    s = SliceBug()

    s[:42]
    s[:42,]

    s[:42] produces slice(0, 42, None)
    s[:42,] produces (slice(None, 42, None),)

    Note that this bug only occurs on classes that do no inherit from object ("old style" classes). If you change the class to make it inherit from "object" both slices have None as their start index. Oddly enough in Python 3000 it still only happens on "old style" classes even though supposedly they are the same as new style classes. I have also reproduced the bug in Python 2.6, 2.4, 2.3, and 2.2. Seems to be a long standing bug/feature.

    @jyzude jyzude mannequin closed this as completed Feb 28, 2007
    @jyzude jyzude mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Feb 28, 2007
    @jyzude
    Copy link
    Mannequin Author

    jyzude mannequin commented Feb 28, 2007

    Correction! This is fixed in Python 3000. I just have too many windows open and too many branches checked out.
    File Added: slicebug.py

    @rhettinger
    Copy link
    Contributor

    Fixing this small inconsistency has very little upside but runs the risk of breaking code that has been running fine for years. I think we should punt. If you agree, please close this bug report.

    @jyzude
    Copy link
    Mannequin Author

    jyzude mannequin commented Apr 3, 2007

    I concur. I'll close the bug.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant