Skip to content

.py files having precedence over .pyi files causes problems with opencv-python module (and probably others) #9185

@n0n3m4

Description

@n0n3m4

Bug description

If module has both .py and .pyi files available, .py file is always used according to the code added in pull request pylint-dev/astroid#2182
Unfortunately, this doesn't always work correctly, as noted in the discussion of that pull request (even pylint-dev/astroid#2195 was created, but not merged)
One of the popular libraries where this doesn't work is opencv-python, here is an example code:

import cv2
# Correct line
c = cv2.VideoCapture(0)
# Incorrect line
i = cv2.ThisDoesntExist(0)

Removing /usr/local/lib/python3.10/dist-packages/cv2/__init__.py resolves the issue

Configuration

No response

Command used

pylint demo.py

Pylint output

************* Module demo
demo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
demo.py:4:4: E1101: Module 'cv2' has no 'VideoCapture' member (no-member)
demo.py:6:4: E1101: Module 'cv2' has no 'ThisDoesntExist' member (no-member)

Expected behavior

************* Module demo
demo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
demo.py:6:4: E1101: Module 'cv2' has no 'ThisDoesntExist' member (no-member)

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]

OS / Environment

Ubuntu 22.04

Additional dependencies

opencv-python==4.8.1.78

Metadata

Metadata

Assignees

No one assigned

    Labels

    Blocked 🚧Blocked by a particular issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions