Skip to content

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

@defe007

Description

@defe007

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions