MCPcopy Create free account
hub / github.com/ipython/traitlets / _safe_literal_eval

Function _safe_literal_eval

traitlets/traitlets.py:182–192  ·  view source on GitHub ↗

Safely evaluate an expression Returns original string if eval fails. Use only where types are ambiguous.

(s: str)

Source from the content-addressed store, hash-verified

180
181
182def _safe_literal_eval(s: str) -> t.Any:
183 """Safely evaluate an expression
184
185 Returns original string if eval fails.
186
187 Use only where types are ambiguous.
188 """
189 try:
190 return literal_eval(s)
191 except (NameError, SyntaxError, ValueError):
192 return s
193
194
195def is_trait(t: t.Any) -> bool:

Callers 3

from_stringMethod · 0.85
from_stringMethod · 0.85
from_stringMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…