Skip to content
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

FIX: Replace unnecessary eval() calls with literal_eval() #1976

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion traitsui/qt4/check_list_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


import logging
from ast import literal_eval

from pyface.qt import QtCore, QtGui, is_pyside

Expand Down Expand Up @@ -266,7 +267,7 @@ def update_object(self, event=None):
"""Handles the user changing the contents of the edit control."""
try:
value = str(self.control.text())
value = eval(value)
value = literal_eval(value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about this one because I don't have much experience with the editor.

except:
pass
try:
Expand Down
6 changes: 4 additions & 2 deletions traitsui/qt4/extra/bounds_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# Thanks for using Enthought open source!

from ast import literal_eval

from pyface.qt import QtGui, QtCore

from traits.api import Float, Any, Str, Union
Expand Down Expand Up @@ -90,7 +92,7 @@ def init(self, parent):
def update_low_on_enter(self):
try:
try:
low = eval(str(self._label_lo.text()).strip())
low = literal_eval(str(self._label_lo.text()).strip())
if self.evaluate is not None:
low = self.evaluate(low)
except Exception as ex:
Expand All @@ -112,7 +114,7 @@ def update_low_on_enter(self):
def update_high_on_enter(self):
try:
try:
high = eval(str(self._label_hi.text()).strip())
high = literal_eval(str(self._label_hi.text()).strip())
if self.evaluate is not None:
high = self.evaluate(high)
except:
Expand Down
7 changes: 4 additions & 3 deletions traitsui/qt4/range_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""


from ast import literal_eval
from math import log10

from pyface.qt import QtCore, QtGui
Expand Down Expand Up @@ -187,7 +188,7 @@ def update_object_on_enter(self):
return

try:
value = eval(str(self.control.text.text()).strip())
value = literal_eval(str(self.control.text.text()).strip())
except Exception as ex:
# They entered something that didn't eval as a number, (e.g.,
# 'foo') pretend it didn't happen
Expand Down Expand Up @@ -460,7 +461,7 @@ def update_object_on_enter(self):
if self.control is None:
return
try:
self.value = eval(str(self.control.text.text()).strip())
self.value = literal_eval(str(self.control.text.text()).strip())
except TraitError as excp:
pass

Expand Down Expand Up @@ -727,7 +728,7 @@ def init(self, parent):
def update_object(self):
"""Handles the user entering input data in the edit control."""
try:
value = eval(str(self.control.text()))
value = literal_eval(str(self.control.text()))
if self.evaluate is not None:
value = self.evaluate(value)

Expand Down
3 changes: 2 additions & 1 deletion traitsui/wx/check_list_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import logging
from ast import literal_eval

import wx

Expand Down Expand Up @@ -240,7 +241,7 @@ def update_object(self, event):
"""Handles the user changing the contents of the edit control."""
try:
value = self.control.GetValue()
value = eval(value)
value = literal_eval(value)
except:
pass
try:
Expand Down
6 changes: 4 additions & 2 deletions traitsui/wx/extra/bounds_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# Thanks for using Enthought open source!

from ast import literal_eval

import wx

from traits.api import Float, Any, Str, Union
Expand Down Expand Up @@ -131,7 +133,7 @@ def update_low_on_enter(self, event):
event.Skip()
try:
try:
low = eval(str(self._label_lo.GetValue()).strip())
low = literal_eval(str(self._label_lo.GetValue()).strip())
if self.evaluate is not None:
low = self.evaluate(low)
except Exception as ex:
Expand All @@ -155,7 +157,7 @@ def update_high_on_enter(self, event):
event.Skip()
try:
try:
high = eval(str(self._label_hi.GetValue()).strip())
high = literal_eval(str(self._label_hi.GetValue()).strip())
if self.evaluate is not None:
high = self.evaluate(high)
except:
Expand Down