Skip to content

Commit def37f7

Browse files
committed
Support and require nptyping 2
Signed-off-by: Bernát Gábor <[email protected]>
1 parent ede082a commit def37f7

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.18.0
4+
5+
- Support and require `nptyping>=2`
6+
37
## 1.17.1
48

59
- Mark it as requiring `nptyping<2`

setup.cfg

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ project_urls =
3030
[options]
3131
packages = find:
3232
install_requires =
33-
Sphinx>=4
33+
Sphinx>=4.5
3434
python_requires = >=3.7
3535
package_dir =
3636
=src
@@ -40,16 +40,16 @@ where = src
4040

4141
[options.extras_require]
4242
testing =
43-
covdefaults>=2
44-
coverage>=6
43+
covdefaults>=2.2
44+
coverage>=6.3
4545
diff-cover>=6.4
46-
nptyping>=1,<2
47-
pytest>=6
46+
nptyping>=2
47+
pytest>=7.1
4848
pytest-cov>=3
4949
sphobjinv>=2
50-
typing-extensions>=3.5
50+
typing-extensions>=4.1
5151
type_comments =
52-
typed-ast>=1.4.0;python_version < "3.8"
52+
typed-ast>=1.5.2;python_version < "3.8"
5353

5454
[options.package_data]
5555
sphinx_autodoc_typehints = py.typed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def get_annotation_module(annotation: Any) -> str:
2626
if annotation is None:
2727
return "builtins"
28-
is_new_type = sys.version_info >= (3, 10) and isinstance(annotation, NewType) # type: ignore
28+
is_new_type = sys.version_info >= (3, 10) and isinstance(annotation, NewType)
2929
if is_new_type or isinstance(annotation, TypeVar):
3030
return "typing"
3131
if hasattr(annotation, "__module__"):
@@ -44,7 +44,7 @@ def get_annotation_class_name(annotation: Any, module: str) -> str:
4444
elif annotation is AnyStr:
4545
return "AnyStr"
4646
elif (sys.version_info < (3, 10) and inspect.isfunction(annotation) and hasattr(annotation, "__supertype__")) or (
47-
sys.version_info >= (3, 10) and isinstance(annotation, NewType) # type: ignore # isinstance NewType is Callable
47+
sys.version_info >= (3, 10) and isinstance(annotation, NewType)
4848
):
4949
return "NewType"
5050

tests/test_sphinx_autodoc_typehints.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828
from unittest.mock import create_autospec, patch
2929

30-
import nptyping # type: ignore
30+
import nptyping
3131
import pytest
3232
import typing_extensions
3333
from sphinx.application import Sphinx
@@ -241,45 +241,42 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
241241
# Internal tuple with following additional type cannot be flattened (specific to nptyping?)
242242
# These cases will fail if nptyping restructures its internal module hierarchy
243243
(
244-
nptyping.NDArray[(Any,), nptyping.Float],
244+
nptyping.NDArray[nptyping.Shape["*"], nptyping.Float],
245245
(
246-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(:py:data:`~typing.Any`, ), "
247-
":py:class:`~nptyping.types._number.Float`]"
246+
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Literal`\\['*'], "
247+
":py:class:`~numpy.float64`]"
248248
),
249249
),
250250
(
251-
nptyping.NDArray[(Any,), nptyping.Float[64]],
251+
nptyping.NDArray[nptyping.Shape["64"], nptyping.Float],
252252
(
253-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(:py:data:`~typing.Any`, ), "
254-
":py:class:`~nptyping.types._number.Float`\\[64]]"
253+
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Literal`\\['64'], "
254+
":py:class:`~numpy.float64`]"
255255
),
256256
),
257257
(
258-
nptyping.NDArray[(Any, Any), nptyping.Float],
258+
nptyping.NDArray[nptyping.Shape["*, *"], nptyping.Float],
259259
(
260-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(:py:data:`~typing.Any`, "
261-
":py:data:`~typing.Any`), :py:class:`~nptyping.types._number.Float`]"
260+
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Literal`\\['*, "
261+
"*'], :py:class:`~numpy.float64`]"
262262
),
263263
),
264264
(
265-
nptyping.NDArray[(Any, ...), nptyping.Float],
266-
(
267-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(:py:data:`~typing.Any`, :py:data:`...<Ellipsis>`), "
268-
":py:class:`~nptyping.types._number.Float`]"
269-
),
265+
nptyping.NDArray[nptyping.Shape["*, ..."], nptyping.Float],
266+
(":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Any`, :py:class:`~numpy.float64`]"),
270267
),
271268
(
272-
nptyping.NDArray[(Any, 3), nptyping.Float],
269+
nptyping.NDArray[nptyping.Shape["*, 3"], nptyping.Float],
273270
(
274-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(:py:data:`~typing.Any`, 3), "
275-
":py:class:`~nptyping.types._number.Float`]"
271+
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Literal`\\['*, 3'], "
272+
":py:class:`~numpy.float64`]"
276273
),
277274
),
278275
(
279-
nptyping.NDArray[(3, ...), nptyping.Float],
276+
nptyping.NDArray[nptyping.Shape["3, ..."], nptyping.Float],
280277
(
281-
":py:class:`~nptyping.types._ndarray.NDArray`\\[(3, :py:data:`...<Ellipsis>`),"
282-
" :py:class:`~nptyping.types._number.Float`]"
278+
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Literal`\\['3, ...'], "
279+
":py:class:`~numpy.float64`]"
283280
),
284281
),
285282
],
@@ -312,6 +309,7 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
312309
if "typing" in expected_result or "nptyping" in expected_result or __name__ in expected_result:
313310
expected_result = expected_result.replace("~typing", "typing")
314311
expected_result = expected_result.replace("~nptyping", "nptyping")
312+
expected_result = expected_result.replace("~numpy", "numpy")
315313
expected_result = expected_result.replace("~" + __name__, __name__)
316314
conf = create_autospec(Config, typehints_fully_qualified=True, _annotation_globals=globals())
317315
assert format_annotation(annotation, conf) == expected_result

tox.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ description = run type check on code base
4545
setenv =
4646
{tty:MYPY_FORCE_COLOR = 1}
4747
deps =
48-
mypy==0.931
48+
mypy==0.942
4949
types-docutils
5050
commands =
5151
mypy --python-version 3.10 src
@@ -59,8 +59,8 @@ setenv =
5959
COVERAGE_FILE = {toxworkdir}/.coverage
6060
skip_install = true
6161
deps =
62-
covdefaults>=2.1
63-
coverage>=6.2
62+
covdefaults>=2.2
63+
coverage>=6.3
6464
diff-cover>=6.4
6565
extras =
6666
parallel_show_output = true
@@ -80,8 +80,8 @@ depends =
8080
description = check that the long description is valid (need for PyPI)
8181
skip_install = true
8282
deps =
83-
build>=0.6
84-
twine>=3
83+
build>=0.7
84+
twine>=4
8585
extras =
8686
commands =
8787
pyproject-build -o {envtmpdir} --wheel --sdist .

0 commit comments

Comments
 (0)