TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.85k stars 214 forks source link

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

Open chopin opened 1 year ago

chopin commented 1 year ago

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 commented 2 months ago

Will be fixed in v3.9.4