Skip to content

pylint fails to import module if the script is named the same way #7093

@bdrung

Description

@bdrung

Bug description

Apport provides a module name apport, but also a script named data/apport. Pylint throws a bunch of failures for data/apport. This problem can be reproduces with this Shell script:

#!/bin/sh
mkdir name
touch name/__init__.py
printf '# pylint: disable=missing-docstring\ndef inc(val):\n    return val + 1\n' > name/math.py
mkdir data
printf '#!/usr/bin/python3\n# pylint: disable=missing-docstring\n\nimport name\nimport name.math\n\nprint(name.math.inc(41))\n' > data/name
chmod +x data/name
PYTHONPATH=. data/name

It will create name/math.py with

# pylint: disable=missing-docstring
def inc(val):
    return val + 1

and data/name with

#!/usr/bin/python3
# pylint: disable=missing-docstring

import name
import name.math

print(name.math.inc(41))

After setting PYTHONPATH, data/name will execute successfully.

Configuration

No response

Command used

pylint name data/name

or

PYTHONPATH=. pylint name data/name

or

pylint --init-hook='import sys; sys.path.append(".")' name data/name

Pylint output

data/name:4:0: W0406: Module import itself (import-self)
data/name:5:0: E0611: No name 'math' in module 'name' (no-name-in-module)
data/name:7:6: I1101: Module 'name' has no 'math' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)

Expected behavior

pylint should produce no output.

Pylint version

pylint 2.14.4
astroid 2.11.6
Python 3.10.5 (main, Jun  8 2022, 09:26:22) [GCC 11.3.0]

OS / Environment

Ubuntu 22.04 (jammy)

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    AstroidRelated to astroidNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationnamespace-package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions