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 · 0 comments
Open

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

chopin opened this issue Jun 7, 2023 · 0 comments
Labels

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants