Skip to content

Commit f15864e

Browse files
committed
Drop 3.9 support
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 8522396 commit f15864e

8 files changed

+34
-33
lines changed

.github/workflows/check.yml

-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
- "3.12"
2525
- "3.11"
2626
- "3.10"
27-
- "3.9"
2827
steps:
2928
- name: Setup python for tox
3029
uses: actions/setup-python@v5
@@ -48,11 +47,6 @@ jobs:
4847
PYTEST_ADDOPTS: "-vv --durations=20"
4948
CI_RUN: "yes"
5049
DIFF_AGAINST: HEAD
51-
- name: Rename coverage report file
52-
run:
53-
import os; import sys; os.rename(f".tox/.coverage.{os.environ['TOXENV']}",
54-
f".tox/.coverage.{os.environ['TOXENV']}-{sys.platform}")
55-
shell: python
5650
- name: Upload coverage data
5751
uses: actions/upload-artifact@v3
5852
with:

pyproject.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ maintainers = [
2323
authors = [
2424
{ name = "Bernát Gábor", email = "[email protected]" },
2525
]
26-
requires-python = ">=3.9"
26+
requires-python = ">=3.10"
2727
classifiers = [
2828
"Development Status :: 5 - Production/Stable",
2929
"Framework :: Sphinx :: Extension",
3030
"Intended Audience :: Developers",
3131
"License :: OSI Approved :: MIT License",
3232
"Programming Language :: Python",
3333
"Programming Language :: Python :: 3 :: Only",
34-
"Programming Language :: Python :: 3.9",
3534
"Programming Language :: Python :: 3.10",
3635
"Programming Language :: Python :: 3.11",
3736
"Programming Language :: Python :: 3.12",
@@ -70,7 +69,7 @@ build.hooks.vcs.version-file = "src/sphinx_autodoc_typehints/version.py"
7069
version.source = "vcs"
7170

7271
[tool.ruff]
73-
target-version = "py39"
72+
target-version = "py310"
7473
line-length = 120
7574
format.preview = true
7675
format.docstring-code-line-length = 100

src/sphinx_autodoc_typehints/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import textwrap
1111
import types
1212
from dataclasses import dataclass
13-
from typing import TYPE_CHECKING, Any, AnyStr, Callable, ForwardRef, NewType, TypeVar, get_type_hints
13+
from typing import TYPE_CHECKING, Any, AnyStr, ForwardRef, NewType, TypeVar, get_type_hints
1414

1515
from docutils import nodes
1616
from docutils.frontend import OptionParser
@@ -26,6 +26,7 @@
2626

2727
if TYPE_CHECKING:
2828
from ast import FunctionDef, Module, stmt
29+
from collections.abc import Callable
2930

3031
from docutils.nodes import Node
3132
from docutils.parsers.rst import states
@@ -79,8 +80,6 @@ def get_annotation_module(annotation: Any) -> str:
7980

8081

8182
def _is_newtype(annotation: Any) -> bool:
82-
if sys.version_info < (3, 10):
83-
return inspect.isfunction(annotation) and hasattr(annotation, "__supertype__")
8483
return isinstance(annotation, NewType)
8584

8685

@@ -379,7 +378,7 @@ def process_signature( # noqa: C901, PLR0913, PLR0917
379378
# when method starts with double underscore Python applies mangling -> prepend the class name
380379
method_name = f"_{obj.__qualname__.split('.')[-2]}{method_name}"
381380
method_object = outer.__dict__[method_name] if outer else obj
382-
if not isinstance(method_object, (classmethod, staticmethod)):
381+
if not isinstance(method_object, classmethod | staticmethod):
383382
start = 1
384383

385384
sph_signature = sph_signature.replace(parameters=parameters[start:])

tests/test_integration.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import ( # no type comments
1010
TYPE_CHECKING,
1111
Any,
12-
Callable,
1312
NewType,
1413
Optional,
1514
TypeVar,
@@ -20,7 +19,7 @@
2019
import pytest
2120

2221
if TYPE_CHECKING:
23-
from collections.abc import AsyncGenerator
22+
from collections.abc import AsyncGenerator, Callable
2423
from io import StringIO
2524
from mailbox import Mailbox
2625
from types import CodeType, ModuleType

tests/test_integration_autodoc_type_aliases.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import sys
55
from pathlib import Path
66
from textwrap import dedent, indent
7-
from typing import TYPE_CHECKING, Any, Callable, Literal, NewType, TypeVar # no type comments
7+
from typing import TYPE_CHECKING, Any, Literal, NewType, TypeVar
88

99
import pytest
1010

1111
if TYPE_CHECKING:
12+
from collections.abc import Callable
1213
from io import StringIO
1314

1415
from sphinx.testing.util import SphinxTestApp
@@ -156,8 +157,6 @@ def test_integration(
156157
result = (Path(app.srcdir) / "_build/text/index.txt").read_text()
157158

158159
expected = val.EXPECTED
159-
if sys.version_info < (3, 10):
160-
expected = expected.replace("NewType", "NewType()")
161160
try:
162161
assert result.strip() == dedent(expected).strip()
163162
except Exception:

tests/test_integration_issue_384.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import sys
55
from pathlib import Path
66
from textwrap import dedent, indent
7-
from typing import TYPE_CHECKING, Any, Callable, NewType, TypeVar # no type comments
7+
from typing import TYPE_CHECKING, Any, NewType, TypeVar
88

99
import pytest
1010

1111
if TYPE_CHECKING:
12+
from collections.abc import Callable
1213
from io import StringIO
1314

1415
from sphinx.testing.util import SphinxTestApp
@@ -109,8 +110,6 @@ def test_integration(
109110
result = (Path(app.srcdir) / "_build/text/index.txt").read_text()
110111

111112
expected = val.EXPECTED
112-
if sys.version_info < (3, 10):
113-
expected = expected.replace("NewType", "NewType()")
114113
try:
115114
assert result.strip() == dedent(expected).strip()
116115
except Exception:

tests/test_sphinx_autodoc_typehints.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272

7373
# Mypy does not support recursive type aliases, but
7474
# other type checkers do.
75-
RecList = Union[int, List["RecList"]] # noqa: UP006
76-
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006
77-
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006
75+
RecList = Union[int, List["RecList"]] # noqa: UP006, UP007
76+
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006, UP007
77+
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006, UP007
7878

7979

8080
class A:
@@ -150,7 +150,7 @@ def __getitem__(self, params): # noqa: ANN001, ANN204
150150
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type] # noqa: UP006
151151
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"), # noqa: UP006
152152
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"), # noqa: UP006
153-
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"),
153+
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"), # noqa: UP007
154154
pytest.param(Callable, "typing", "Callable", (), id="Callable"),
155155
pytest.param(Callable[..., str], "typing", "Callable", (..., str), id="Callable_returntype"),
156156
pytest.param(Callable[[int, str], str], "typing", "Callable", (int, str, str), id="Callable_all_types"),
@@ -266,20 +266,32 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
266266
),
267267
pytest.param(Union, ":py:data:`~typing.Union`", id="Union"),
268268
pytest.param(
269-
Union[str, bool], r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]", id="Union-str-bool"
269+
Union[str, bool], # noqa: UP007
270+
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]",
271+
id="Union-str-bool",
270272
),
271273
pytest.param(
272-
Union[str, bool, None],
274+
Union[str, bool, None], # noqa: UP007
273275
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
274276
id="Union-str-bool-None",
275277
),
276278
pytest.param(
277-
Union[str, Any], r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]", id="Union-str-Any"
279+
Union[str, Any], # noqa: UP007
280+
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]",
281+
id="Union-str-Any",
278282
),
279-
pytest.param(Optional[str], r":py:data:`~typing.Optional`\ \[:py:class:`str`]", id="Optional-str"),
280-
pytest.param(Union[str, None], r":py:data:`~typing.Optional`\ \[:py:class:`str`]", id="Optional-str-None"),
281283
pytest.param(
282-
Optional[Union[str, bool]],
284+
Optional[str], # noqa: UP007
285+
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
286+
id="Optional-str",
287+
),
288+
pytest.param(
289+
Union[str, None], # noqa: UP007
290+
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
291+
id="Optional-str-None",
292+
),
293+
pytest.param(
294+
Optional[str | bool], # noqa: UP007
283295
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
284296
id="Optional-Union-str-bool",
285297
),

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ env_list =
66
type
77
coverage
88
readme
9+
3.13
910
3.12
1011
3.11
1112
3.10
12-
3.9
1313
skip_missing_interpreters = true
1414

1515
[testenv]
@@ -70,10 +70,10 @@ commands =
7070
coverage html -d {toxworkdir}/htmlcov
7171
diff-cover --compare-branch {env:DIFF_AGAINST:origin/main} {toxworkdir}/coverage.xml
7272
depends =
73+
3.13
7374
3.12
7475
3.11
7576
3.10
76-
3.9
7777

7878
[testenv:readme]
7979
description = check that the long description is valid (need for PyPI)

0 commit comments

Comments
 (0)