float() does not behave the same as CPython

Open Beginner friendly
#908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript, python
Domain
compilers

Research direction

Start at transcrypt/modules/org/transcrypt/builtin.js#L263, where the transcrypted float() implementation is identified, and compare its behavior with CPython for strings containing trailing non-numeric text and invalid values. Done means float() raises the expected ValueError instead of partially parsing input or returning NaN.

Written by the indexing model from the issue text.

Description

IS: bug

Right now the transcrypted float() uses JS parseFloat, but parseFoat allows for non-numeric values in the string it is partsing. It jsut stops parsing when it hits a non-numeric value instead of throwing NaN. CPython will instead raise a ValueError.

parseFloat("123.pdf")
123
float("123.pdf")
Traceback (most recent call last):
  File "/opt/pycharm/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
ValueError: could not convert string to float: '123.pdf'

Maybe use Number instead of parseFloat?

Update: float() is also returning NaN in some cases without throwing an error.

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.