The following issues were found

numpy/tests/test_numpy_version.py
5 issues
Using deprecated method assert_()
Error

Line: 34 Column: 5

                  else:
        res = re.match(version_pattern + dev_suffix + '$', np.__version__)

    assert_(res is not None, np.__version__)


def test_short_version():
    # Check numpy.short_version actually exists
    if np.version.release:

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 40 Column: 9

              def test_short_version():
    # Check numpy.short_version actually exists
    if np.version.release:
        assert_(np.__version__ == np.version.short_version,
                "short_version mismatch in release version")
    else:
        assert_(np.__version__.split("+")[0] == np.version.short_version,
                "short_version mismatch in development version")

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 43 Column: 9

                      assert_(np.__version__ == np.version.short_version,
                "short_version mismatch in release version")
    else:
        assert_(np.__version__.split("+")[0] == np.version.short_version,
                "short_version mismatch in development version")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              from numpy.testing import assert_


def test_valid_numpy_version():
    # Verify that the numpy version is a valid one (no .post suffix or other
    # nonsense).  See gh-6431 for an issue caused by an invalid version.
    version_pattern = r"^[0-9]+\.[0-9]+\.[0-9]+(a[0-9]|b[0-9]|rc[0-9]|)"
    dev_suffix = r"(\.dev0|)(\+[0-9]*\.g[0-9a-f]+|)"
    if np.version.release:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 37 Column: 1

                  assert_(res is not None, np.__version__)


def test_short_version():
    # Check numpy.short_version actually exists
    if np.version.release:
        assert_(np.__version__ == np.version.short_version,
                "short_version mismatch in release version")
    else:

            

Reported by Pylint.

numpy/typing/tests/data/fail/random.py
4 issues
Value 'np.ndarray' is unsubscriptable
Error

Line: 5 Column: 17

              from typing import Any, List

SEED_FLOAT: float = 457.3
SEED_ARR_FLOAT: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0, 2, 3, 4])
SEED_ARRLIKE_FLOAT: List[float] = [1.0, 2.0, 3.0, 4.0]
SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)
SEED_STR: str = "String seeding not allowed"
# default rng
np.random.default_rng(SEED_FLOAT)  # E: incompatible type

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from typing import Any, List

SEED_FLOAT: float = 457.3
SEED_ARR_FLOAT: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0, 2, 3, 4])
SEED_ARRLIKE_FLOAT: List[float] = [1.0, 2.0, 3.0, 4.0]
SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)
SEED_STR: str = "String seeding not allowed"
# default rng

            

Reported by Pylint.

standard import "from typing import Any, List" should be placed before "import numpy as np"
Error

Line: 2 Column: 1

              import numpy as np
from typing import Any, List

SEED_FLOAT: float = 457.3
SEED_ARR_FLOAT: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0, 2, 3, 4])
SEED_ARRLIKE_FLOAT: List[float] = [1.0, 2.0, 3.0, 4.0]
SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)
SEED_STR: str = "String seeding not allowed"
# default rng

            

Reported by Pylint.

Module 'numpy.random.bit_generator' has no 'SeedSequence' member, but source is unavailable. Consider adding this module to extension-pkg-whitelist if you want to perform analysis based on run-time introspection of living objects.
Error

Line: 22 Column: 11

              np.random.SeedSequence(SEED_SEED_SEQ)  # E: incompatible type
np.random.SeedSequence(SEED_STR)  # E: incompatible type

seed_seq: np.random.bit_generator.SeedSequence = np.random.SeedSequence()
seed_seq.spawn(11.5)  # E: incompatible type
seed_seq.generate_state(3.14)  # E: incompatible type
seed_seq.generate_state(3, np.uint8)  # E: incompatible type
seed_seq.generate_state(3, "uint8")  # E: incompatible type
seed_seq.generate_state(3, "u1")  # E: incompatible type

            

Reported by Pylint.

numpy/testing/tests/test_doctesting.py
4 issues
Unable to import 'nose'
Error

Line: 54 Column: 5

              
if __name__ == '__main__':
    # Run tests outside numpy test rig
    import nose
    from numpy.testing.noseclasses import NumpyDoctest
    argv = ['', __file__, '--with-numpydoctest']
    nose.core.TestProgram(argv=argv, addplugins=[NumpyDoctest()])

            

Reported by Pylint.

No name 'noseclasses' in module 'numpy.testing'
Error

Line: 55 Column: 5

              if __name__ == '__main__':
    # Run tests outside numpy test rig
    import nose
    from numpy.testing.noseclasses import NumpyDoctest
    argv = ['', __file__, '--with-numpydoctest']
    nose.core.TestProgram(argv=argv, addplugins=[NumpyDoctest()])

            

Reported by Pylint.

Unable to import 'numpy.testing.noseclasses'
Error

Line: 55 Column: 5

              if __name__ == '__main__':
    # Run tests outside numpy test rig
    import nose
    from numpy.testing.noseclasses import NumpyDoctest
    argv = ['', __file__, '--with-numpydoctest']
    nose.core.TestProgram(argv=argv, addplugins=[NumpyDoctest()])

            

Reported by Pylint.

FIXME: None of these tests is run, because 'check' is not a recognized
Error

Line: 4 Column: 2

              """ Doctests for NumPy-specific nose/doctest modifications

"""
#FIXME: None of these tests is run, because 'check' is not a recognized
# testing prefix.

# try the #random directive on the output line
def check_random_directive():
    '''

            

Reported by Pylint.

numpy/distutils/command/install_data.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              import sys
have_setuptools = ('setuptools' in sys.modules)

from distutils.command.install_data import install_data as old_install_data

#data installer with improved intelligence over distutils
#data files are copied into the project directory instead
#of willy-nilly
class install_data (old_install_data):

            

Reported by Pylint.

Import "from distutils.command.install_data import install_data as old_install_data" should be placed at the top of the module
Error

Line: 4 Column: 1

              import sys
have_setuptools = ('setuptools' in sys.modules)

from distutils.command.install_data import install_data as old_install_data

#data installer with improved intelligence over distutils
#data files are copied into the project directory instead
#of willy-nilly
class install_data (old_install_data):

            

Reported by Pylint.

Class name "install_data" doesn't conform to PascalCase naming style
Error

Line: 9 Column: 1

              #data installer with improved intelligence over distutils
#data files are copied into the project directory instead
#of willy-nilly
class install_data (old_install_data):

    def run(self):
        old_install_data.run(self)

        if have_setuptools:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              #data installer with improved intelligence over distutils
#data files are copied into the project directory instead
#of willy-nilly
class install_data (old_install_data):

    def run(self):
        old_install_data.run(self)

        if have_setuptools:

            

Reported by Pylint.

numpy/typing/tests/data/pass/ufunclike.py
4 issues
Value 'np.ndarray' is unsubscriptable
Error

Line: 16 Column: 28

                  def __ge__(self, value: object) -> bool:
        return True

    def __array__(self) -> np.ndarray[Any, np.dtype[np.object_]]:
        ret = np.empty((), dtype=object)
        ret[()] = self
        return ret



            

Reported by Pylint.

Value 'np.ndarray' is unsubscriptable
Error

Line: 27 Column: 7

              AR_LIKE_i = [1, 2, 3]
AR_LIKE_f = [1.0, 2.0, 3.0]
AR_LIKE_O = [Object(), Object(), Object()]
AR_U: np.ndarray[Any, np.dtype[np.str_]] = np.zeros(3, dtype="U5")

np.fix(AR_LIKE_b)
np.fix(AR_LIKE_u)
np.fix(AR_LIKE_i)
np.fix(AR_LIKE_f)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import annotations
from typing import Any
import numpy as np


class Object:
    def __ceil__(self) -> Object:
        return self


            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              import numpy as np


class Object:
    def __ceil__(self) -> Object:
        return self

    def __floor__(self) -> Object:
        return self

            

Reported by Pylint.

numpy/core/_string_helpers.py
4 issues
Argument name "s" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

              UPPER_TABLE = "".join(_all_chars[:97] + _ascii_upper + _all_chars[97+26:])


def english_lower(s):
    """ Apply English case rules to convert ASCII strings to all lower case.

    This is an internal utility function to replace calls to str.lower() such
    that we can avoid changing behavior with changing locales. In particular,
    Turkish has distinct dotted and dotless variants of the Latin letter "I" in

            

Reported by Pylint.

Argument name "s" doesn't conform to snake_case naming style
Error

Line: 44 Column: 1

                  return lowered


def english_upper(s):
    """ Apply English case rules to convert ASCII strings to all upper case.

    This is an internal utility function to replace calls to str.upper() such
    that we can avoid changing behavior with changing locales. In particular,
    Turkish has distinct dotted and dotless variants of the Latin letter "I" in

            

Reported by Pylint.

Argument name "s" doesn't conform to snake_case naming style
Error

Line: 72 Column: 1

                  return uppered


def english_capitalize(s):
    """ Apply English case rules to convert the first character of an ASCII
    string to upper case.

    This is an internal utility function to replace calls to str.capitalize()
    such that we can avoid changing behavior with changing locales.

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 97 Column: 5

                  >>> english_capitalize('')
    ''
    """
    if s:
        return english_upper(s[0]) + s[1:]
    else:
        return s

            

Reported by Pylint.

numpy/distutils/tests/test_from_template.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              
from numpy.distutils.from_template import process_str
from numpy.testing import assert_equal


pyf_src = """
python module foo
    <_rd=real,double precision>
    interface

            

Reported by Pylint.

Constant name "pyf_src" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              from numpy.testing import assert_equal


pyf_src = """
python module foo
    <_rd=real,double precision>
    interface
        subroutine <s,d>foosub(tol)
            <_rd>, intent(in,out) :: tol

            

Reported by Pylint.

Constant name "expected_pyf" doesn't conform to UPPER_CASE naming style
Error

Line: 17 Column: 1

              end python module foo
"""

expected_pyf = """
python module foo
    interface
        subroutine sfoosub(tol)
            real, intent(in,out) :: tol
        end subroutine sfoosub

            

Reported by Pylint.

Argument name "s" doesn't conform to snake_case naming style
Error

Line: 31 Column: 1

              """


def normalize_whitespace(s):
    """
    Remove leading and trailing whitespace, and convert internal
    stretches of whitespace to a single space.
    """
    return ' '.join(s.split())

            

Reported by Pylint.

numpy/distutils/fcompiler/fujitsu.py
4 issues
Method 'find_library_file' is abstract in class 'CCompiler' but is not overridden
Error

Line: 11 Column: 1

              
compilers = ['FujitsuFCompiler']

class FujitsuFCompiler(FCompiler):
    compiler_type = 'fujitsu'
    description = 'Fujitsu Fortran Compiler'

    possible_executables = ['frt']
    version_pattern = r'frt \(FRT\) (?P<version>[a-z\d.]+)'

            

Reported by Pylint.

Method 'wrap_unlinkable_objects' is abstract in class 'FCompiler' but is not overridden
Error

Line: 11 Column: 1

              
compilers = ['FujitsuFCompiler']

class FujitsuFCompiler(FCompiler):
    compiler_type = 'fujitsu'
    description = 'Fujitsu Fortran Compiler'

    possible_executables = ['frt']
    version_pattern = r'frt \(FRT\) (?P<version>[a-z\d.]+)'

            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 37 Column: 42

                      return ['-O3']
    def get_flags_debug(self):
        return ['-g']
    def runtime_library_dir_option(self, dir):
        return f'-Wl,-rpath={dir}'
    def get_libraries(self):
        return ['fj90f', 'fj90i', 'fjsrcinfo']

if __name__ == '__main__':

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              
compilers = ['FujitsuFCompiler']

class FujitsuFCompiler(FCompiler):
    compiler_type = 'fujitsu'
    description = 'Fujitsu Fortran Compiler'

    possible_executables = ['frt']
    version_pattern = r'frt \(FRT\) (?P<version>[a-z\d.]+)'

            

Reported by Pylint.

numpy/core/src/multiarray/nditer_impl.h
4 issues
printf - If format strings can be influenced by an attacker, they can be exploited
Security

Line: 57 Column: 34 CWE codes: 134
Suggestion: Use a constant for the format specification

              
#if NPY_IT_DBG_TRACING
#define NPY_IT_DBG_PRINT(s) printf("%s", s)
#define NPY_IT_DBG_PRINT1(s, p1) printf(s, p1)
#define NPY_IT_DBG_PRINT2(s, p1, p2) printf(s, p1, p2)
#define NPY_IT_DBG_PRINT3(s, p1, p2, p3) printf(s, p1, p2, p3)
#else
#define NPY_IT_DBG_PRINT(s)
#define NPY_IT_DBG_PRINT1(s, p1)

            

Reported by FlawFinder.

printf - If format strings can be influenced by an attacker, they can be exploited
Security

Line: 58 Column: 38 CWE codes: 134
Suggestion: Use a constant for the format specification

              #if NPY_IT_DBG_TRACING
#define NPY_IT_DBG_PRINT(s) printf("%s", s)
#define NPY_IT_DBG_PRINT1(s, p1) printf(s, p1)
#define NPY_IT_DBG_PRINT2(s, p1, p2) printf(s, p1, p2)
#define NPY_IT_DBG_PRINT3(s, p1, p2, p3) printf(s, p1, p2, p3)
#else
#define NPY_IT_DBG_PRINT(s)
#define NPY_IT_DBG_PRINT1(s, p1)
#define NPY_IT_DBG_PRINT2(s, p1, p2)

            

Reported by FlawFinder.

printf - If format strings can be influenced by an attacker, they can be exploited
Security

Line: 59 Column: 42 CWE codes: 134
Suggestion: Use a constant for the format specification

              #define NPY_IT_DBG_PRINT(s) printf("%s", s)
#define NPY_IT_DBG_PRINT1(s, p1) printf(s, p1)
#define NPY_IT_DBG_PRINT2(s, p1, p2) printf(s, p1, p2)
#define NPY_IT_DBG_PRINT3(s, p1, p2, p3) printf(s, p1, p2, p3)
#else
#define NPY_IT_DBG_PRINT(s)
#define NPY_IT_DBG_PRINT1(s, p1)
#define NPY_IT_DBG_PRINT2(s, p1, p2)
#define NPY_IT_DBG_PRINT3(s, p1, p2, p3)

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 237 Column: 19 CWE codes: 120 20

              /* Internal-only BUFFERDATA MEMBER ACCESS */

struct NpyIter_TransferInfo_tag {
    NPY_cast_info read;
    NPY_cast_info write;
    /* Probably unnecessary, but make sure what follows is intp aligned: */
    npy_intp _unused_ensure_alignment[];
};


            

Reported by FlawFinder.

numpy/typing/tests/data/pass/ufuncs.py
4 issues
Statement seems to have no effect
Error

Line: 13 Column: 1

              # re-enable this we can infer the exact return type of `np.sin(...)`.
#
# np.sin(1) + np.sin(1)
np.sin.types[0]
np.sin.__name__
np.sin.__doc__

np.abs(np.array([1]))

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 14 Column: 1

              #
# np.sin(1) + np.sin(1)
np.sin.types[0]
np.sin.__name__
np.sin.__doc__

np.abs(np.array([1]))

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 15 Column: 1

              # np.sin(1) + np.sin(1)
np.sin.types[0]
np.sin.__name__
np.sin.__doc__

np.abs(np.array([1]))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np

np.sin(1)
np.sin([1, 2, 3])
np.sin(1, out=np.empty(1))
np.matmul(np.ones((2, 2, 2)), np.ones((2, 2, 2)), axes=[(0, 1), (0, 1), (0, 1)])
np.sin(1, signature="D->D")
np.sin(1, extobj=[16, 1, lambda: None])
# NOTE: `np.generic` subclasses are not guaranteed to support addition;

            

Reported by Pylint.