From 4df89d13e64c23205504cebe25750fade41e2daa Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Wed, 10 Jun 2020 21:29:45 -0700 Subject: MAINT: fix name of first parameter to dtype constructor in type stubs The first parameter to the constructor is currently called "obj", which is incorrect. It should instead be "dtype". --- numpy/__init__.pyi | 7 ++++++- numpy/tests/typing/pass/dtype.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 numpy/tests/typing/pass/dtype.py diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 2e9c28821..4aab0bbfa 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -51,7 +51,12 @@ _NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray) class dtype: names: Optional[Tuple[str, ...]] - def __init__(self, obj: DtypeLike, align: bool = ..., copy: bool = ...) -> None: ... + def __init__( + self, + dtype: DtypeLike, + align: bool = ..., + copy: bool = ..., + ) -> None: ... def __eq__(self, other: DtypeLike) -> bool: ... def __ne__(self, other: DtypeLike) -> bool: ... def __gt__(self, other: DtypeLike) -> bool: ... diff --git a/numpy/tests/typing/pass/dtype.py b/numpy/tests/typing/pass/dtype.py new file mode 100644 index 000000000..f954fdd44 --- /dev/null +++ b/numpy/tests/typing/pass/dtype.py @@ -0,0 +1,3 @@ +import numpy as np + +np.dtype(dtype=np.int64) -- cgit v1.2.1 From 8190116aa2fa58aba628b0a5cea768017acf82bf Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Thu, 11 Jun 2020 20:59:35 -0700 Subject: DOC: correct name of first dtype constructor parameter --- numpy/core/_add_newdocs.py | 4 ++-- numpy/core/tests/test_dtype.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index 688238af3..c6c724ab3 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -5142,7 +5142,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', add_newdoc('numpy.core.multiarray', 'dtype', """ - dtype(obj, align=False, copy=False) + dtype(dtype, align=False, copy=False) Create a data type object. @@ -5152,7 +5152,7 @@ add_newdoc('numpy.core.multiarray', 'dtype', Parameters ---------- - obj + dtype Object to be converted to a data type object. align : bool, optional Add padding to the fields to match what a C compiler would output diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index faea8688c..2e2b0dbe2 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -1056,6 +1056,11 @@ def test_invalid_dtype_string(): assert_raises(TypeError, np.dtype, u'Fl\xfcgel') +def test_keyword_argument(): + # test for https://github.com/numpy/numpy/pull/16574#issuecomment-642660971 + assert np.dtype(dtype=np.float64) == np.dtype(np.float64) + + class TestFromDTypeAttribute: def test_simple(self): class dt: @@ -1333,4 +1338,3 @@ class TestFromCTypes: pair_type = np.dtype('{},{}'.format(*pair)) expected = np.dtype([('f0', pair[0]), ('f1', pair[1])]) assert_equal(pair_type, expected) - -- cgit v1.2.1