Skip to content

Refactor arithmetic_analysis/newton_raphson to not use eval #8863

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

Closed
CaedenPH opened this issue Jul 11, 2023 · 2 comments · Fixed by #10824
Closed

Refactor arithmetic_analysis/newton_raphson to not use eval #8863

CaedenPH opened this issue Jul 11, 2023 · 2 comments · Fixed by #10824
Labels
awaiting triage Awaiting triage from a maintainer

Comments

@CaedenPH
Copy link
Contributor

What would you like to share?

https://github.com/TheAlgorithms/Python/blob/master/arithmetic_analysis/newton_raphson.py#L28
The newton raphson function uses eval, which is flagged by ruff here
https://github.com/TheAlgorithms/Python/actions/runs/5515973175/jobs/10056851168?pr=8861

Additional information

Error: arithmetic_analysis/newton_raphson.py:28:3[5](https://github.com/TheAlgorithms/Python/actions/runs/5515973175/jobs/10056851168?pr=8861#step:4:6): S307 Use of possibly insecure function; consider using `ast.literal_eval`
Error: arithmetic_analysis/newton_raphson.py:28:57: S307 Use of possibly insecure function; consider using `ast.literal_eval`
Error: arithmetic_analysis/newton_raphson.py:30:1[6](https://github.com/TheAlgorithms/Python/actions/runs/5515973175/jobs/10056851168?pr=8861#step:4:7): S307 Use of possibly insecure function; consider using `ast.literal_eval
@CaedenPH CaedenPH added the awaiting triage Awaiting triage from a maintainer label Jul 11, 2023
@rohan472000
Copy link
Contributor

I tried using ast.literal_eval() but getting error, as all doctest failed

      ValueError: malformed node or string on line 1: <ast.Call object at 0x00000240A44AC280>

after some search I came to know that the ast.literal_eval function is designed to evaluate Python literals or valid Python expressions, but it cannot directly handle mathematical functions or expressions involving variables like x.

look into PR #8867 .

@cclauss
Copy link
Member

cclauss commented Oct 15, 2023

CONTRIBUTING.md says:

Do not create an issue to contribute an algorithm. Please submit a pull request instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting triage Awaiting triage from a maintainer
Projects
None yet
3 participants