Repository: spyder-ide/spyder

Issue:
TypeError in Outline explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Doing anything with outline explorer doesn't do as expected. Clicking on Display variables and attributes will cause an error.
special comments and def and class information is not displayed for all files

ADDENDUM  (the next day)
I have tracked down the issues to scripts in a project. 
 If I close my project and navigate to a folder outside any project path and load any script, the outline pane displays as it should.
You can click on a def or class and the code in the editor is navigated to.  
More importantly, you can see the complete tree of your script's functions/methods and classes to facilitate navigation and organization.
Closing Spyder and reopening necessitates closing all open scripts and reloading them in order to get the tree information back

### Traceback
```python-traceback
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 433, in toggle_variables
    self.update_editor(editor.info, editor)
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 615, in update_editor
    update = self.update_tree(items, editor_id, language)
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 645, in update_tree
    for symbol in items:
TypeError: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 433, in toggle_variables
    self.update_editor(editor.info, editor)
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 615, in update_editor
    update = self.update_tree(items, editor_id, language)
  File "C:\arc_pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder\plugins\outlineexplorer\widgets.py", line 645, in update_tree
    for symbol in items:
TypeError: 'NoneType' object is not iterable
```

## Versions

* Spyder version: 4.2.0 
* Python version: 3.7.9
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  3.0.4 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=4.0                   :  7.18.1 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
nbconvert >=4.0                 :  5.6.1 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.7.2 (OK)
pygments >=2.0                  :  2.7.0 (OK)
pylint >=1.0                    :  2.6.0 (OK)
pyls >=0.36.1;<1.0.0            :  0.36.1 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.1.1             :  0.2.1 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.1 (OK)
qtconsole >=4.7.7               :  4.7.7 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.4 (OK)
setuptools >=39.0.0             :  51.0.0.post20201207 (OK)
sphinx >=0.6.6                  :  3.2.1 (OK)
spyder_kernels >=1.10.0;<1.11.0 :  1.10.0 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  0.10.4 (OK)
zmq >=17                        :  19.0.2 (OK)

# Optional:
cython >=0.21                   :  None (NOK)
matplotlib >=2.0.0              :  3.3.1 (OK)
numpy >=1.7                     :  1.19.2 (OK)
pandas >=1.1.1                  :  1.1.3 (OK)
scipy >=0.17.0                  :  1.5.2 (OK)
sympy >=0.7.3                   :  1.5.1 (OK)
```



Discussion:
Hi @Dan-Patterson,

Can you please upload a gif with the behavior you are having? Also, can you clarify me if this error is happening during the first session you open of spyder, or in the second one? 

![spyder](https://user-images.githubusercontent.com/6071199/102140802-d1d85c00-3e2d-11eb-8183-de8541164449.png)
@steff456 Thanks for responding... in short...
The left is what I see when opening a project. Just the comments for the class definition.  There is no function (F) or method (M) designations for any script.
I have to go into the project folder and kill the .spyproject folder.  I can then load all the project scripts one at a time in order to see what I want on the right.

I have attached a *.png to show the difference.
NOTE  This issue only arose when upgrading to 4.20,  previous versions were find.  I have always maintained a proper project structure, so it isn't a real issue, but it certainly removes the "Project" convenience factor.
@steff456 .... 
Did some more exploring.
If you add a script or open a project for the first time after updating to 4.2, it doesn't go well.
If you want to see the function/method indicators in the outline, then you have to delete and re-add the script.  Not sure if pyls is at issue or something else.
I can confirm this behavior on Linux Mint, Spyder 4.2.0, Python 3.7.9. With simple scripts with functions and comments starting with `# ----------`, the output pane shows both comments and function markers, which allow navigation. When it comes to modules containing classes and internal methods, the Output pane only shows the comment markers, not the class or method markers. Not having the navigation capabilities for more complex files makes developing much slower and cumbersome.
Hi @Dan-Patterson and @dcasasor-purdue, have you tried to see if the error persists in the latest release?
Hi @steff456 , thanks for the follow up. I just installed spyder 4.2.1 on Linux Mint (conda-forge install), and I'm getting the same behavior. As an example, this is the outline pane for a module with 3 classes, each one with its set of methods. Not classes nor method markers are shown, only comments followed by `----------`. 
![image](https://user-images.githubusercontent.com/56893746/104027799-e93d0780-5195-11eb-9911-ccb31b77bed7.png)

The classes inside the module are these:
![image](https://user-images.githubusercontent.com/56893746/104027920-15f11f00-5196-11eb-85a8-ca35b006e771.png)

@steff456 I have to wait until it comes out on anaconda because of my environment
Note: Still presented in Spyder 4.2.1
I'm having a similar problem with Spyder 4.2.1 on mac OS. When I toggle "Display variables and attributes", I receive the error 
```

  File ".../miniconda3/envs/spyder-env/lib/python3.8/site-packages/spyder/plugins/outlineexplorer/widgets.py", line 413, in toggle_variables
    self.update_editor(editor.info, editor)
  File ".../miniconda3/envs/spyder-env/lib/python3.8/site-packages/spyder/plugins/outlineexplorer/widgets.py", line 595, in update_editor
    update = self.update_tree(items, editor_id, language)
  File ".../miniconda3/envs/spyder-env/lib/python3.8/site-packages/spyder/plugins/outlineexplorer/widgets.py", line 626, in update_tree
    for symbol in items:
TypeError: 'NoneType' object is not iterable

```
It is still present in 4.2.1.
The issue is still open.
In Spyder 4.2.1 I can reproduce just like @cruyffturn and get the same stack trace when toggling the  "Display variables and attributes" checkbox on the pop-up menu button in the top right corner of the Outline panel. However, my troubleshooting below suggests this could be a separate issue from what makes things go missing from the Outline panel:

At first I had a more specific issue where enabling Completion and linting -> **Docstring style** blanked out the Outline panel completely (not even the comment-lines that @Dan-Patterson got, only the filename on top). However, this turned out to be because I had created a .pydocstyle in my home directory that beyond an ignore-line also had the line "match = \*.py". After correcting this from a glob-expression to a regex, i.e. "match = .\*\\.py" and cleaning out (\_\_pycache\_\_ and a .pylint.d directory that had appeared once) and restaring Spyder, I now have a fully working Outline panel!

Toggling the "Display variables and attributes" checkbox still triggers the Spyder crash report with the same lines as in @cruyffturn's comment, but the attributes really get shown or hidden from the Outline.

Thus, I feel that it is not at all obvious that the message @cruyffturn and I see is the cause of whatever caused a broken Outline for @Dan-Patterson's screenshots. My own issues seem to be solved (for today...) but I post this comment in case it contains any clues or helps people exclude some troubleshooting paths. (Perhaps one could also hope for pydocstyle to more gracefully report a misconfiguration and not block the Outline, let me know if it is worth opening a separate issue about.)

I attach the complete listing of package versions for this Miniconda environment: [conda_env_export.yaml.txt](https://github.com/spyder-ide/spyder/files/5958822/conda_env_export.yaml.txt)

That's an interesting find @erik-mansson! Thanks for sharing it!

Note to self: perhaps we need to check for errors in config files and drop them if that's the case in the PyLS.

Resolving patch:
diff --git a/spyder/plugins/outlineexplorer/widgets.py b/spyder/plugins/outlineexplorer/widgets.py
--- a/spyder/plugins/outlineexplorer/widgets.py
+++ b/spyder/plugins/outlineexplorer/widgets.py
@@ -587,6 +587,9 @@ def update_editor(self, items, editor=None):
         Update the outline explorer for `editor` preserving the tree
         state.
         """
+        if items is None:
+            return
+
         plugin_base = self.parent().parent()
         if editor is None:
             editor = self.current_editor


Test patch: