镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Pylint no-member and no-name-in-module warnings since version 4.6.0.66 #824

Open

Description

@robertschweizer

Note: Previously reported in #570, probably very related to #676.

Expected behaviour

Pylint was previously able to inspect cv2 member existence with the extension-pkg-whitelist parameter.

Actual behaviour

For opencv-python-4.6.0.66 (including the latest 4.7.0.72), pylint cannot inspect the members.

Workarounds

  1. Use older opencv-python version (e.g. 4.5.5.64)
  2. Set the generated-members=cv2.* pylint option (Use import cv2, not from cv2 import ..., suggested in cv2 module members are not recognized pylint-dev/pylint#2426)

Steps to reproduce

On Windows 10, Python 3.8 64bit, using Pylint 2.11.1:

"""Test module test.py"""
from cv2 import getStructuringElement, MORPH_ELLIPSE

a = getStructuringElement(MORPH_ELLIPSE, (3, 3))

With opencv-python-4.5.5.64:

$ pylint test.py --extension-pkg-whitelist=cv2 --unsafe-load-any-extension=y

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

With opencv-python-4.6.0.66 and the latest 4.7.0.72.:

$ pylint test.py --extension-pkg-whitelist=cv2 --unsafe-load-any-extension=y
************* Module test
test.py:2:0: E0611: No name 'getStructuringElement' in module 'cv2' (no-name-in-module)
test.py:2:0: E0611: No name 'MORPH_ELLIPSE' in module 'cv2' (no-name-in-module)

----------------------------------------------------------------------
Your code has been rated at -40.00/10 (previous run: 10.00/10, -50.00)
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python

Activity

  1. asmorkalov commented on Jun 23, 2023

    @asmorkalov
    Collaborator
  2. robertschweizer commented on Jul 27, 2023

    @robertschweizer
    Author

    Thanks for working on this @asmorkalov

    I tried with opencv-python-headless 4.8.0.74 and pylint 2.17.5. The pylint issue is not fixed.

    The new typing stubs work well though, mypy runs fine with the new opencv version.

    As a workaround, cv2 can be added to pylint's ignored-modules list. Mypy type checking has to be enough for cv2 calls then.

  3. jakeanq commented on Dec 4, 2023

    @jakeanq

    This issue is still present in opencv-python==4.8.1.78, linting with pylint==3.0.2 and using the example from above:

    ❯ pylint test_cv2.py --extension-pkg-whitelist=cv2 --unsafe-load-any-extension=y
    ************* Module test_cv2
    test_cv2.py:2:0: E0401: Unable to import 'cv2' (import-error)
    
    ------------------------------------------------------------------
    Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
    
    ❯ pip freeze
    astroid==3.0.1
    dill==0.3.7
    isort==5.12.0
    mccabe==0.7.0
    numpy==1.26.2
    opencv-python==4.8.1.78
    platformdirs==4.0.0
    pylint==3.0.2
    tomlkit==0.12.3
    
    ❯ python --version
    Python 3.11.5
    

    Looking at the PRs above, it looks like those are adding type stub files, however as far as I'm aware pylint will not use the type stub files, instead it prefers to be able to import the C extension and introspect it.

    Could we perhaps re-open the ticket? Or I can submit another one if that's preferable.

  4. MrTorstein commented on Jan 4, 2024

    @MrTorstein

    I also have the same problem, and would love for this issue to be reopened. Or for any new issue opened to be linked.

  5. self-assigned this
    on Jan 6, 2024
  6. OlliejED commented on Jun 11, 2024

    @OlliejED

    I am still experiencing this problem. Adding '--extension-pkg-whitelist=cv2' in my vscode settings.json does not work for me, I have to use '--generated-members=cv2.*'.
    However, this does not help on collaborative projects as other developers also need to add this to their settings.json, and the automatic linting tests need to have the '--generated-members' parameter for them to pass.

  7. Avasam commented on Aug 1, 2024

    @Avasam

    That sounds like a pylint issue, not an OpenCV one. Both mypy, pyright (and I'm sure more) can pickup on the stubs. Stubs should also always be prioritized over implementation when present.
    Possibly related: pylint-dev/pylint#9574

  8. asmorkalov commented on Sep 12, 2024

    @asmorkalov
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions