Comments (5)
I guess this is another example, trying to evaluate something like {**a, **b}
:
>>> names = dict(a=dict(x=1, y=2), b=dict(z=3))
>>> EvalWithCompoundTypes(names=names).eval('{**a, **b}')
Traceback (most recent call last):
File "/Users/psurry/Downloads/simpleeval.py", line 395, in _eval
handler = self.nodes[type(node)]
KeyError: <class 'NoneType'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/psurry/Downloads/simpleeval.py", line 616, in eval
return super(EvalWithCompoundTypes, self).eval(expr)
File "/Users/psurry/Downloads/simpleeval.py", line 389, in eval
return self._eval(ast.parse(expr.strip()).body[0])
File "/Users/psurry/Downloads/simpleeval.py", line 401, in _eval
return handler(node)
File "/Users/psurry/Downloads/simpleeval.py", line 404, in _eval_expr
return self._eval(node.value)
File "/Users/psurry/Downloads/simpleeval.py", line 401, in _eval
return handler(node)
File "/Users/psurry/Downloads/simpleeval.py", line 619, in _eval_dict
return {self._eval(k): self._eval(v) for (k, v) in zip(node.keys, node.values)}
File "/Users/psurry/Downloads/simpleeval.py", line 619, in <dictcomp>
return {self._eval(k): self._eval(v) for (k, v) in zip(node.keys, node.values)}
File "/Users/psurry/Downloads/simpleeval.py", line 398, in _eval
"Sorry, {0} is not available in this " "evaluator".format(type(node).__name__)
simpleeval.FeatureNotAvailable: Sorry, NoneType is not available in this evaluator
>>>
from simpleeval.
I used a workaround by evaluating something like this dict(list(a.items()) + list(b.items()))
. Looking at the AST parse:
>>> ast.dump(ast.parse('{**a}'))
"Module(body=[Expr(value=Dict(keys=[None], values=[Name(id='a', ctx=Load())]))])"
I guess it's not handling the keys=[None]
piece? Adding an explicit key doesn't help:
>>> ast.dump(ast.parse('{"a": 1, **a}'))
"Module(body=[Expr(value=Dict(keys=[Str(s='a'), None], values=[Num(n=1), Name(id='a', ctx=Load())]))])"
>>>
I guess this would be fixed by either tweaking _eval_dict
to handle injection of a dictionary in v when k was None? See the ast docs where it explains: "When doing dictionary unpacking using dictionary literals the expression to be expanded goes in the values list, with a None at the corresponding position in keys."
Perhaps this is a different bug that the originally reported one?
from simpleeval.
This would be really cool to add
from simpleeval.
+1 for this feature request. DictComp is really a missing thing for this cool library.
@Reskov could you prepare a PR? As I see in the previous comment @danthedeckie is ready to accept it (please correct me if I'm wrong)
from simpleeval.
@amyasnikov Not sure. Personally, I am not interested in this anymore. 😞 And there was already PR #62.
from simpleeval.
Related Issues (20)
- Setuptools 58 breaks install HOT 1
- Possible to return function object rather than evaluate? HOT 2
- Possible to generate RPN from AST. HOT 1
- Low performance HOT 9
- We need to revisit performance limits
- We should switch to explicitly giving permission for methods / data access HOT 2
- while shortcode seems endless loop HOT 1
- Add a timeout for statements
- intercept evaluation of simpleeval and add if conditions
- MAX_STRING_LENGTH used on objects which do not increase size, creating false positives
- `and` operator bug HOT 1
- Escaping the sandbox through generators HOT 1
- Is this project still alive?
- Possible to define my own operators HOT 1
- Problem when building using simpleeval HOT 4
- Operator with arguments?? HOT 1
- Failing install with latest setuptools (fails due to `use_2to3` no longer supported) HOT 19
- simpleeval raises NameNotDefined exception when KeyError exception occured using callable names resolver HOT 4
- Any plans for a new release? HOT 1
- how do i set limits HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleeval.