Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

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

Open chopin opened this issue 2 years ago • 1 comments

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

chopin avatar Jun 07 '23 13:06 chopin

Will be fixed in v3.9.4

JennaSys avatar Jul 28 '24 22:07 JennaSys