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

No error is thrown in list.pop(idx) when the index is out of range #854

Open
chopin opened this issue Jun 7, 2023 · 1 comment
Open

Comments

@chopin
Copy link

chopin commented Jun 7, 2023

Index error is thrown correctly in list[idx]. But, not in list.pop(idx). In Python, pop() also can have an index as an argument. Following is test code I tried:

def test_keycheck(idx):
    print('in test_keycheck(), idx=', idx)
    #__pragma__ ('keycheck') # to catch IndexError
    stack= []
    try:
        content = stack.pop(idx)
    except IndexError as e:
        print('Caught IndexError')
        raise e
    except KeyError as e:
        print('Caught KeyError')
        raise e
    except Error as e:
        print('Caught Error')
        raise e
    print('content= ', content)
    #__pragma__ ('nokeycheck')
def main():
    test_keycheck(-1)
    test_keycheck(0)
    test_keycheck(1)
if __name__ == '__main__':
    main()

result:

in test_keycheck(), idx= -1
content=  None
in test_keycheck(), idx= 0
content=  None
n test_keycheck(), idx= 1
content=  None

IndexError is thrown in CPython.

Thanks

@JennaSys
Copy link
Collaborator

Will be fixed in v3.9.4

JennaSys added a commit that referenced this issue Jul 28, 2024
Added more autotests for list.pop and list.remove
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants