Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 15157e5

Browse filesBrowse files
committed
MNT: use less eval
In the textbox example we need eval because we are taking symbolic input from the user and then plotting it. I restricted the namespaces a bit to set a better example, but I think we fundamentally do need to use `eval` in this case. In the qt editor eval was changed to ast.literal_eval which only handles literals so is safer.
1 parent 370547e commit 15157e5
Copy full SHA for 15157e5

File tree

Expand file treeCollapse file tree

2 files changed

+4
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-2
lines changed

‎galleries/examples/widgets/textbox.py

Copy file name to clipboardExpand all lines: galleries/examples/widgets/textbox.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def submit(expression):
3232
*expression* is a string using "t" as its independent variable, e.g.
3333
"t ** 3".
3434
"""
35-
ydata = eval(expression)
35+
ydata = eval(expression, {'np': np}, {'t': t})
3636
l.set_ydata(ydata)
3737
ax.relim()
3838
ax.autoscale_view()

‎lib/matplotlib/backends/qt_editor/_formlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/_formlayout.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
__version__ = '1.0.10'
4242
__license__ = __doc__
4343

44+
from ast import literal_eval
45+
4446
import copy
4547
import datetime
4648
import logging
@@ -351,7 +353,7 @@ def get(self):
351353
else:
352354
value = date_.toPython()
353355
else:
354-
value = eval(str(field.text()))
356+
value = literal_eval(str(field.text()))
355357
valuelist.append(value)
356358
return valuelist
357359

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.