
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Safe evaluation of strings as math expressions
Install Python 3.6 or newer.
Install
# or PyPI
pip install math_eval
Use in situations where you need safe evaluation of strings as math expressions
>>> from math_eval import compute, safe_compute
>>> fun = safe_compute("x*y")
>>> fun('a', 3)
Traceback (most recent call last):
...
ValueError: Functions produced by compute() with safe = True do not accept non-numeric arguments.
>>> fun(3.4, 3)
10.2
>>> fun2 = compute("str(z) + x*y")
>>> fun2('a', 3, 3.5)
'3.5aaa'
>>> print(fun2.__doc__)
str(z) + x*y
Args are positional-only in the order ['x', 'y', 'z'].
>>> compute("(3*4.5**2 >= 17) | 1/-5 == 3")
True
WARNING
safe_compute()
is not safe if arbitrary ufunctions are added, and compute()
is probably unsafe in countless ways I haven't thought of as it is.
For instance, if the chr
and eval
ufunctions were introduced, even safe_compute()
could be used to evaluate artibrary Python expressions by translating integers into strings, and evaluating those strings with the normal Python interpreter.
I (Mark J. Olson) am not knowledgeable about computer security, so think carefully about possible workarounds for safe_compute's safety features before deploying it in a safety-sensitive setting.
Be sure to read the [contribution guidelines]
(https://github.com/molsonkiko/math_eval/blob/main/CONTRIBUTING.md).
TODO: add something to show test coverage of code (Coverage URL does not exist)
FAQs
Tool for safe (or less safe) evaluation of strings as math expressions
We found that math-eval demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.