Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid no-name-in-module error when using lazy_loader #9553

Closed
defe007 opened this issue Apr 17, 2024 · 3 comments
Closed

Invalid no-name-in-module error when using lazy_loader #9553

defe007 opened this issue Apr 17, 2024 · 3 comments

Comments

@defe007
Copy link

defe007 commented Apr 17, 2024

Bug description

Pylint is reporting an invalid no-name-in-module when a module is using lazy_loader. This was tested in a conda environment created by:

conda create -n pylint_env -c conda-forge python=3.10 lazy_loader==0.4.0 pylint==3.1.0 -y

Creating a dummy library example:

# lib/__init__.py
import lazy_loader as lazy
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
# lib/__init__.pyi
__all__ == ["bar"]
from ._foo import bar
# lib/_foo.py
def bar():
    print("I'm happy")
# test.py
from lib import bar
bar()

Running test.py executes as expected but pylint is reporting an error.

conda activate pylint_env
python test.py  # works and prints "I'm happy"
pylint test.py  # fails with 
# test.py:1:0: E0611: No name 'bar' in module 'lib' (no-name-in-module)

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:1:0: E0611: No name 'bar' in module 'lib' (no-name-in-module)

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

Expected behavior

I would expect the no-name-in-module error to not be reported.

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]

OS / Environment

RHEL7

Additional dependencies

lazy_loader==0.4.0
@DanielNoord
Copy link
Collaborator

I think this is to be expected. I don't know lazy_loader but it seems very hard to statically infer what it is doing.

Even if possible I don't think it should live in the core pylint package.

@DanielNoord DanielNoord closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Won't fix/not planned and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 22, 2024
@lagru
Copy link

lagru commented May 1, 2024

I'd like to add some context. lazy_loader tries to account for precisely this case by providing lazy_loader.attach_stub . That function populates the namespace of where attach_stub is called with the namespace indicated by a PYI file. I haven't looked up any official recommendations or PEPs on this, but my impression is, that most IDEs and type checkers will give PYI files priority for static analysis.

So depending on the above, this might not be a problem with specific to lazy_loader, depending on how Pylint takes PYI files into account during analysis.

@Pierre-Sassoulas
Copy link
Member

Probably something that'll get fixed by pylint-dev/astroid#2375 in pylint/astroid 3.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants