The following issues were found
numpy/typing/tests/data/fail/dtype.py
5 issues
Line: 1
Column: 1
import numpy as np
class Test1:
not_dtype = np.dtype(float)
class Test2:
dtype = float
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
class Test1:
not_dtype = np.dtype(float)
class Test2:
dtype = float
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
class Test1:
not_dtype = np.dtype(float)
class Test2:
dtype = float
Reported by Pylint.
Line: 8
Column: 1
not_dtype = np.dtype(float)
class Test2:
dtype = float
np.dtype(Test1()) # E: No overload variant of "dtype" matches
np.dtype(Test2()) # E: incompatible type
Reported by Pylint.
Line: 8
Column: 1
not_dtype = np.dtype(float)
class Test2:
dtype = float
np.dtype(Test1()) # E: No overload variant of "dtype" matches
np.dtype(Test2()) # E: incompatible type
Reported by Pylint.
numpy/ma/__init__.py
5 issues
Line: 43
Column: 1
"""
from . import core
from .core import *
from . import extras
from .extras import *
__all__ = ['core', 'extras']
Reported by Pylint.
Line: 46
Column: 1
from .core import *
from . import extras
from .extras import *
__all__ = ['core', 'extras']
__all__ += core.__all__
__all__ += extras.__all__
Reported by Pylint.
Line: 42
Column: 1
.. moduleauthor:: Jarrod Millman
"""
from . import core
from .core import *
from . import extras
from .extras import *
Reported by Pylint.
Line: 45
Column: 1
from . import core
from .core import *
from . import extras
from .extras import *
__all__ = ['core', 'extras']
__all__ += core.__all__
__all__ += extras.__all__
Reported by Pylint.
Line: 52
Column: 1
__all__ += core.__all__
__all__ += extras.__all__
from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester
Reported by Pylint.
numpy/distutils/command/build_py.py
5 issues
Line: 9
Column: 13
def run(self):
build_src = self.get_finalized_command('build_src')
if build_src.py_modules_dict and self.packages is None:
self.packages = list(build_src.py_modules_dict.keys ())
old_build_py.run(self)
def find_package_modules(self, package, package_dir):
modules = old_build_py.find_package_modules(self, package, package_dir)
Reported by Pylint.
Line: 30
Column: 3
return modules
# XXX: Fix find_source_files for item in py_modules such that item is 3-tuple
# and item[2] is source file.
Reported by Pylint.
Line: 1
Column: 1
from distutils.command.build_py import build_py as old_build_py
from numpy.distutils.misc_util import is_string
class build_py(old_build_py):
def run(self):
build_src = self.get_finalized_command('build_src')
if build_src.py_modules_dict and self.packages is None:
self.packages = list(build_src.py_modules_dict.keys ())
Reported by Pylint.
Line: 4
Column: 1
from distutils.command.build_py import build_py as old_build_py
from numpy.distutils.misc_util import is_string
class build_py(old_build_py):
def run(self):
build_src = self.get_finalized_command('build_src')
if build_src.py_modules_dict and self.packages is None:
self.packages = list(build_src.py_modules_dict.keys ())
Reported by Pylint.
Line: 4
Column: 1
from distutils.command.build_py import build_py as old_build_py
from numpy.distutils.misc_util import is_string
class build_py(old_build_py):
def run(self):
build_src = self.get_finalized_command('build_src')
if build_src.py_modules_dict and self.packages is None:
self.packages = list(build_src.py_modules_dict.keys ())
Reported by Pylint.
numpy/core/src/multiarray/compiled_base.c
5 issues
Line: 1540
Column: 25
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
} else {
for(int i = 0; i < 4; i++) {
for (int j = 0; j < vstep; j++) {
memcpy(outptr, (char*)&bb[i] + j, 1);
outptr += out_stride;
}
}
}
}
Reported by FlawFinder.
Line: 1553
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
npy_uint64 bb = npyv_tobits_b8(npyv_cmpneq_u8(va, v_zero));
for (int i = 0; i < vstep; ++i) {
memcpy(outptr, (char*)&bb + i, 1);
outptr += out_stride;
}
}
}
#endif
Reported by FlawFinder.
Line: 1842
Column: 21
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (order == 'b') {
for (index = 0; index < in_n; index++) {
npy_uint64 v = unpack_lookup_big[*inptr].uint64;
memcpy(outptr, &v, 8);
outptr += 8;
inptr += in_stride;
}
}
else {
Reported by FlawFinder.
Line: 1853
Column: 21
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (order != 'b') {
v = npy_bswap8(v);
}
memcpy(outptr, &v, 8);
outptr += 8;
inptr += in_stride;
}
}
/* Clean up the tail portion */
Reported by FlawFinder.
Line: 1864
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (order != 'b') {
v = npy_bswap8(v);
}
memcpy(outptr, &v, in_tail);
}
/* Add padding */
else if (out_pad) {
memset(outptr, 0, out_pad);
}
Reported by FlawFinder.
numpy/typing/tests/data/fail/index_tricks.py
5 issues
Line: 9
Column: 1
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
np.mgrid[1] # E: Invalid index type
np.mgrid[...] # E: Invalid index type
np.ogrid[1] # E: Invalid index type
np.ogrid[...] # E: Invalid index type
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
np.diag_indices(1.0) # E: incompatible type
Reported by Pylint.
Line: 10
Column: 1
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
np.mgrid[1] # E: Invalid index type
np.mgrid[...] # E: Invalid index type
np.ogrid[1] # E: Invalid index type
np.ogrid[...] # E: Invalid index type
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
np.diag_indices(1.0) # E: incompatible type
Reported by Pylint.
Line: 11
Column: 1
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
np.mgrid[1] # E: Invalid index type
np.mgrid[...] # E: Invalid index type
np.ogrid[1] # E: Invalid index type
np.ogrid[...] # E: Invalid index type
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
np.diag_indices(1.0) # E: incompatible type
Reported by Pylint.
Line: 12
Column: 1
np.mgrid[1] # E: Invalid index type
np.mgrid[...] # E: Invalid index type
np.ogrid[1] # E: Invalid index type
np.ogrid[...] # E: Invalid index type
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
np.diag_indices(1.0) # E: incompatible type
Reported by Pylint.
Line: 1
Column: 1
from typing import List
import numpy as np
AR_LIKE_i: List[int]
AR_LIKE_f: List[float]
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
np.mgrid[1] # E: Invalid index type
Reported by Pylint.
numpy/core/src/multiarray/getset.c
5 issues
Line: 87
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
((PyArrayObject_fields *)self)->strides = _dimensions + nd;
if (nd) {
memcpy(PyArray_DIMS(self), PyArray_DIMS(ret), nd*sizeof(npy_intp));
memcpy(PyArray_STRIDES(self), PyArray_STRIDES(ret), nd*sizeof(npy_intp));
}
}
else {
/* Free old dimensions and strides */
Reported by FlawFinder.
Line: 88
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (nd) {
memcpy(PyArray_DIMS(self), PyArray_DIMS(ret), nd*sizeof(npy_intp));
memcpy(PyArray_STRIDES(self), PyArray_STRIDES(ret), nd*sizeof(npy_intp));
}
}
else {
/* Free old dimensions and strides */
npy_free_cache_dim_array(self);
Reported by FlawFinder.
Line: 170
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
goto fail;
}
if (newstrides.len) {
memcpy(PyArray_STRIDES(self), newstrides.ptr, sizeof(npy_intp)*newstrides.len);
}
PyArray_UpdateFlags(self, NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS |
NPY_ARRAY_ALIGNED);
npy_free_cache_dim_obj(newstrides);
return 0;
Reported by FlawFinder.
Line: 634
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
inter->strides = inter->shape + PyArray_NDIM(self);
if (PyArray_NDIM(self)) {
memcpy(inter->shape, PyArray_DIMS(self), sizeof(npy_intp)*PyArray_NDIM(self));
memcpy(inter->strides, PyArray_STRIDES(self), sizeof(npy_intp)*PyArray_NDIM(self));
}
}
else {
inter->shape = NULL;
Reported by FlawFinder.
Line: 635
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
inter->strides = inter->shape + PyArray_NDIM(self);
if (PyArray_NDIM(self)) {
memcpy(inter->shape, PyArray_DIMS(self), sizeof(npy_intp)*PyArray_NDIM(self));
memcpy(inter->strides, PyArray_STRIDES(self), sizeof(npy_intp)*PyArray_NDIM(self));
}
}
else {
inter->shape = NULL;
inter->strides = NULL;
Reported by FlawFinder.
numpy/typing/_add_docstring.py
5 issues
Line: 6
Column: 1
import re
import textwrap
from ._generic_alias import NDArray
_docstrings_list = []
def add_newdoc(name: str, value: str, doc: str) -> None:
Reported by Pylint.
Line: 34
Column: 9
"""
type_list_ret = []
for name, value, doc in _docstrings_list:
s = textwrap.dedent(doc).replace("\n", "\n ")
# Replace sections by rubrics
lines = s.split("\n")
new_lines = []
indent = ""
Reported by Pylint.
Line: 41
Column: 13
new_lines = []
indent = ""
for line in lines:
m = re.match(r'^(\s+)[-=]+\s*$', line)
if m and new_lines:
prev = textwrap.dedent(new_lines.pop())
if prev == "Examples":
indent = ""
new_lines.append(f'{m.group(1)}.. rubric:: {prev}')
Reported by Pylint.
Line: 53
Column: 9
new_lines.append("")
else:
new_lines.append(f"{indent}{line}")
s = "\n".join(new_lines)
# Done.
type_list_ret.append(f""".. data:: {name}\n :value: {value}\n {s}""")
return "\n".join(type_list_ret)
Reported by Pylint.
Line: 149
Column: 1
""")
_docstrings = _parse_docstrings()
Reported by Pylint.
numpy/core/src/multiarray/scalartypes.h
5 issues
Line: 5
Column: 31
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
#define _NPY_SCALARTYPES_H_
/* Internal look-up tables */
extern NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
Reported by FlawFinder.
Line: 7
Column: 29
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
/* Internal look-up tables */
extern NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
Reported by FlawFinder.
Line: 9
Column: 29
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
extern NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];
Reported by FlawFinder.
Line: 11
Column: 29
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
_npy_scalar_kinds_table[NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
extern NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];
NPY_NO_EXPORT void
Reported by FlawFinder.
Line: 13
Column: 29
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
extern NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];
NPY_NO_EXPORT void
initialize_casting_tables(void);
Reported by FlawFinder.
numpy/fft/__init__.py
5 issues
Line: 204
Column: 1
"""
from . import _pocketfft, helper
from ._pocketfft import *
from .helper import *
__all__ = _pocketfft.__all__.copy()
__all__ += helper.__all__
Reported by Pylint.
Line: 205
Column: 1
from . import _pocketfft, helper
from ._pocketfft import *
from .helper import *
__all__ = _pocketfft.__all__.copy()
__all__ += helper.__all__
from numpy._pytesttester import PytestTester
Reported by Pylint.
Line: 203
Column: 1
"""
from . import _pocketfft, helper
from ._pocketfft import *
from .helper import *
__all__ = _pocketfft.__all__.copy()
__all__ += helper.__all__
Reported by Pylint.
Line: 203
Column: 1
"""
from . import _pocketfft, helper
from ._pocketfft import *
from .helper import *
__all__ = _pocketfft.__all__.copy()
__all__ += helper.__all__
Reported by Pylint.
Line: 210
Column: 1
__all__ = _pocketfft.__all__.copy()
__all__ += helper.__all__
from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester
Reported by Pylint.
numpy/f2py/tests/test_quoted_character.py
5 issues
Line: 5
Column: 1
"""
import sys
import pytest
from numpy.testing import assert_equal
from . import util
Reported by Pylint.
Line: 8
Column: 1
import pytest
from numpy.testing import assert_equal
from . import util
class TestQuotedCharacter(util.F2PyTest):
code = """
SUBROUTINE FOO(OUT1, OUT2, OUT3, OUT4, OUT5, OUT6)
Reported by Pylint.
Line: 11
Column: 1
from . import util
class TestQuotedCharacter(util.F2PyTest):
code = """
SUBROUTINE FOO(OUT1, OUT2, OUT3, OUT4, OUT5, OUT6)
CHARACTER SINGLE, DOUBLE, SEMICOL, EXCLA, OPENPAR, CLOSEPAR
PARAMETER (SINGLE="'", DOUBLE='"', SEMICOL=';', EXCLA="!",
1 OPENPAR="(", CLOSEPAR=")")
Reported by Pylint.
Line: 11
Column: 1
from . import util
class TestQuotedCharacter(util.F2PyTest):
code = """
SUBROUTINE FOO(OUT1, OUT2, OUT3, OUT4, OUT5, OUT6)
CHARACTER SINGLE, DOUBLE, SEMICOL, EXCLA, OPENPAR, CLOSEPAR
PARAMETER (SINGLE="'", DOUBLE='"', SEMICOL=';', EXCLA="!",
1 OPENPAR="(", CLOSEPAR=")")
Reported by Pylint.
Line: 31
Column: 5
@pytest.mark.skipif(sys.platform=='win32',
reason='Fails with MinGW64 Gfortran (Issue #9673)')
def test_quoted_character(self):
assert_equal(self.module.foo(), (b"'", b'"', b';', b'!', b'(', b')'))
Reported by Pylint.