list.pop() in a list with 'undefined' returned from a function raises IndexError

Open
#901 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, python
Domain
compilers

Research direction

Start by running the supplied reproducer with Transcrypt 3.9.4 and compare its generated JavaScript behavior with Python's bare return semantics. Check the list.pop() path and the handling of undefined values; done means the example prints the list and removes the first element without raising IndexError.

Written by the indexing model from the issue text.

Description

IS: bug?

Hi,

I encountered an error in list.pop() in Transcrypt3.9.4. It had no problem in previous versions. When a list contains an element 'undefined' returned from a function, list.pop() raises IndexError. The return command with no argument returns None in Python. But, 'undefined' is returned in Transcrypt3.9.4.

test code:

sMsg= "list.pop() in a list with 'undefined' returned from a function raises IndexError in Transcrypt3.9.4"
def x():
    return  # Python returns None, but Transcrypt3.9.4 returns 'undefined'
def main():
    print('\n'+sMsg)
    l= [x(), x(), x()]
    print(l)
    print(l.pop(0))

if __name__ == '__main__':
    main()

output:

list.pop() in a list with 'undefined' returned from a function raises IndexError in Transcrypt3.9.4
msgWhileLoading.js:64 [None, None, None]
localhost/:1 Uncaught Function {__args__: Array(1), stack: 'Error\n    at Array.py_pop (https://localhost:8443/…/compiled.DEBUG/main_frontend.js:6:2', __class__: ƒ}

The exception can be caught by try... except IndexError.

Thanks.

Dominant language
Python
Stars
2.9k
Forks
218
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TranscryptOrg/Transcrypt

All issues in TranscryptOrg/Transcrypt

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.