Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#1059546: pylint generates false positive 'import-error' with local editable modules.

171 views
Skip to first unread message

Mike Castle

unread,
Dec 27, 2023, 10:50:04 PM12/27/23
to
Package: pylint
Version: 2.16.2-2
Severity: important
Tags: upstream
X-Debbugs-Cc: dal...@gmail.com

Dear Maintainer,

This *might* be https://github.com/pylint-dev/pylint/issues/8829 . However, I
am new to this bits of the Python eco-system, so not confident in my
assessment.

When trying to run pylint against a module that imports an _editable_ module
install, a false positive 'import-error' is given.

To reproduce, I used the following toy module:
$ find -type f -exec printf '\n%s\n' {} \; -exec cat {} \;

./pyproject.toml
[project]
name = 'ttt'
version = '0'

./ttt/__init__.py

./ttt/pylintbug.py
"""Docstring."""

def bug_func():
"""Bug."""
print('I am the bug_func')

And this module for testing:
$ cat t.py
"""Docstring."""

from ttt import pylintbug

pylintbug.bug_func()


With the module not installed, nothing works, as expected:
# nothing installed
$ pip list --user ; date
Wed Dec 27 07:31:09 PM PST 2023

$ python --version
Python 3.11.2

$ python t.py
Traceback (most recent call last):
File "/home/nexus/t.py", line 3, in <module>
from ttt import pylintbug
ModuleNotFoundError: No module named 'ttt'

$ pylint --rcfile /dev/null t.py
************* Module t
t.py:3:0: E0401: Unable to import 'ttt' (import-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)


Install the module:

$ pip install --break-system-packages .
Defaulting to user installation because normal site-packages is not writeable
Processing /home/nexus/src/ttt
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: ttt
Building wheel for ttt (pyproject.toml) ... done
Created wheel for ttt: filename=ttt-0-py3-none-any.whl size=1225 sha256=051948400d275bad5c31d656ef0394f8a43232d00754ab826bbe18dcd67d1c60
Stored in directory: /tmp/pip-ephem-wheel-cache-upb4wjrt/wheels/c3/93/be/4d7b95f07076bb565c6c69548aef2e2868a95b899b724660dd
Successfully built ttt
Installing collected packages: ttt
Successfully installed ttt-0

And everything works as expected:
$ pip list --user ; date
Package Version
------- -------
ttt 0
Wed Dec 27 07:32:56 PM PST 2023

$ python t.py
I am the bug_func

$ pylint --rcfile /dev/null t.py

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)


Now, install the module and reinstall in _editable_ mode (-e):

$ pip uninstall --break-system-packages -y ttt
Found existing installation: ttt 0
Uninstalling ttt-0:
Successfully uninstalled ttt-0

$ pip install --break-system-packages -e .
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///home/nexus/src/ttt
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... done
Preparing editable metadata (pyproject.toml) ... done
Building wheels for collected packages: ttt
Building editable for ttt (pyproject.toml) ... done
Created wheel for ttt: filename=ttt-0-0.editable-py3-none-any.whl size=2313 sha256=20eacec25143d7c0f57fed066c7c57dbed566853edc944919e1029a65349822b
Stored in directory: /tmp/pip-ephem-wheel-cache-2sxotfjx/wheels/c3/93/be/4d7b95f07076bb565c6c69548aef2e2868a95b899b724660dd
Successfully built ttt
Installing collected packages: ttt
Successfully installed ttt-0


Now, executing the 't.py' script works, but pylint fails with the false
positive:

$ pip list --user ; date
Package Version Editable project location
------- ------- -------------------------
ttt 0 /home/nexus/src/ttt
Wed Dec 27 07:35:24 PM PST 2023

$ python t.py
I am the bug_func

$ pylint --rcfile /dev/null t.py
************* Module t
t.py:3:0: E0401: Unable to import 'ttt' (import-error)

--------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 10.00/10, -10.00)


Reinstalling the module in regular mode and it works again:

$ pip list --user ; date
Package Version
------- -------
ttt 0
Wed Dec 27 07:38:27 PM PST 2023

$ python t.py
I am the bug_func

$ pylint --rcfile /dev/null t.py

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)


-- System Information:
Debian Release: 12.4
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-16-amd64 (SMP w/6 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages pylint depends on:
ii python3 3.11.2-1+b1
ii python3-astroid 2.14.2-1
ii python3-dill 0.3.6-1
ii python3-isort 5.6.4-1
ii python3-logilab-common 1.9.8-1
ii python3-mccabe 0.7.0-1
ii python3-platformdirs 2.6.0-1
ii python3-setuptools 66.1.1-1
ii python3-tomli 2.0.1-2
ii python3-tomlkit 0.11.7-1
ii python3-typing-extensions 4.4.0-1

Versions of packages pylint recommends:
ii python3-tk 3.11.2-3

Versions of packages pylint suggests:
pn pylint-doc <none>

-- no debconf information

Sandro Tosi

unread,
Jan 17, 2024, 1:10:05 AM1/17/24
to
control: tags -1 +moreinfo

> To reproduce, I used the following toy module:
> $ find -type f -exec printf '\n%s\n' {} \; -exec cat {} \;

next time, please setup a throw-away repo somewhere like
github.com/gitlab.com, cause it takes too long to setup a reproduce
environment like this.

> With the module not installed, nothing works, as expected:

not really

> $ python t.py
> Traceback (most recent call last):
> File "/home/nexus/t.py", line 3, in <module>
> from ttt import pylintbug
> ModuleNotFoundError: No module named 'ttt'

python has . in its module search path, so this should work (and in
fact it does in my docker container testing env). please check your
installation environment.

--
Sandro "morph" Tosi
My website: http://sandrotosi.me/
Me at Debian: http://wiki.debian.org/SandroTosi
Twitter: https://twitter.com/sandrotosi

Mike Castle

unread,
Jan 17, 2024, 10:50:06 AM1/17/24
to
Sorry. I now realize that changing my local PROMPT to be the default
'$ ', I dropped an important bit of information.

The file, `t.py` is NOT in the same directory as `pyproject.toml`.
That is, while t.py was $HOME for the test, the pyproject.toml file
and associated source was in some $RANDOM directory.

Just like, if I have two python projects, A and B, living in
completely different source directories, and A depends on B.

If B is installed in normal mode, pylint against A works fine.
However, if B is installed with 'pip -e', then pylint against A cannot
find B.

mrc

Sandro Tosi

unread,
Jan 17, 2024, 11:00:04 AM1/17/24
to
since you have not provided an easily replicable setup environment,
please go ahead and test with the newly uploaded pylint/3.0.1 and
report back
0 new messages