Repository: spyder-ide/spyder

Issue:
TypeError while trying to process git data
<!--- **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)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] 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

Completion from packages installed in an external environment are not showing in the editor. Instead, completions from the package installed in the spyder environment are showing.

### What steps reproduce the problem?

1. Create an external environment with `conda create --name test flask spyder-kernels`
2. Set the python interpreter to the external `test` environment
3. Type `import fl`+tab in the editor

### What is the expected output? What do you see instead?

The editor shows no completions for the the flask package, but show completions for the flake8 package that is installed in the spyder environment.

```
> conda activate spyder && conda list | grep fl
flake8                    7.0.0              pyhd8ed1ab_0    conda-forge
giflib                    5.2.1                h1a8c8d9_3    conda-forge
inflection                0.5.1              pyh9f0ad1d_0    conda-forge
libdeflate                1.19                 hb547adb_0    conda-forge
pyflakes                  3.2.0              pyhd8ed1ab_0    conda-forge

> > conda activate test && conda list | grep fl
# packages in environment at /Users/remisalmon/Miniconda/envs/flask:
flask                     3.0.2              pyhd8ed1ab_0    conda-forge
```
<img width="429" alt="image" src="https://github.com/spyder-ide/spyder/assets/26257211/27c94389-5cbb-4a3a-b3a1-e4efdc67a14b">

The ipython console does show the right completions:
<img width="595" alt="image" src="https://github.com/spyder-ide/spyder/assets/26257211/9ef42e77-96e0-4585-a4d6-b2b2d803368f">



## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.5.1  (conda)
* Python version: 3.11.8 64-bit
* Qt version: 5.15.8
* PyQt5 version: 5.15.9
* Operating System: macOS-13.6.2-arm64-arm-64bit

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
# Mandatory:
applaunchservices >=0.3.0        :  0.3.0 (OK)
atomicwrites >=1.2.0             :  1.4.1 (OK)
chardet >=2.0.0                  :  5.2.0 (OK)
cloudpickle >=0.5.0              :  3.0.0 (OK)
cookiecutter >=1.6.0             :  2.6.0 (OK)
diff_match_patch >=20181111      :  20230430 (OK)
intervaltree >=3.0.2             :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1 :  8.22.1 (OK)
jedi >=0.17.2,<0.20.0            :  0.19.1 (OK)
jellyfish >=0.7                  :  1.0.3 (OK)
jsonschema >=3.2.0               :  4.21.1 (OK)
keyring >=17.0.0                 :  24.3.0 (OK)
nbconvert >=4.0                  :  7.16.1 (OK)
numpydoc >=0.6.0                 :  1.6.0 (OK)
parso >=0.7.0,<0.9.0             :  0.8.3 (OK)
pexpect >=4.4.0                  :  4.9.0 (OK)
pickleshare >=0.4                :  0.7.5 (OK)
psutil >=5.3                     :  5.9.8 (OK)
pygments >=2.0                   :  2.17.2 (OK)
pylint >=2.5.0,<3.1              :  3.0.3 (OK)
pylint_venv >=3.0.2              :  3.0.3 (OK)
pyls_spyder >=0.4.0              :  0.4.0 (OK)
pylsp >=1.10.0,<1.11.0           :  1.10.0 (OK)
pylsp_black >=2.0.0,<3.0.0       :  2.0.0 (OK)
qdarkstyle >=3.2.0,<3.3.0        :  3.2.3 (OK)
qstylizer >=0.2.2                :  0.2.2 (OK)
qtawesome >=1.2.1                :  1.3.0 (OK)
qtconsole >=5.5.1,<5.6.0         :  5.5.1 (OK)
qtpy >=2.1.0                     :  2.4.1 (OK)
rtree >=0.9.7                    :  1.2.0 (OK)
setuptools >=49.6.0              :  69.1.1 (OK)
sphinx >=0.6.6                   :  7.2.6 (OK)
spyder_kernels >=2.5.0,<2.6.0    :  2.5.0 (OK)
textdistance >=4.2.0             :  4.5.0 (OK)
three_merge >=0.1.1              :  0.1.1 (OK)
watchdog >=0.10.3                :  4.0.0 (OK)
zmq >=22.1.0                     :  25.1.2 (OK)

# Optional:
cython >=0.21                    :  None (NOK)
matplotlib >=3.0.0               :  None (NOK)
numpy >=1.7                      :  1.26.4 (OK)
pandas >=1.1.1                   :  2.2.1 (OK)
scipy >=0.17.0                   :  None (NOK)
sympy >=0.7.3                    :  None (NOK)
```



Discussion:
Hey @remisalmon, thanks for reporting. Did you set some advanced options for the Python language server in `Preferences > Completion and linting`?
> Hey @remisalmon, thanks for reporting. Did you set some advanced options for the Python language server in `Preferences > Completion and linting`?

I did not. I tested with the box checked and the default options but still had this issue.
I tested with the latest dev version from the 5.x branch and was not able to reproduce from there, fingers crossed for Spyder 5.5.2?

The python-lsp-* packages versions are the same between this and the conda environment where I have this issue:
```
> conda list | grep spyder                                      (spyder-dev)
# packages in environment at /Users/remisalmon/Miniconda/envs/spyder-dev:
pyls-spyder               0.4.0              pyhd8ed1ab_0    conda-forge
spyder                    5.5.2rc1                  dev_0    <develop>
spyder-kernels            2.6.0.dev0                dev_0    <develop>
> conda list | grep lsp                                         (spyder-dev)
python-lsp-black          2.0.0              pyhd8ed1ab_0    conda-forge
python-lsp-jsonrpc        1.1.2              pyhd8ed1ab_0    conda-forge
python-lsp-server         1.10.0             pyhd8ed1ab_0    conda-forge
python-lsp-server-base    1.10.0             pyhd8ed1ab_0    conda-forge
```
> I tested with the latest dev version from the 5.x branch and was not able to reproduce from there, fingers crossed for Spyder 5.5.2?

Ok, that's good news. Let us know if that continues to be the case when 5.5.2 is available in Conda-forge (most probably tomorrow).
I removed and recreated all my conda environments, deleted .spyder-py3/ and updated to 5.5.2, and still having this issue. This error in the logs seems unrelated:
```
Traceback (most recent call last):
  File "/Users/remisalmon/Work/Miniconda/envs/spyder/lib/python3.11/site-packages/spyder/plugins/editor/widgets/status.py", line 121, in process_git_data
    branches, branch, files_modified = output
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object
```
@remisalmon, is the problem you reported above still an issue for you? If so, we can fix it for 5.5.4, to be released soon.
> @remisalmon, is the problem you reported above still an issue for you? If so, we can fix it for 5.5.4, to be released soon.

Yes I am still having this issue with spyder 5.5.3, but only when spyder is installed in another conda environment. I am not having this issue using the standalone spyder app, or when sypder is installed in a virtual environment with pip.

This is my config for the spyder environment:
```
name: spyder
channels:
  - conda-forge
dependencies:
  - python=3.11
  - spyder=5.5
  - pandas
```

Its bizarre, I will report back if this goes away with spyder 5.5.4.
> Yes I am still having this issue with spyder 5.5.3, but only when spyder is installed in another conda environment.

But did you also update Spyder to 5.5.3 in your other env?
@remisalmon, checking again about this one. Is the problem still present for you?
> @remisalmon, checking again about this one. Is the problem still present for you?

Yes and this with Spyder 5.5.3 in all my conda/pip/dmg environments, though conda is the only one with this issue.
Ok, we'll fix this problem in our next version (5.5.4), to be released tomorrow.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/status.py b/spyder/plugins/editor/widgets/status.py
--- a/spyder/plugins/editor/widgets/status.py
+++ b/spyder/plugins/editor/widgets/status.py
@@ -118,7 +118,13 @@ def get_git_refs(self, fname):
 
     def process_git_data(self, worker, output, error):
         """Receive data from git and update gui."""
-        branches, branch, files_modified = output
+        # Output can be None under some circumstances, so we need to deal with
+        # it here.
+        # Fixes spyder-ide/spyder#21865
+        if output is None:
+            branch, files_modified = None, []
+        else:
+            __, branch, files_modified = output
 
         text = branch if branch else ''
         if len(files_modified):


Test patch: