Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
n0n3m4 opened this issue Oct 24, 2023 · 2 comments · Fixed by pylint-dev/astroid#2375
Labels
Blocked 🚧 Blocked by a particular issue
Milestone

Comments

@n0n3m4
Copy link

n0n3m4 commented Oct 24, 2023

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
@n0n3m4 n0n3m4 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 24, 2023
@v-giacomini-nabla
Copy link

Another common library affected by this issue is alembic where op.py generates the functions and op.pyi is the stub for such functions.

My hack is to swap the order of .py and .pyi extensions at https://github.com/pylint-dev/astroid/blob/31ba1dbd8ae86b55330be861e37d6bc372d9a8a5/astroid/modutils.py#L47C42-L47C42

so that get_source_file() will return the .pyi file.

@jacobtylerwalls

This comment was marked as outdated.

@Pierre-Sassoulas Pierre-Sassoulas added Blocked 🚧 Blocked by a particular issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 23, 2024
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.1.0, 3.2.0 Feb 24, 2024
copybara-service bot pushed a commit to google-deepmind/tf2jax that referenced this issue Apr 25, 2024
copybara-service bot pushed a commit to google-deepmind/tf2jax that referenced this issue Apr 25, 2024
copybara-service bot pushed a commit to google-deepmind/tf2jax that referenced this issue Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked 🚧 Blocked by a particular issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants