Search code examples
pythonvisual-studio-codepylint

Why Pylint says numpy.random does not have 'normal' member since it does?


enter image description here

This code can run but got a error notation from vscode.


Solution

  • Pylint is a static checker but NumPy does dynamic imports of sub-modules such as random. This is the relevant part of the numpy/__init__.py:

    from . import random
    # skipped lines
    __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
    

    In numpy/random.__init__.py you can find this line:

    from .info import __doc__, __all__
    

    Following this track further numpy/random/info.py contains:

    __all__ = [
        # skipped lines
        'normal',
        # skipped lines
    ]
    

    The __init__.py is executed during the first import of numpy. The list __all__ contains the names that numpy exposes. This list is extended at run time and hence, cannot really statically be check by PyLint.

    There are different ways to turn the check of NumPy members off.