-
Notifications
You must be signed in to change notification settings - Fork 4
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
Provide 'how to upgrade' instructions, please? #5
Comments
Easiest workaround is just to lock evalidate version to any before 2.0.0 (which I published just few hours ago), e.g. v1.1.0 has evalidate function. But better to upgrade it: #!/usr/bin/env python3
import evalidate
VALID_MATH_EXPRESSION_NODES = ['Call', 'Mult']
MATHEMATICAL_FUNCTIONS = ['int']
def pi():
return 3.14
model = evalidate.base_eval_model.clone()
model.nodes.extend(VALID_MATH_EXPRESSION_NODES)
model.allowed_functions.extend(MATHEMATICAL_FUNCTIONS)
model.imported_functions = dict(pi=pi)
def prepare(math):
expr = evalidate.Expr(math, model=model)
return expr.code
code = prepare('int(a) * 3 + pi() + 100')
# 139.14
print(eval(code, None, dict(a=12.34))) |
Thank you! That was enough to figure it out, though I did have to change 'expr.code' to 'expr.node' to match the previous functionality. For future explorers: math_node = evalidate.evalidate(math,
addnodes=VALID_MATH_EXPRESSION_NODES,
funcs=MATHEMATICAL_FUNCTIONS.keys()) becomes: model = evalidate.base_eval_model.clone()
model.nodes.extend(VALID_MATH_EXPRESSION_NODES)
model.allowed_functions.extend(MATHEMATICAL_FUNCTIONS.keys())
math_node = evalidate.Expr(math, model=model).node If something like this could be added to the docs (for this and other functionality), I think that would help anyone else in the same boat. |
Attribute |
It's possible the downstream code could also be changed, but since 'evalidate' retuned a node, that's what the code expects--using 'code' gave me an error it took some time to track down. This is not time-sensitive code; the time it takes me as a programmer to update stuff is far far longer than the time spent executing it. |
I'm trying to maintain legacy code, which literally just broke because evalidate.evalidate is now gone. I don't know the code nearly well enough to tell how to update it; some sort of 'if you did X, do Y now' instructions would be fantastic.
Specifically, the code in question looks like:
Any hints appreciated!
The text was updated successfully, but these errors were encountered: