Repository: spyder-ide/spyder

Issue:
"Local variable 'reply' referenced before assignment" on debugger exit
## Description of your problem

**What steps will reproduce the problem?**
1.  a program im debugging runs to completion and exits normally
2. crash

**What is the expected output? What do you see instead?**

Internal console:

Traceback (most recent call last):
  File "C:\Users\Rob Buckley\Anaconda2\lib\site-packages\qtconsole\base_frontend_mixin.py", line 163, in _dispatch
    handler(msg)
  File "C:\Users\Rob Buckley\Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole\debugging.py", line 136, in _handle_stream
    self._input_reply = reply
UnboundLocalError: local variable 'reply' referenced before assignment

**Please provide any additional information below**
As  temporary hack i changed debugger.py line 136 
from 
self._input_reply = reply
to
self._input_reply = None
## Versions and main components
- Spyder Version: 3.0.0 (via conda)
- Python Version: 2.7.12
- Operating system: Windows 10
## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:

jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.11.1 (OK)
pandas >=0.13.1  :  0.18.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
pyflakes >=0.5.0 :  1.3.0 (OK)
pygments >=2.0   :  2.1.3 (OK)
pylint >=0.25    :  1.5.4 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4 (OK)
sphinx >=0.6.6   :  1.4.6 (OK)
sympy >=0.7.3    :  1.0 (OK)



Discussion:
Thanks for reporting. Could you post a simple program that generates this error?

hi - to WAR this issue i downgraded to 2.3.9. When i upgraded again i got into a mess with qt bindings so i ended up reinstalling a clean environment. Now i cant seem to reproduce the issue!

looking at _handle_stream() in Anaconda2\lib\site-packages\spyder\widgets\ipythonconsole\debugging.py, I cant see where reply gets assigned to before its referenced in line 136.  Maybe this is just a rarely used path?

sorry thats all i can offer. Feel free to close

Thanks. In any case, I'll check if `reply` can go unreferenced before closing :-)


Resolving patch:
diff --git a/spyder/widgets/ipythonconsole/control.py b/spyder/widgets/ipythonconsole/control.py
--- a/spyder/widgets/ipythonconsole/control.py
+++ b/spyder/widgets/ipythonconsole/control.py
@@ -55,7 +55,7 @@ def keyPressEvent(self, event):
         """Reimplement Qt Method - Basic keypress event handler"""
         event, text, key, ctrl, shift = restore_keyevent(event)
         if key == Qt.Key_ParenLeft and not self.has_selected_text() \
-          and self.help_enabled:
+          and self.help_enabled and not self.parent()._reading:
             self._key_paren_left(text)
         else:
             # Let the parent widget handle the key press event
diff --git a/spyder/widgets/ipythonconsole/debugging.py b/spyder/widgets/ipythonconsole/debugging.py
--- a/spyder/widgets/ipythonconsole/debugging.py
+++ b/spyder/widgets/ipythonconsole/debugging.py
@@ -133,7 +133,7 @@ def _handle_stream(self, msg):
                     self._input_reply = reply
                     self.sig_input_reply.emit()
                 else:
-                    self._input_reply = reply
+                    self._input_reply = None
                     self.sig_input_reply.emit()
             else:
                 self._input_reply = None


Test patch: