The following issues were found

tools/npy_tempita/compat3.py
26 issues
Undefined variable 'basestring'
Error

Line: 17 Column: 19

                      return d.iteritems(**kw)

    b = bytes = str
    basestring_ = basestring

else:

    def b(s):
        if isinstance(s, str):

            

Reported by Pylint.

Undefined variable 'unicode'
Error

Line: 38 Column: 32

              
def is_unicode(obj):
    if sys.version_info[0] < 3:
        return isinstance(obj, unicode)
    else:
        return isinstance(obj, str)


def coerce_text(v):

            

Reported by Pylint.

Undefined variable 'unicode'
Error

Line: 50 Column: 20

                      else:
            attr = '__str__'
        if hasattr(v, attr):
            return unicode(v)
        else:
            return bytes(v)
    return v

            

Reported by Pylint.

Redefining built-in 'next'
Error

Line: 10 Column: 5

              
if sys.version_info[0] < 3:

    def next(obj):
        return obj.next()

    def iteritems(d, **kw):
        return d.iteritems(**kw)


            

Reported by Pylint.

Redefining built-in 'bytes'
Error

Line: 16 Column: 9

                  def iteritems(d, **kw):
        return d.iteritems(**kw)

    b = bytes = str
    basestring_ = basestring

else:

    def b(s):

            

Reported by Pylint.

Assigning the same variable 'next' to itself
Error

Line: 29 Column: 5

                  def iteritems(d, **kw):
        return iter(d.items(**kw))

    next = next
    basestring_ = (bytes, str)
    bytes = bytes

text = str


            

Reported by Pylint.

Assigning the same variable 'bytes' to itself
Error

Line: 31 Column: 5

              
    next = next
    basestring_ = (bytes, str)
    bytes = bytes

text = str


def is_unicode(obj):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import sys

__all__ = ['PY3', 'b', 'basestring_', 'bytes', 'next', 'is_unicode',
           'iteritems']

PY3 = True if sys.version_info[0] >= 3 else False

if sys.version_info[0] < 3:


            

Reported by Pylint.

The if expression can be replaced with 'test'
Error

Line: 6 Column: 7

              __all__ = ['PY3', 'b', 'basestring_', 'bytes', 'next', 'is_unicode',
           'iteritems']

PY3 = True if sys.version_info[0] >= 3 else False

if sys.version_info[0] < 3:

    def next(obj):
        return obj.next()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

              
if sys.version_info[0] < 3:

    def next(obj):
        return obj.next()

    def iteritems(d, **kw):
        return d.iteritems(**kw)


            

Reported by Pylint.

numpy/tests/test_matlib.py
26 issues
Using deprecated method assert_()
Error

Line: 7 Column: 5

              
def test_empty():
    x = numpy.matlib.empty((2,))
    assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))

def test_ones():
    assert_array_equal(numpy.matlib.ones((2, 3)),
                       np.matrix([[ 1.,  1.,  1.],

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 8 Column: 5

              def test_empty():
    x = numpy.matlib.empty((2,))
    assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))

def test_ones():
    assert_array_equal(numpy.matlib.ones((2, 3)),
                       np.matrix([[ 1.,  1.,  1.],
                                 [ 1.,  1.,  1.]]))

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 46 Column: 5

              def test_rand():
    x = numpy.matlib.rand(3)
    # check matrix type, array would have shape (3,)
    assert_(x.ndim == 2)

def test_randn():
    x = np.matlib.randn(3)
    # check matrix type, array would have shape (3,)
    assert_(x.ndim == 2)

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 51 Column: 5

              def test_randn():
    x = np.matlib.randn(3)
    # check matrix type, array would have shape (3,)
    assert_(x.ndim == 2)

def test_repmat():
    a1 = np.arange(4)
    x = numpy.matlib.repmat(a1, 2, 2)
    y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import numpy.matlib
from numpy.testing import assert_array_equal, assert_

def test_empty():
    x = numpy.matlib.empty((2,))
    assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              import numpy.matlib
from numpy.testing import assert_array_equal, assert_

def test_empty():
    x = numpy.matlib.empty((2,))
    assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))

def test_ones():

            

Reported by Pylint.

Variable name "x" doesn't conform to snake_case naming style
Error

Line: 6 Column: 5

              from numpy.testing import assert_array_equal, assert_

def test_empty():
    x = numpy.matlib.empty((2,))
    assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))

def test_ones():
    assert_array_equal(numpy.matlib.ones((2, 3)),

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

                  assert_(isinstance(x, np.matrix))
    assert_(x.shape, (1, 2))

def test_ones():
    assert_array_equal(numpy.matlib.ones((2, 3)),
                       np.matrix([[ 1.,  1.,  1.],
                                 [ 1.,  1.,  1.]]))

    assert_array_equal(numpy.matlib.ones(2), np.matrix([[ 1.,  1.]]))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              
    assert_array_equal(numpy.matlib.ones(2), np.matrix([[ 1.,  1.]]))

def test_zeros():
    assert_array_equal(numpy.matlib.zeros((2, 3)),
                       np.matrix([[ 0.,  0.,  0.],
                                 [ 0.,  0.,  0.]]))

    assert_array_equal(numpy.matlib.zeros(2), np.matrix([[ 0.,  0.]]))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              
    assert_array_equal(numpy.matlib.zeros(2), np.matrix([[ 0.,  0.]]))

def test_identity():
    x = numpy.matlib.identity(2, dtype=int)
    assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))

def test_eye():
    xc = numpy.matlib.eye(3, k=1, dtype=int)

            

Reported by Pylint.

numpy/matrixlib/tests/test_regression.py
26 issues
Module 'numpy.random' has no 'uniform' member
Error

Line: 29 Column: 25

              
    def test_matrix_std_argmax(self):
        # Ticket #83
        x = np.asmatrix(np.random.uniform(0, 1, (3, 3)))
        assert_equal(x.std().shape, ())
        assert_equal(x.argmax().shape, ())

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 14 Column: 9

                  def test_matrix_properties(self):
        # Ticket #125
        a = np.matrix([1.0], dtype=float)
        assert_(type(a.real) is np.matrix)
        assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 15 Column: 9

                      # Ticket #125
        a = np.matrix([1.0], dtype=float)
        assert_(type(a.real) is np.matrix)
        assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)

    def test_matrix_multiply_by_1d_vector(self):

            

Reported by Pylint.

Possible unbalanced tuple unpacking with sequence defined at line 100 of : left side has 2 label(s), right side has 1 value(s)
Error

Line: 16 Column: 9

                      a = np.matrix([1.0], dtype=float)
        assert_(type(a.real) is np.matrix)
        assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)

    def test_matrix_multiply_by_1d_vector(self):
        # Ticket #473

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 17 Column: 9

                      assert_(type(a.real) is np.matrix)
        assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)

    def test_matrix_multiply_by_1d_vector(self):
        # Ticket #473
        def mul():

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 18 Column: 9

                      assert_(type(a.imag) is np.matrix)
        c, d = np.matrix([0.0]).nonzero()
        assert_(type(c) is np.ndarray)
        assert_(type(d) is np.ndarray)

    def test_matrix_multiply_by_1d_vector(self):
        # Ticket #473
        def mul():
            np.mat(np.eye(2))*np.ones(2)

            

Reported by Pylint.

Expression "np.mat(np.eye(2)) * np.ones(2)" is assigned to nothing
Error

Line: 23 Column: 13

                  def test_matrix_multiply_by_1d_vector(self):
        # Ticket #473
        def mul():
            np.mat(np.eye(2))*np.ones(2)

        assert_raises(ValueError, mul)

    def test_matrix_std_argmax(self):
        # Ticket #83

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from numpy.testing import assert_, assert_equal, assert_raises


class TestRegression:
    def test_kron_matrix(self):
        # Ticket #71
        x = np.matrix('[1 0; 1 0]')
        assert_equal(type(np.kron(x, x)), type(x))

            

Reported by Pylint.

Missing class docstring
Error

Line: 5 Column: 1

              from numpy.testing import assert_, assert_equal, assert_raises


class TestRegression:
    def test_kron_matrix(self):
        # Ticket #71
        x = np.matrix('[1 0; 1 0]')
        assert_equal(type(np.kron(x, x)), type(x))


            

Reported by Pylint.

Method could be a function
Error

Line: 6 Column: 5

              

class TestRegression:
    def test_kron_matrix(self):
        # Ticket #71
        x = np.matrix('[1 0; 1 0]')
        assert_equal(type(np.kron(x, x)), type(x))

    def test_matrix_properties(self):

            

Reported by Pylint.

numpy/typing/_extended_precision.py
25 issues
Attempted relative import beyond top-level package
Error

Line: 10 Column: 1

              from typing import TYPE_CHECKING

import numpy as np
from . import (
    _80Bit,
    _96Bit,
    _128Bit,
    _256Bit,
)

            

Reported by Pylint.

Value 'np.unsignedinteger' is unsubscriptable
Error

Line: 18 Column: 15

              )

if TYPE_CHECKING:
    uint128 = np.unsignedinteger[_128Bit]
    uint256 = np.unsignedinteger[_256Bit]
    int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]

            

Reported by Pylint.

Value 'np.unsignedinteger' is unsubscriptable
Error

Line: 19 Column: 15

              
if TYPE_CHECKING:
    uint128 = np.unsignedinteger[_128Bit]
    uint256 = np.unsignedinteger[_256Bit]
    int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]

            

Reported by Pylint.

Value 'np.signedinteger' is unsubscriptable
Error

Line: 20 Column: 14

              if TYPE_CHECKING:
    uint128 = np.unsignedinteger[_128Bit]
    uint256 = np.unsignedinteger[_256Bit]
    int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]

            

Reported by Pylint.

Value 'np.signedinteger' is unsubscriptable
Error

Line: 21 Column: 14

                  uint128 = np.unsignedinteger[_128Bit]
    uint256 = np.unsignedinteger[_256Bit]
    int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]

            

Reported by Pylint.

Value 'np.floating' is unsubscriptable
Error

Line: 22 Column: 15

                  uint256 = np.unsignedinteger[_256Bit]
    int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]
    complex192 = np.complexfloating[_96Bit, _96Bit]

            

Reported by Pylint.

Value 'np.floating' is unsubscriptable
Error

Line: 23 Column: 15

                  int128 = np.signedinteger[_128Bit]
    int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]
    complex192 = np.complexfloating[_96Bit, _96Bit]
    complex256 = np.complexfloating[_128Bit, _128Bit]

            

Reported by Pylint.

Value 'np.floating' is unsubscriptable
Error

Line: 24 Column: 16

                  int256 = np.signedinteger[_256Bit]
    float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]
    complex192 = np.complexfloating[_96Bit, _96Bit]
    complex256 = np.complexfloating[_128Bit, _128Bit]
    complex512 = np.complexfloating[_256Bit, _256Bit]

            

Reported by Pylint.

Value 'np.floating' is unsubscriptable
Error

Line: 25 Column: 16

                  float80 = np.floating[_80Bit]
    float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]
    complex192 = np.complexfloating[_96Bit, _96Bit]
    complex256 = np.complexfloating[_128Bit, _128Bit]
    complex512 = np.complexfloating[_256Bit, _256Bit]
else:

            

Reported by Pylint.

Value 'np.complexfloating' is unsubscriptable
Error

Line: 26 Column: 18

                  float96 = np.floating[_96Bit]
    float128 = np.floating[_128Bit]
    float256 = np.floating[_256Bit]
    complex160 = np.complexfloating[_80Bit, _80Bit]
    complex192 = np.complexfloating[_96Bit, _96Bit]
    complex256 = np.complexfloating[_128Bit, _128Bit]
    complex512 = np.complexfloating[_256Bit, _256Bit]
else:
    uint128 = Any

            

Reported by Pylint.

numpy/distutils/command/__init__.py
25 issues
Undefined variable 'np'
Error

Line: 8 Column: 9

              
"""
def test_na_writable_attributes_deletion():
    a = np.NA(2)
    attr =  ['payload', 'dtype']
    for s in attr:
        assert_raises(AttributeError, delattr, a, s)



            

Reported by Pylint.

Undefined variable 'assert_raises'
Error

Line: 11 Column: 9

                  a = np.NA(2)
    attr =  ['payload', 'dtype']
    for s in attr:
        assert_raises(AttributeError, delattr, a, s)


__revision__ = "$Id: __init__.py,v 1.3 2005/05/16 11:08:49 pearu Exp $"

distutils_all = [  #'build_py',

            

Reported by Pylint.

Undefined variable name 'clean' in __all__
Error

Line: 17 Column: 20

              __revision__ = "$Id: __init__.py,v 1.3 2005/05/16 11:08:49 pearu Exp $"

distutils_all = [  #'build_py',
                   'clean',
                   'install_clib',
                   'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',

            

Reported by Pylint.

Undefined variable name 'install_clib' in __all__
Error

Line: 18 Column: 20

              
distutils_all = [  #'build_py',
                   'clean',
                   'install_clib',
                   'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',
                ]

            

Reported by Pylint.

Undefined variable name 'install_scripts' in __all__
Error

Line: 19 Column: 20

              distutils_all = [  #'build_py',
                   'clean',
                   'install_clib',
                   'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',
                ]


            

Reported by Pylint.

Undefined variable name 'bdist' in __all__
Error

Line: 20 Column: 20

                                 'clean',
                   'install_clib',
                   'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',
                ]

__import__('distutils.command', globals(), locals(), distutils_all)

            

Reported by Pylint.

Undefined variable name 'bdist_dumb' in __all__
Error

Line: 21 Column: 20

                                 'install_clib',
                   'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',
                ]

__import__('distutils.command', globals(), locals(), distutils_all)


            

Reported by Pylint.

Undefined variable name 'bdist_wininst' in __all__
Error

Line: 22 Column: 20

                                 'install_scripts',
                   'bdist',
                   'bdist_dumb',
                   'bdist_wininst',
                ]

__import__('distutils.command', globals(), locals(), distutils_all)

__all__ = ['build',

            

Reported by Pylint.

Undefined variable name 'build' in __all__
Error

Line: 27 Column: 12

              
__import__('distutils.command', globals(), locals(), distutils_all)

__all__ = ['build',
           'config_compiler',
           'config',
           'build_src',
           'build_py',
           'build_ext',

            

Reported by Pylint.

Undefined variable name 'config_compiler' in __all__
Error

Line: 28 Column: 12

              __import__('distutils.command', globals(), locals(), distutils_all)

__all__ = ['build',
           'config_compiler',
           'config',
           'build_src',
           'build_py',
           'build_ext',
           'build_clib',

            

Reported by Pylint.

numpy/typing/tests/test_generic_alias.py
25 issues
Unable to import 'pytest'
Error

Line: 9 Column: 1

              import weakref
from typing import TypeVar, Any, Callable, Tuple, Type, Union

import pytest
import numpy as np
from numpy.typing._generic_alias import _GenericAlias

ScalarType = TypeVar("ScalarType", bound=np.generic, covariant=True)
T1 = TypeVar("T1")

            

Reported by Pylint.

Module 'types' has no 'GenericAlias' member
Error

Line: 20 Column: 17

              NDArray = _GenericAlias(np.ndarray, (Any, DType))

if sys.version_info >= (3, 9):
    DType_ref = types.GenericAlias(np.dtype, (ScalarType,))
    NDArray_ref = types.GenericAlias(np.ndarray, (Any, DType_ref))
    FuncType = Callable[[Union[_GenericAlias, types.GenericAlias]], Any]
else:
    DType_ref = Any
    NDArray_ref = Any

            

Reported by Pylint.

Module 'types' has no 'GenericAlias' member
Error

Line: 21 Column: 19

              
if sys.version_info >= (3, 9):
    DType_ref = types.GenericAlias(np.dtype, (ScalarType,))
    NDArray_ref = types.GenericAlias(np.ndarray, (Any, DType_ref))
    FuncType = Callable[[Union[_GenericAlias, types.GenericAlias]], Any]
else:
    DType_ref = Any
    NDArray_ref = Any
    FuncType = Callable[[_GenericAlias], Any]

            

Reported by Pylint.

Module 'types' has no 'GenericAlias' member
Error

Line: 22 Column: 47

              if sys.version_info >= (3, 9):
    DType_ref = types.GenericAlias(np.dtype, (ScalarType,))
    NDArray_ref = types.GenericAlias(np.ndarray, (Any, DType_ref))
    FuncType = Callable[[Union[_GenericAlias, types.GenericAlias]], Any]
else:
    DType_ref = Any
    NDArray_ref = Any
    FuncType = Callable[[_GenericAlias], Any]


            

Reported by Pylint.

Access to a protected member _ATTR_EXCEPTIONS of a client class
Error

Line: 28 Column: 47

                  NDArray_ref = Any
    FuncType = Callable[[_GenericAlias], Any]

GETATTR_NAMES = sorted(set(dir(np.ndarray)) - _GenericAlias._ATTR_EXCEPTIONS)

BUFFER = np.array([1], dtype=np.int64)
BUFFER.setflags(write=False)

def _get_subclass_mro(base: type) -> Tuple[type, ...]:

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 56 Column: 22

                      ("__reduce__", lambda n: n.__reduce__()[1:]),
        ("__reduce_ex__", lambda n: n.__reduce_ex__(1)[1:]),
        ("__mro_entries__", lambda n: n.__mro_entries__([object])),
        ("__hash__", lambda n: hash(n)),
        ("__repr__", lambda n: repr(n)),
        ("__getitem__", lambda n: n[np.float64]),
        ("__getitem__", lambda n: n[ScalarType][np.float64]),
        ("__getitem__", lambda n: n[Union[np.int64, ScalarType]][np.float64]),
        ("__getitem__", lambda n: n[Union[T1, T2]][np.float32, np.float64]),

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 57 Column: 22

                      ("__reduce_ex__", lambda n: n.__reduce_ex__(1)[1:]),
        ("__mro_entries__", lambda n: n.__mro_entries__([object])),
        ("__hash__", lambda n: hash(n)),
        ("__repr__", lambda n: repr(n)),
        ("__getitem__", lambda n: n[np.float64]),
        ("__getitem__", lambda n: n[ScalarType][np.float64]),
        ("__getitem__", lambda n: n[Union[np.int64, ScalarType]][np.float64]),
        ("__getitem__", lambda n: n[Union[T1, T2]][np.float32, np.float64]),
        ("__eq__", lambda n: n == n),

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 64 Column: 21

                      ("__getitem__", lambda n: n[Union[T1, T2]][np.float32, np.float64]),
        ("__eq__", lambda n: n == n),
        ("__ne__", lambda n: n != np.ndarray),
        ("__dir__", lambda n: dir(n)),
        ("__call__", lambda n: n((1,), np.int64, BUFFER)),
        ("__call__", lambda n: n(shape=(1,), dtype=np.int64, buffer=BUFFER)),
        ("subclassing", lambda n: _get_subclass_mro(n)),
        ("pickle", lambda n: n == pickle.loads(pickle.dumps(n))),
    ])

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 67 Column: 25

                      ("__dir__", lambda n: dir(n)),
        ("__call__", lambda n: n((1,), np.int64, BUFFER)),
        ("__call__", lambda n: n(shape=(1,), dtype=np.int64, buffer=BUFFER)),
        ("subclassing", lambda n: _get_subclass_mro(n)),
        ("pickle", lambda n: n == pickle.loads(pickle.dumps(n))),
    ])
    def test_pass(self, name: str, func: FuncType) -> None:
        """Compare `types.GenericAlias` with its numpy-based backport.


            

Reported by Pylint.

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Security blacklist

Line: 68
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle

                      ("__call__", lambda n: n((1,), np.int64, BUFFER)),
        ("__call__", lambda n: n(shape=(1,), dtype=np.int64, buffer=BUFFER)),
        ("subclassing", lambda n: _get_subclass_mro(n)),
        ("pickle", lambda n: n == pickle.loads(pickle.dumps(n))),
    ])
    def test_pass(self, name: str, func: FuncType) -> None:
        """Compare `types.GenericAlias` with its numpy-based backport.

        Checker whether ``func`` runs as intended and that both `GenericAlias`

            

Reported by Bandit.

numpy/core/tests/test_errstate.py
25 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
import sysconfig

import numpy as np
from numpy.testing import assert_, assert_raises

# The floating point emulation on ARM EABI systems lacking a hardware FPU is
# known to be buggy. This is an attempt to identify these hosts. It may not
# catch all possible cases, but it catches the known cases of gh-413 and

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 34 Column: 17

                          a = -np.arange(3)
            # This should work
            with np.errstate(divide='ignore'):
                a // 0
            # While this should fail!
            with assert_raises(FloatingPointError):
                a // 0
            # As should this, see gh-15562
            with assert_raises(FloatingPointError):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 37 Column: 17

                              a // 0
            # While this should fail!
            with assert_raises(FloatingPointError):
                a // 0
            # As should this, see gh-15562
            with assert_raises(FloatingPointError):
                a // a

    def test_errcall(self):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 40 Column: 17

                              a // 0
            # As should this, see gh-15562
            with assert_raises(FloatingPointError):
                a // a

    def test_errcall(self):
        def foo(*args):
            print(args)


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 48 Column: 13

              
        olderrcall = np.geterrcall()
        with np.errstate(call=foo):
            assert_(np.geterrcall() is foo, 'call is not foo')
            with np.errstate(call=None):
                assert_(np.geterrcall() is None, 'call is not None')
        assert_(np.geterrcall() is olderrcall, 'call is not olderrcall')

    def test_errstate_decorator(self):

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 50 Column: 17

                      with np.errstate(call=foo):
            assert_(np.geterrcall() is foo, 'call is not foo')
            with np.errstate(call=None):
                assert_(np.geterrcall() is None, 'call is not None')
        assert_(np.geterrcall() is olderrcall, 'call is not olderrcall')

    def test_errstate_decorator(self):
        @np.errstate(all='ignore')
        def foo():

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 51 Column: 9

                          assert_(np.geterrcall() is foo, 'call is not foo')
            with np.errstate(call=None):
                assert_(np.geterrcall() is None, 'call is not None')
        assert_(np.geterrcall() is olderrcall, 'call is not olderrcall')

    def test_errstate_decorator(self):
        @np.errstate(all='ignore')
        def foo():
            a = -np.arange(3)

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 57 Column: 13

                      @np.errstate(all='ignore')
        def foo():
            a = -np.arange(3)
            a // 0
            
        foo()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
import sysconfig

import numpy as np
from numpy.testing import assert_, assert_raises

# The floating point emulation on ARM EABI systems lacking a hardware FPU is
# known to be buggy. This is an attempt to identify these hosts. It may not
# catch all possible cases, but it catches the known cases of gh-413 and

            

Reported by Pylint.

standard import "import sysconfig" should be placed before "import pytest"
Error

Line: 2 Column: 1

              import pytest
import sysconfig

import numpy as np
from numpy.testing import assert_, assert_raises

# The floating point emulation on ARM EABI systems lacking a hardware FPU is
# known to be buggy. This is an attempt to identify these hosts. It may not
# catch all possible cases, but it catches the known cases of gh-413 and

            

Reported by Pylint.

benchmarks/benchmarks/bench_itemselection.py
25 issues
Attempted relative import beyond top-level package
Error

Line: 3 Column: 1

              from __future__ import absolute_import, division, print_function

from .common import Benchmark, TYPES1

import numpy as np


class Take(Benchmark):
    params = [

            

Reported by Pylint.

Unused argument 'mode'
Error

Line: 15 Column: 28

                      TYPES1]
    param_names = ["shape", "mode", "dtype"]

    def setup(self, shape, mode, dtype):
        self.arr = np.ones(shape, dtype)
        self.indices = np.arange(1000)

    def time_contiguous(self, shape, mode, dtype):
        self.arr.take(self.indices, axis=-2, mode=mode)

            

Reported by Pylint.

Attribute 'arr' defined outside __init__
Error

Line: 16 Column: 9

                  param_names = ["shape", "mode", "dtype"]

    def setup(self, shape, mode, dtype):
        self.arr = np.ones(shape, dtype)
        self.indices = np.arange(1000)

    def time_contiguous(self, shape, mode, dtype):
        self.arr.take(self.indices, axis=-2, mode=mode)


            

Reported by Pylint.

Attribute 'indices' defined outside __init__
Error

Line: 17 Column: 9

              
    def setup(self, shape, mode, dtype):
        self.arr = np.ones(shape, dtype)
        self.indices = np.arange(1000)

    def time_contiguous(self, shape, mode, dtype):
        self.arr.take(self.indices, axis=-2, mode=mode)



            

Reported by Pylint.

Unused argument 'shape'
Error

Line: 19 Column: 31

                      self.arr = np.ones(shape, dtype)
        self.indices = np.arange(1000)

    def time_contiguous(self, shape, mode, dtype):
        self.arr.take(self.indices, axis=-2, mode=mode)


class PutMask(Benchmark):
    params = [

            

Reported by Pylint.

Unused argument 'dtype'
Error

Line: 19 Column: 44

                      self.arr = np.ones(shape, dtype)
        self.indices = np.arange(1000)

    def time_contiguous(self, shape, mode, dtype):
        self.arr.take(self.indices, axis=-2, mode=mode)


class PutMask(Benchmark):
    params = [

            

Reported by Pylint.

Attribute 'vals' defined outside __init__
Error

Line: 31 Column: 13

              
    def setup(self, values_is_scalar, dtype):
        if values_is_scalar:
            self.vals = np.array(1., dtype=dtype)
        else:
            self.vals = np.ones(1000, dtype=dtype)

        self.arr = np.ones(1000, dtype=dtype)


            

Reported by Pylint.

Attribute 'vals' defined outside __init__
Error

Line: 33 Column: 13

                      if values_is_scalar:
            self.vals = np.array(1., dtype=dtype)
        else:
            self.vals = np.ones(1000, dtype=dtype)

        self.arr = np.ones(1000, dtype=dtype)

        self.dense_mask = np.ones(1000, dtype="bool")
        self.sparse_mask = np.zeros(1000, dtype="bool")

            

Reported by Pylint.

Attribute 'arr' defined outside __init__
Error

Line: 35 Column: 9

                      else:
            self.vals = np.ones(1000, dtype=dtype)

        self.arr = np.ones(1000, dtype=dtype)

        self.dense_mask = np.ones(1000, dtype="bool")
        self.sparse_mask = np.zeros(1000, dtype="bool")

    def time_dense(self, values_is_scalar, dtype):

            

Reported by Pylint.

Attribute 'dense_mask' defined outside __init__
Error

Line: 37 Column: 9

              
        self.arr = np.ones(1000, dtype=dtype)

        self.dense_mask = np.ones(1000, dtype="bool")
        self.sparse_mask = np.zeros(1000, dtype="bool")

    def time_dense(self, values_is_scalar, dtype):
        np.putmask(self.arr, self.dense_mask, self.vals)


            

Reported by Pylint.

numpy/f2py/tests/test_return_character.py
25 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from numpy import array
from numpy.testing import assert_
from . import util
import platform
IS_S390X = platform.machine() == 's390x'



            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 5 Column: 1

              
from numpy import array
from numpy.testing import assert_
from . import util
import platform
IS_S390X = platform.machine() == 's390x'


class TestReturnCharacter(util.F2PyTest):

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 14 Column: 13

              
    def check_function(self, t, tname):
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == b'2')
            r = t('ab')
            assert_(r == b'a', repr(r))
            r = t(array('ab'))
            assert_(r == b'a', repr(r))
            r = t(array(77, 'u1'))

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 16 Column: 13

                      if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == b'2')
            r = t('ab')
            assert_(r == b'a', repr(r))
            r = t(array('ab'))
            assert_(r == b'a', repr(r))
            r = t(array(77, 'u1'))
            assert_(r == b'M', repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 18 Column: 13

                          r = t('ab')
            assert_(r == b'a', repr(r))
            r = t(array('ab'))
            assert_(r == b'a', repr(r))
            r = t(array(77, 'u1'))
            assert_(r == b'M', repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 20 Column: 13

                          r = t(array('ab'))
            assert_(r == b'a', repr(r))
            r = t(array(77, 'u1'))
            assert_(r == b'M', repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('123456789abcdef') == b'123456789a')

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 24 Column: 13

                          #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('123456789abcdef') == b'123456789a')
        elif tname in ['t5', 's5']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('ab') == b'ab', repr(t('ab')))
            assert_(t('123456789abcdef') == b'12345')

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 25 Column: 13

                          #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('123456789abcdef') == b'123456789a')
        elif tname in ['t5', 's5']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('ab') == b'ab', repr(t('ab')))
            assert_(t('123456789abcdef') == b'12345')
        else:

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 27 Column: 13

                          assert_(t(23) == b'23', repr(t(23)))
            assert_(t('123456789abcdef') == b'123456789a')
        elif tname in ['t5', 's5']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('ab') == b'ab', repr(t('ab')))
            assert_(t('123456789abcdef') == b'12345')
        else:
            raise NotImplementedError


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 28 Column: 13

                          assert_(t('123456789abcdef') == b'123456789a')
        elif tname in ['t5', 's5']:
            assert_(t(23) == b'23', repr(t(23)))
            assert_(t('ab') == b'ab', repr(t('ab')))
            assert_(t('123456789abcdef') == b'12345')
        else:
            raise NotImplementedError



            

Reported by Pylint.

numpy/distutils/from_template.py
24 issues
Unused variable 'ext'
Error

Line: 251 Column: 16

                      outfile = sys.stdout
    else:
        fid = open(file, 'r')
        (base, ext) = os.path.splitext(file)
        newname = base
        outfile = open(newname, 'w')

    allstr = fid.read()
    writestr = process_str(allstr)

            

Reported by Pylint.

Variable name "m" doesn't conform to snake_case naming style
Error

Line: 67 Column: 9

                  spanlist = []
    ind = 0
    while True:
        m = routine_start_re.search(astr, ind)
        if m is None:
            break
        start = m.start()
        if function_start_re.match(astr, start, m.end()):
            while True:

            

Reported by Pylint.

Variable name "m" doesn't conform to snake_case naming style
Error

Line: 80 Column: 9

                              if astr[i:i+7]!='\n     $':
                    break
        start += 1
        m = routine_end_re.search(astr, m.end())
        ind = end = m and m.end()-1 or len(astr)
        spanlist.append((start, end))
    return spanlist

template_re = re.compile(r"<\s*(\w[\w\d]*)\s*>")

            

Reported by Pylint.

Consider using ternary (m.end() - 1 if m else len(astr))
Error

Line: 81 Column: 9

                                  break
        start += 1
        m = routine_end_re.search(astr, m.end())
        ind = end = m and m.end()-1 or len(astr)
        spanlist.append((start, end))
    return spanlist

template_re = re.compile(r"<\s*(\w[\w\d]*)\s*>")
named_re = re.compile(r"<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 89 Column: 1

              named_re = re.compile(r"<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>")
list_re = re.compile(r"<\s*((.*?))\s*>")

def find_repl_patterns(astr):
    reps = named_re.findall(astr)
    names = {}
    for rep in reps:
        name = rep[0].strip() or unique_key(names)
        repl = rep[1].replace(r'\,', '@comma@')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 99 Column: 1

                      names[name] = thelist
    return names

def find_and_remove_repl_patterns(astr):
    names = find_repl_patterns(astr)
    astr = re.subn(named_re, '', astr)[0]
    return astr, names

item_re = re.compile(r"\A\\(?P<index>\d+)\Z")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 105 Column: 1

                  return astr, names

item_re = re.compile(r"\A\\(?P<index>\d+)\Z")
def conv(astr):
    b = astr.split(',')
    l = [x.strip() for x in b]
    for i in range(len(l)):
        m = item_re.match(l[i])
        if m:

            

Reported by Pylint.

Variable name "b" doesn't conform to snake_case naming style
Error

Line: 106 Column: 5

              
item_re = re.compile(r"\A\\(?P<index>\d+)\Z")
def conv(astr):
    b = astr.split(',')
    l = [x.strip() for x in b]
    for i in range(len(l)):
        m = item_re.match(l[i])
        if m:
            j = int(m.group('index'))

            

Reported by Pylint.

Variable name "l" doesn't conform to snake_case naming style
Error

Line: 107 Column: 5

              item_re = re.compile(r"\A\\(?P<index>\d+)\Z")
def conv(astr):
    b = astr.split(',')
    l = [x.strip() for x in b]
    for i in range(len(l)):
        m = item_re.match(l[i])
        if m:
            j = int(m.group('index'))
            l[i] = l[j]

            

Reported by Pylint.

Consider using enumerate instead of iterating with range and len
Error

Line: 108 Column: 5

              def conv(astr):
    b = astr.split(',')
    l = [x.strip() for x in b]
    for i in range(len(l)):
        m = item_re.match(l[i])
        if m:
            j = int(m.group('index'))
            l[i] = l[j]
    return ','.join(l)

            

Reported by Pylint.