Skip to content

Import detection and resolution via Python resolver for pylint #9103

@pwithams

Description

@pwithams

I'm interested in implementing no-name-in-module (E0611) and import-error (E0401) for pylint (#970).

I think this would handle this issue #6327 but as mentioned in that issue thread it might get a little complex with things like virtual environments.

I've taken a brief look at the resolver but wondering if there has been any other work into this issue before continuing. A couple of my thoughts:

  • I believe pylint essentially runs the code and catches the exceptions ImportError and ModuleNotFoundError, although it will return all errors, not just the first, with a line like import os.foobar triggering both errors
  • ruff appears to be so fast currently due to avoiding (or at least minimizing) invoking any python
  • is there any way to achieve this functionality without actually calling python, such as somehow determining a list of available modules (for import-error at least)? Could this ever be fully trustworthy? I'm guessing not.
  • if python does have to be called (can't really see a way to avoid it for no-name-in-module, especially when it comes to things like c libraries), are there ways to optimize/minimize python usage/runtime?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-inferenceRequires more advanced type inference.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions