Skip to content
Snippets Groups Projects
Commit 9082c8c2 authored by Laurent Peuch's avatar Laurent Peuch Committed by GitHub
Browse files

Merge pull request #140 from duncf/master

Fix to_python() when strings are indented by stripping whitespace before evaluating.
parents 8fecf13c fa245696
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -137,7 +137,7 @@ class Path(object):
class LiteralyEvaluable(object):
def to_python(self):
try:
return ast.literal_eval(self.dumps())
return ast.literal_eval(self.dumps().strip())
except ValueError as e:
message = 'to_python method only works on numbers, strings, list, tuple, dict, boolean and None. (using ast.literal_eval). The piece of code that you are trying to convert contains an illegale value, for example, a variable.'
e.message = message
Loading
Loading
Loading
Loading
@@ -149,6 +149,11 @@ def test_to_python_name_node_None():
assert red[0].to_python() == None
 
 
def test_to_python_with_spacing():
red = RedBaron("{ 'pouet': d}")
assert red.find("string").to_python() == 'pouet'
def test_to_python_name_node_otherwise_raise():
red = RedBaron("foo")
try:
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment