Skip to content

E0401 (import-error): False positive with relative import from file in another module #9262

Open
@fdelu

Description

@fdelu

Bug description

Two files required to reproduce:

  • app/main.py:

    # pylint: disable=missing-module-docstring
    from .lib.a import hello
    
    hello()
  • app/lib/a.py:

    # pylint: disable=missing-module-docstring
    # pylint: disable=missing-function-docstring
    def hello():
        print("hello")

Configuration

.pylintrc:

[MAIN]
source-roots=.

Command used

pylint app

Pylint output

************* Module app.main
app/main.py:2:0: E0401: Unable to import 'lib.a' (import-error)

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

Expected behavior

No errors. Running python3 -m app.main prints hello successfully (and thus the import succedeed)

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.11.6 (main, Oct 23 2023, 22:48:54) [GCC 11.4.0]

OS / Environment

Ubuntu 22.04, zsh

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeImport systemNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions