internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: spyder-ide/spyder

Issue:
Error when viewing bytes in the Variable Explorer
This was reported in StackOverflow:

https://stackoverflow.com/q/49775771/438386

----

In Spyder I can run the script without errors:

    filename = '$tmp$.tmp' 
    # create binary file with all bytes
    with open(filename, 'wb') as f:
        f.write(bytearray(list(range(255))))
    # read bytes back
    with open(filename, 'rb') as f:
        buffer=f.read()
    print(buffer)
But during debugging an exception is thrown after execute the line "buffer=f.read()"

    ...
     File "C:\Miniconda3\lib\site-packages\spyder\widgets\variableexplorer\utils.py", line 458, in value_to_display
        display = display[:70].rstrip()  + ' ...'
    
    TypeError: can't concat str to bytes

No error during debugging occurs with:

    buffer=bytearray(list(range(255)))
    print(buffer)


Discussion:

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/utils.py b/spyder/widgets/variableexplorer/utils.py
--- a/spyder/widgets/variableexplorer/utils.py
+++ b/spyder/widgets/variableexplorer/utils.py
@@ -455,7 +455,11 @@ def value_to_display(value, minmax=False, level=0):
     # Truncate display at 70 chars to avoid freezing Spyder
     # because of large displays
     if len(display) > 70:
-        display = display[:70].rstrip() + ' ...'
+        if is_binary_string(display):
+            ellipses = b' ...'
+        else:
+            ellipses = u' ...'
+        display = display[:70].rstrip() + ellipses
 
     # Restore Numpy threshold
     if np_threshold is not FakeObject:


Test patch:
diff --git a/spyder/widgets/variableexplorer/tests/test_utils.py b/spyder/widgets/variableexplorer/tests/test_utils.py
--- a/spyder/widgets/variableexplorer/tests/test_utils.py
+++ b/spyder/widgets/variableexplorer/tests/test_utils.py
@@ -222,5 +222,23 @@ def test_str_in_container_display():
         assert value_to_display([u'Э'.encode('cp1251')]) == "['\xdd']"
 
 
+def test_ellipses(tmpdir):
+    """
+    Test that we're adding a binary ellipses when value_to_display of
+    a collection is too long and binary.
+
+    For issue 6942
+    """
+    # Create binary file with all bytes
+    file = tmpdir.new(basename='bytes.txt')
+    file.write_binary(bytearray(list(range(255))))
+
+    # Read bytes back
+    buffer = file.read(mode='rb')
+
+    # Assert that there's a binary ellipses in the representation
+    assert b' ...' in value_to_display(buffer)
+
+
 if __name__ == "__main__":
     pytest.main()
Repository: spyder-ide/spyder

Issue:
Validate serialized length of modified objects in the Variable Explorer
This is causing huge memory leaks right now, so it's really critical for us to fix it.


Discussion:
Is this related or the same as the cause of the memory leaks when modifying objects discussed and confirmed in #5830 , but never fixed?
> but never fixed?

I asked @dalthviz to open these issues because the memory leaks are caused by several things, not a single one.

Besides, he's going to work on them in the next couple of weeks.
Okay, great! Glad to hear. So is some combination of these the underlying cause of #5830? Should it be closed as a duplicate, then?
It's not a duplicate. That issue made me realize all these problems, so leave it open for now. We'll see what to do about it later.

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/namespacebrowser.py b/spyder/widgets/variableexplorer/namespacebrowser.py
--- a/spyder/widgets/variableexplorer/namespacebrowser.py
+++ b/spyder/widgets/variableexplorer/namespacebrowser.py
@@ -45,6 +45,9 @@
 # To be able to get and set variables between Python 2 and 3
 PICKLE_PROTOCOL = 2
 
+# Maximum length of a serialized variable to be set in the kernel
+MAX_SERIALIZED_LENGHT = 1e6
+
 
 class NamespaceBrowser(QWidget):
     """Namespace browser (global variables explorer widget)"""
@@ -294,7 +297,16 @@ def set_value(self, name, value):
             # We need to enclose values in a list to be able to send
             # them to the kernel in Python 2
             svalue = [cloudpickle.dumps(value, protocol=PICKLE_PROTOCOL)]
-            self.shellwidget.set_value(name, svalue)
+
+            # Needed to prevent memory leaks. See issue 7158
+            if len(svalue) < MAX_SERIALIZED_LENGHT:
+                self.shellwidget.set_value(name, svalue)
+            else:
+                QMessageBox.warning(self, _("Warning"),
+                                    _("The object you are trying to modify is "
+                                      "too big to be sent back to the kernel. "
+                                      "Therefore, your modifications won't "
+                                      "take place."))
         except TypeError as e:
             QMessageBox.critical(self, _("Error"),
                                  "TypeError: %s" % to_text_string(e))


Test patch:
Repository: spyder-ide/spyder

Issue:
Stop button not working after second run on dedicated consoles
## Description
(More detailed description of the remaining bug from #5759)
The "Stop the current command" button in the IPython console can be made unavailable when running scripts. In these cases the button is grayed out.

**What steps will reproduce the problem?**

1. Run a long (or infinitively) running script in a new IPython console (e.g. using F5). 
2. Terminate the execution (So far I have only tested stopping either with the "Stop the current command" button or a caught KeyboardInterrupt)
3. Start the Script again (e.g. by pressing F5) which will run the script in the same IPython console created in 1

**What is the expected output? What do you see instead?**
I expect to have the "Stop the current command" available (i.e. clickable and not grayed out), however it is unavailable.

**Please provide any additional information below**

If I run it twice (i.e. pressing F5 again after the first time) the button becomes enabled and can be used to stop the script. However, even with the disabled button, the script is running correctly after the first time.


## Version and main components

* Spyder Version: 3.2.4 
* Python Version: 2.7.13
* Qt Versions: 5.6.2, PyQt5 5.6 on Linux

## Dependencies
```
pyflakes >=0.5.0  :  1.5.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  1.12.1 (OK)
sphinx >=0.6.6    :  1.5.6 (OK)
rope >=0.9.4      :  0.9.4 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
psutil >=0.3      :  5.2.2 (OK)
nbconvert >=4.0   :  5.1.1 (OK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  0.27.2 (OK)
qtconsole >=4.2.0 :  4.3.0 (OK)
IPython >=4.0;<6.0:  5.3.0 (OK)
pylint >=0.25     :  1.6.4 (OK)

```



Discussion:
Thanks @jpoeppel!
I see the 3.2.8 milestone, but just in case I confirm this bug.
* Spyder Version: 3.2.6 
* Python Version: 3.6.4
* Qt Versions: 5.10.1, PyQt5 5.10 on Linux

Resolving patch:
diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py
--- a/spyder/widgets/ipythonconsole/client.py
+++ b/spyder/widgets/ipythonconsole/client.py
@@ -250,7 +250,11 @@ def enable_stop_button(self):
         self.stop_button.setEnabled(True)
 
     def disable_stop_button(self):
-        self.stop_button.setDisabled(True)
+        # This avoids disabling automatically the button when
+        # re-running files on dedicated consoles.
+        # See issue #5958
+        if not self.shellwidget._executing:
+            self.stop_button.setDisabled(True)
 
     @Slot()
     def stop_button_click_handler(self):


Test patch:
Repository: spyder-ide/spyder

Issue:
Adding, removing, or moving a breakpoint while debugging changes the focus
## Description

**What steps will reproduce the problem?**

1. Debug
2. Press return in the text editor
3. Watch as the focus goes back to ipython


## Version and main components

* Spyder Version: 3.2.4.dev0 474e59379
* Python Version: 3.6.2
* Qt Versions: 5.9.1, PyQt5 5.9 on Darwin

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.1 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
psutil >=0.3     :  5.2.2 (OK)
nbconvert >=4.0  :  5.2.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.2 (OK)

```



Discussion:
I can't reproduce this on Linux. Maybe it's an issue with Qt.
I found out why this is caused: if you add (or remove) a line to a file with a breakpoint, that causes this breakpoint to change line.
And when you add/remove/modify breakpoints, it jumps to the current debug line. 

Resolving patch:
diff --git a/spyder/utils/site/sitecustomize.py b/spyder/utils/site/sitecustomize.py
--- a/spyder/utils/site/sitecustomize.py
+++ b/spyder/utils/site/sitecustomize.py
@@ -490,7 +490,8 @@ def reset(self):
 #     specific behaviour desired?)
 @monkeypatch_method(pdb.Pdb, 'Pdb')
 def postcmd(self, stop, line):
-    self.notify_spyder(self.curframe)
+    if line != "!get_ipython().kernel._set_spyder_breakpoints()":
+        self.notify_spyder(self.curframe)
     return self._old_Pdb_postcmd(stop, line)
 
 


Test patch:
Repository: spyder-ide/spyder

Issue:
HIstory browsing while debugging is broken
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [ ] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
While debugging, when pressing up, only the last command can be accessed


### What steps reproduce the problem?

1. debbug
2. press:
a0
a1
b0
3. type "a" then press up

### What is the expected output? What do you see instead?
want to see a1
see b0 instead




## Versions
Python 3.6.5 64bits, Qt 5.9.1, PyQt5 5.9 on Darwin 




Discussion:

Resolving patch:
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
@@ -103,6 +103,8 @@ def _event_filter_console_keypress(self, event):
                 return True
             elif key in (Qt.Key_Return, Qt.Key_Enter):
                 self._control.reset_search_pos()
+            else:
+                self._control.hist_wholeline = False
             return super(DebuggingWidget,
                          self)._event_filter_console_keypress(event)
         else:


Test patch:
Repository: spyder-ide/spyder

Issue:
Debugging history saves both python commands and pdb commands
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When debugging, I end up with many "s" and "n" in my debugging history, preventing me from finding what I am looking for. It would be nicer to only save python commands, or at least to have an option to do so.


Discussion:

Resolving patch:
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
@@ -10,6 +10,7 @@
 """
 
 import ast
+import pdb
 import pickle
 
 from qtpy.QtCore import Qt
@@ -86,7 +87,10 @@ def callback(line):
             # Save history to browse it later
             if not (len(self._control.history) > 0
                     and self._control.history[-1] == line):
-                self._control.history.append(line)
+                # do not save pdb commands
+                cmd = line.split(" ")[0]
+                if "do_" + cmd not in dir(pdb.Pdb):
+                    self._control.history.append(line)
 
             # This is the Spyder addition: add a %plot magic to display
             # plots while debugging


Test patch:
Repository: spyder-ide/spyder

Issue:
AttributeError: 'NoneType' object has no attribute 'get_active_project_path'
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

(python3:12490): Gtk-WARNING **: 13:04:31.888: Theme parsing error: gtk-main.css:73:38: Failed to import: Error opening file /usr/share/themes/Radiance/gtk-3.20/apps/gnome-builder.css: No such file or directory

### Traceback
```python-traceback
  File "/usr/local/lib/python3.6/dist-packages/spyder/app/mainwindow.py", line 1961, in valid_project
    if bool(self.projects.get_active_project_path()):
AttributeError: 'NoneType' object has no attribute 'get_active_project_path'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
```

## Versions

* Spyder version: 3.3.0 
* Python version: 3.6.5
* Qt version: 5.9.3
* PyQt5 version: 5.9.2
* Operating System: Linux 4.15.0-24-generic

### Dependencies

```
pyflakes >=0.6.0  :  2.0.0 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
rope >=0.9.4      :  0.10.7 (OK)
jedi >=0.9.0      :  0.12.1 (OK)
psutil >=0.3      :  5.4.6 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  1.14.3 (OK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0     :  5.5.0 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.9.2 (OK)
```



Discussion:
Please describe step by step how you got this error so we can reproduce it in our side. If you fail to do that, we'll close this issue in a week from now.

Also, please read our

https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ

to see if you are able to fix this problem by following it.

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -1958,8 +1958,12 @@ def show_toolbars(self):
     # --- Other
     def valid_project(self):
         """Handle an invalid active project."""
-        if bool(self.projects.get_active_project_path()):
+        try:
             path = self.projects.get_active_project_path()
+        except AttributeError:
+            return
+
+        if bool(path):
             if not self.projects.is_valid_project(path):
                 if path:
                     QMessageBox.critical(


Test patch:
Repository: spyder-ide/spyder

Issue:
Don't ask again ineffective in Console delete all variables dialog 
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. click the eraser icon in the ipython console
2. confirm don't ask again, 
3. click OK,
4. click eraser again -> confirmation dialog opens again 




## Versions

* Spyder version: 3.3.0 
* Python version: 3.6.1
* Qt version: 5.6.2
* PyQt5 version: 5.6
* Operating System: Windows 10

### Dependencies

```
pyflakes >=0.6.0  :  1.5.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.5.6 (OK)
rope >=0.9.4      :  0.9.4-1 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
nbconvert >=4.0   :  5.1.1 (OK)
pandas >=0.13.1   :  0.22.0 (OK)
numpy >=1.7       :  1.14.2 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.25.2 (OK)
qtconsole >=4.2.0 :  4.3.0 (OK)
IPython >=4.0     :  5.3.0 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.7.4 (OK)
```



Discussion:
Thanks for reporting. I can confirm this bug and we'll try to fix in our next release.

Resolving patch:
diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py
--- a/spyder/widgets/ipythonconsole/shell.py
+++ b/spyder/widgets/ipythonconsole/shell.py
@@ -251,6 +251,7 @@ def reset_namespace(self, warning=False, silent=True, message=False):
             # Update checkbox based on user interaction
             CONF.set('ipython_console', 'show_reset_namespace_warning',
                      not box.is_checked())
+            self.ipyclient.reset_warning = not box.is_checked()
 
             if answer != QMessageBox.Yes:
                 return
diff --git a/spyder/widgets/shell.py b/spyder/widgets/shell.py
--- a/spyder/widgets/shell.py
+++ b/spyder/widgets/shell.py
@@ -24,7 +24,7 @@
 from qtpy.compat import getsavefilename
 from qtpy.QtCore import Property, QCoreApplication, Qt, QTimer, Signal, Slot
 from qtpy.QtGui import QKeySequence, QTextCharFormat, QTextCursor
-from qtpy.QtWidgets import QApplication, QMenu, QMessageBox, QToolTip
+from qtpy.QtWidgets import QApplication, QMenu, QToolTip
 
 # Local import
 from spyder.config.base import _, DEBUG, get_conf_path, STDERR


Test patch:
Repository: spyder-ide/spyder

Issue:
NameError: name '_' is not defined
After "spyder --reset", "NameError: name '_' is not defined" show up, spyder cann't start up
spyder version 3.3.0
conda version 4.5.8

------

The problem content:

```python
Traceback (most recent call last):
  File "/home/yang/anaconda3/bin/spyder", line 7, in <module>
    from spyder.app.start import main
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/app/start.py", line 37, in <module>
    from spyder.config.base import (get_conf_path, running_in_mac_app,
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/config/base.py", line 415, in <module>
    _ = get_translation("spyder")
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/config/base.py", line 386, in get_translation
    language = load_lang_conf()
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/config/base.py", line 359, in load_lang_conf
    lang = get_interface_language()
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/config/base.py", line 330, in get_interface_language
    spyder_languages = get_available_translations()
  File "/home/yang/anaconda3/lib/python3.6/site-packages/spyder/config/base.py", line 297, in get_available_translations
    error = _('Update LANGUAGE_CODES (inside config/base.py) if a new '
NameError: name '_' is not defined
```


Discussion:
Thanks for reporting. We'll fix this problem in our next version.

Resolving patch:
diff --git a/spyder/config/base.py b/spyder/config/base.py
--- a/spyder/config/base.py
+++ b/spyder/config/base.py
@@ -294,9 +294,10 @@ def get_available_translations():
     # is added, to ensure LANGUAGE_CODES is updated.
     for lang in langs:
         if lang not in LANGUAGE_CODES:
-            error = _('Update LANGUAGE_CODES (inside config/base.py) if a new '
-                      'translation has been added to Spyder')
-            raise Exception(error)
+            error = ('Update LANGUAGE_CODES (inside config/base.py) if a new '
+                     'translation has been added to Spyder')
+            print(error)  # spyder: test-skip
+            return ['en']
     return langs
 
 


Test patch:
Repository: spyder-ide/spyder

Issue:
AttributeError: 'NoneType' object has no attribute 'input'
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Start Anaconda navigator
Launch Spyder

Or

Start Spyder directly

### Traceback
```python-traceback
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor.py", line 803, in <lambda>
    triggered=lambda: self.debug_command("exit"))
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor.py", line 2362, in debug_command
    self.main.ipyconsole.write_to_stdin(command)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole.py", line 1040, in write_to_stdin
    sw.write_to_stdin(line)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\debugging.py", line 33, in write_to_stdin
    self.kernel_client.input(line)
AttributeError: 'NoneType' object has no attribute 'input'
failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
```

## Versions

* Spyder version: 3.3.0 
* Python version: 3.6.6
* Qt version: 5.6.2
* PyQt5 version: 5.6
* Operating System: Windows 10

### Dependencies

```
pyflakes >=0.6.0  :  1.6.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.6.6 (OK)
rope >=0.9.4      :  0.10.7 (OK)
jedi >=0.9.0      :  0.11.1 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.22.0 (OK)
numpy >=1.7       :  1.14.0 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.27.3 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0     :  6.2.1 (OK)
matplotlib >=2.0.0:  2.1.2 (OK)
pylint >=0.25     :  1.8.2 (OK)
```



Discussion:
Thanks for reporting. We'll fix this error in a futute release.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -1047,7 +1047,12 @@ def execute_code(self, lines, current_client=True, clear_variables=False):
     def write_to_stdin(self, line):
         sw = self.get_current_shellwidget()
         if sw is not None:
-            sw.write_to_stdin(line)
+            # Needed to handle an error when kernel_client is None
+            # See issue 7578
+            try:
+                sw.write_to_stdin(line)
+            except AttributeError:
+                pass
 
     @Slot()
     @Slot(bool)


Test patch: