PyCQA / redbaron

Bottom-up approach to refactoring in python
http://redbaron.pycqa.org/
694 stars 74 forks source link

redbaron.base_nodes.NodeList.insert() raises ValueError (on in_a_shell() is False) #121

Closed podhmo closed 7 years ago

podhmo commented 8 years ago

For Example.

# this is OK (because in_a_shell() returns True, so __str__() is called on __repr__())
$ python myscript.py
# but this is NG. (because in_a_shel() returns False)
$ python myscript.py > output.py

Actually, after changing such as below. some tests are failed.

diff --git a/redbaron/utils.py b/redbaron/utils.py
index 451675b..91c60b7 100644
--- a/redbaron/utils.py
+++ b/redbaron/utils.py
@@ -31,6 +31,7 @@ def log(string, *args):

 def in_a_shell():
+    return False
     # the isinstance here is for building sphinx doc
     if redbaron.DEBUG or isinstance(sys.stdout, StringIO):
         return True
$ py.test tests
# ... snip
======================================= 62 failed, 1346 passed in 42.57 seconds =======================================
podhmo commented 8 years ago

This is a sample script for reproducing a error.

https://gist.github.com/podhmo/d13d20a85f31127e81315eeed356e71d

$ pip freeze | grep redbaron
redbaron==0.6.1
# ValueError
$ python redbaron-error-on-insertion.py > /tmp/xxxx 
podhmo commented 8 years ago

this issue is fixed on current master?

$ pip freeze
-e git+git@github.com:PyCQA/redbaron.git@497a55f51a1902f67b30519c126469e60b4f569f#egg=redbaron
# ValueError is not raised.
$ python redbaron-error-on-insertion.py > /tmp/xxxx 
podhmo commented 8 years ago

Oh, I see, thanks to this commit, changing to ValueError is not raised, on redbaron.DEBUG = False

podhmo commented 8 years ago

(I wonder this issue's priority is low. ) (Because reproducing error in the case that redbaron.DEBUG = True and in_a_shell() returns False only.)

Psycojoker commented 8 years ago

Hello,

I wanted to merge @b5y PR before doing a release (this logging thing is cause troubles to several people) but I just don't find the time nor the energy to review his PR right now, so I'm going to do a quick bugfix release and I'll take a better look at this bug ... someday :/

Thanks for reporting!

podhmo commented 8 years ago

OK, thanks for replying. I'm looking forward to the next release.

Psycojoker commented 7 years ago

Next release is there (but this was also in the previous one iirc) https://pypi.python.org/pypi/redbaron/0.6.3