Skip to content

you accidentally made __init__ anti-linter #131

Description

@kelvinwop

Expected behaviour

be detected by linter

Actual behaviour

not detected by linter

Steps to reproduce

  • install opencv-python
  • use vscode >extension microsoft python linter
  • try to use cv2 methods
  • RED SQUIGGLY LINES

I blame:

\cv2\__init__.py:

import importlib

from .cv2 import *
from .data import *

# wildcard import above does not import "private" variables like __version__
# this makes them available
globals().update(importlib.import_module('cv2.cv2').__dict__)

Activity

  1. skvark commented on Oct 13, 2018

    @skvark
    Member

    This seems to be a pylint issue. Add cv2 to the pylint extension package whitelist as suggested by this answer at Stack Overflow: https://stackoverflow.com/a/51916065/5795428

    The wildcard import code in the __init__ file is perfectly valid Python. There's nothing "anti-linter" in the file. The last line is a bit hacky, but as the comment implies, it's needed to expose members which are ignored by the wildcard import.

    I believe that the actual problem is related to the fact that the cv2 is binary extension module. For example Numpy behaves excatly the same way with pylint / vscode: https://stackoverflow.com/questions/20553551/how-do-i-get-pylint-to-recognize-numpy-members

  2. kelvinwop commented on Oct 14, 2018

    @kelvinwop
    Author

    Strange. Seems to work with numpy lol.

    Will add this link to the vscode issue

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

Metadata

Metadata

Assignees

No one assigned

    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