spyder: Outline not showing functions or erroneously showing imports as functions

Issue Report Checklist

  • [x ] Searched the issues page for similar reports
  • [ x] Read the relevant sections of the Spyder Troubleshooting Guide 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
    • [x ] Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • [x ] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

What steps reproduce the problem?

  1. outline not listing functions, doesn’t matter if they are in code cells or not image
  2. outline listing module imports as generic functions when they are moved to a new line with "" image

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

Paste Traceback/Error Below (if applicable)


PASTE TRACEBACK HERE

Versions

  • Spyder version: 5.1.3
  • Python version: 3.7.11
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: windows 10

Dependencies


# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.26.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.7.2 (OK)
parso >=0.7.0;<0.9.0          :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.2 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.10.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  4.0.2 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.3 (OK)
zmq >=17                      :  22.2.1 (OK)

# Optional:
cython >=0.21                 :  None (OK)
matplotlib >=2.0.0            :  3.4.2 (OK)
numpy >=1.7                   :  1.18.5 (OK)
pandas >=1.1.1                :  1.1.2 (OK)
scipy >=0.17.0                :  1.6.3 (OK)
sympy >=0.7.3                 :  None (OK)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

A bit off topic here but just in short: The python import system considers each package (i.e. folder) that dies not contain a “init.py” file a “namespace package”. You don’t need that for standalone projects normally. It is only useful if you want to have multiple projects to be importable from the same namespace. This is the (lenghty but detailed) description of namespace packages: https://www.python.org/dev/peps/pep-0420/

Moritz Lürig @.***> schrieb am Mo., 13. Sep. 2021, 16:28:

curious…

Your phenopype.core package is a namespace package. Is that intentional?

I guess not, because I don’t know what a namespace package is. at least, I couldn’t guess from your example…

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/16406#issuecomment-918250866, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7SKK365XTAKSZO4QLV243UBYDBJANCNFSM5D4FXIAA .

I’m seeing a similar issue and I think I could at least identify part of the problem, maybe the whole problem: It seems like any module that is part of a namespace package does not have its functions and classes listed in the outline.

I can confirm that this is the issue - adding an __init__.py solved it for me

I have also encountered this problem with Spyder 5.2.2 on Windows 10.

Continuing discussion from comment on issue #15139 after some more testing.

Project directory structure (in summary)

Project_root/
├── some_directories ...
├── some_files ...
├── src/
│   ├── main_module.py
│   └── submodules/
│       ├── __init__.py
│       ├── submodule_1.py
│       ├── submodule_2.py
│       └── subsubmodules/
│           ├── __init__.py
│           └── subsubmodule_1.py
└── build_script.py

Versions

  • Spyder version: 5.2.2 None
  • Python version: 3.7.9 64-bit
  • Qt version: 5.12.10
  • PyQt5 version: 5.12.3
  • Operating System: Windows 10

Installed with .exe installer, same result with Spyder’s own Python 3.7.9 and the system-wide Python 3.9.2 which I mainly use.

Results

The outline view works for modules placed in the project root directory (e.g. build_script.py), but not for anything under src/ and further down (only filename is shown).

Curiously, the outlines for src/ and its modules work and update even for new files after removing __init__.py from src/, changing the Python interpreter and restarting Spyder (?!)

Workaround

Putting an __init__.py into src/ and restarting Spyder (or the LSP language server) makes the outline work for all the modules in src/ and its subdirectories.

I didn’t think about doing it at first, given that src/ is just my folder for keeping code and is not intended to be a package. But happily it looks workable.

@ccordoba12

Thanks for merging issues.

I also solved this issue by adding an init.py (sorry, I failed to input the right filename.)

@mluerig or @Brow71189, did you install your packages with pip install -e .?

I don’t have any of my packages installed in the python installation that spyder uses (since I’m using the installer, it is completely separate from any other installations on my system).

Great that you could reproduce the problem and thanks for taking it on!

I was able to reproduce the problem with @Brow71189’s example and will try to fix it in our next release. At least you have a workaround until then.