Skip to content

Commit 6d81868

Browse files
mbyrnepr2DanielNoordcdce8p
authored
Add missing shape parameter to numpy methods (#1450)
Closes pylint-dev/pylint#5871 Co-authored-by: Daniël van Noord <[email protected]> Co-authored-by: Marc Mueller <[email protected]>
1 parent 81235ff commit 6d81868

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Release date: TBA
2727
to unexpected errors. Overwriting them with ``None`` will cause a fallback
2828
to the already supported way of PyPy 3.7.
2929

30+
* Add missing ``shape`` parameter to numpy ``zeros_like``, ``ones_like``,
31+
and ``full_like`` methods.
32+
33+
Closes PyCQA/pylint#5871
34+
3035

3136
What's New in astroid 2.10.1?
3237
=============================

astroid/brain/brain_numpy_core_numeric.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def numpy_core_numeric_transform():
2424
"""
2525
# different functions defined in numeric.py
2626
import numpy
27-
def zeros_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
28-
def ones_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
29-
def full_like(a, fill_value, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
27+
def zeros_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
28+
def ones_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
29+
def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
3030
"""
3131
)
3232

requirements_test_brain.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
attrs
22
types-attrs
33
nose
4-
numpy
4+
numpy>=1.17.0
55
python-dateutil
66
types-python-dateutil
77
six

tests/unittest_brain_numpy_core_numeric.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
99
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
10+
1011
import unittest
12+
from typing import List
13+
14+
import pytest
1115

1216
try:
1317
import numpy # pylint: disable=unused-import
@@ -62,5 +66,26 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
6266
)
6367

6468

69+
@pytest.mark.skipif(not HAS_NUMPY, reason="This test requires the numpy library.")
70+
@pytest.mark.parametrize(
71+
"method, expected_args",
72+
[
73+
("zeros_like", ["a", "dtype", "order", "subok", "shape"]),
74+
("full_like", ["a", "fill_value", "dtype", "order", "subok", "shape"]),
75+
("ones_like", ["a", "dtype", "order", "subok", "shape"]),
76+
("ones", ["shape", "dtype", "order"]),
77+
],
78+
)
79+
def test_function_parameters(method: str, expected_args: List[str]) -> None:
80+
instance = builder.extract_node(
81+
f"""
82+
import numpy
83+
numpy.{method} #@
84+
"""
85+
)
86+
actual_args = instance.inferred()[0].args.args
87+
assert [arg.name for arg in actual_args] == expected_args
88+
89+
6590
if __name__ == "__main__":
6691
unittest.main()

0 commit comments

Comments
 (0)