Skip to content

Running pylint on namespace modules results in import-error #2862

Open
@gpakosz

Description

@gpakosz

Here's a simple repro

(tmp) bash-3.2$ tree
.
├── foo
│   ├── __init__.py
│   └── bar.py
└── tools
    └── foo
        └── foo.py

3 directories, 3 files
(tmp) bash-3.2$ cat foo/__init__.py
"""foo lib"""
(tmp) bash-3.2$ cat foo/bar.py
"""foo.bar module"""

def baz():
    print("baz")
(tmp) bash-3.2$ cat tools/foo/foo.py
"""foo tool"""
import foo.bar

foo.bar.baz()

When I launch the code with python -m, the code runs just fine.

(tmp) bash-3.2$ python -m tools.foo.foo
baz

However, when running pylint on a single file, I'm hitting E0611. My real goal is to launch pylint on modified file from a Git pre-commit hook. I tried using --init-hook and manipulate sys.path without success.

(tmp) bash-3.2$ pylint ./tools/foo/foo.py
************* Module foo
tools/foo/foo.py:1:0: C0102: Black listed name "foo" (blacklisted-name)
tools/foo/foo.py:2:0: E0611: No name 'bar' in module 'foo' (no-name-in-module)
tools/foo/foo.py:2:0: E0401: Unable to import 'foo.bar' (import-error)
tools/foo/foo.py:4:0: E1101: Module 'foo' has no 'bar' member (no-member)

-----------------------------------------------------------------------
Your code has been rated at -70.00/10 (previous run: -46.67/10, -23.33)

Thanks for the help

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions