Skip to content

Add import management tools #28

@kbauer

Description

@kbauer

Issue Report Checklist

Enhancement request, so only a subset applies.

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

The python ecosystem discourages in many way the use of star imports. In Spyder this is most visible through "basic linting" complaining, that pyflakes can't analyze undefined names when star-imports are used.

However, the alternative is to constantly manually update import lists, which is undesirable, especially during data analysis tasks.

At this point it would be extremely useful to have a utility, that manages imports; For instance, I'd like to be able to write x = linspace(0, 1, 101) and, after pressing some hotkey, be offered to add from numpy import linspace. Not having to worry about the manual imports would put python usage closer in convenience aspects to dedicated data analysis tools like Matlab, where imports are basically automated.

Desirable subfeature: Automatic execution of the imports

After an import statement has been added, the user would still have to go back to the top of the file and execute the #%%-cell, containing the import statements. This is likewise undesirable; After updating the import statements, they should therefore also be evaluated in the associated console, if any.

Desirable subfeature: Cleanup of unused imports

In order to reduce the number of distracting linter warnings, cleaning up imports would also be desirable. For instance, by reducing from numpy import array, linspace to from numpy import linspace, if array is never used, or dropping import os, if os is never referenced.

Available infrastructure libraries

The desired functionality is provided by some libraries. Personally, I have experience only with importmagic through importmagic.el, from which I know that edge-cases may be an issue. In this case, it failed to provide an autoimport for pprint, getting confused by the duplicity of pprint the module and pprint.pprint the function.

Versions

Python 3.9.4 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Linux 4.12.14-lp151.28.91-default

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.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.6.0               :  7.23.1 (OK)
jedi =0.17.2                  :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.0.7 (OK)
numpydoc >=0.6.0              :  1.1.0 (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.8.0 (OK)
pygments >=2.0                :  2.9.0 (OK)
pylint >=1.0                  :  2.7.2 (OK)
pyls >=0.36.2;<1.0.0          :  0.36.2 (OK)
pyls_black >=0.4.6            :  0.4.6 (OK)
pyls_spyder >=0.3.2;<0.4.0    :  0.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.0 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.8.3                 :  0.9.7 (OK)
setuptools >=39.0.0           :  49.6.0.post20210108 (OK)
sphinx >=0.6.6                :  4.0.1 (OK)
spyder_kernels >=2.0.2;<2.1.0 :  2.0.3 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0      :  1.0.2 (OK)
xdg >=0.26                    :  0.26 (OK)
zmq >=17                      :  22.0.3 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=2.0.0            :  None (NOK)
numpy >=1.7                   :  None (NOK)
pandas >=1.1.1                :  None (NOK)
scipy >=0.17.0                :  None (NOK)
sympy >=0.7.3                 :  None (NOK)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions