Skip to content

Commit

Permalink
Drop 3.9 support
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Sep 7, 2024
1 parent 8522396 commit f15864e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
- "3.12"
- "3.11"
- "3.10"
- "3.9"
steps:
- name: Setup python for tox
uses: actions/setup-python@v5
Expand All @@ -48,11 +47,6 @@ jobs:
PYTEST_ADDOPTS: "-vv --durations=20"
CI_RUN: "yes"
DIFF_AGAINST: HEAD
- name: Rename coverage report file
run:
import os; import sys; os.rename(f".tox/.coverage.{os.environ['TOXENV']}",
f".tox/.coverage.{os.environ['TOXENV']}-{sys.platform}")
shell: python
- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ maintainers = [
authors = [
{ name = "Bernát Gábor", email = "gaborjbernat@gmail.com" },
]
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Sphinx :: Extension",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down Expand Up @@ -70,7 +69,7 @@ build.hooks.vcs.version-file = "src/sphinx_autodoc_typehints/version.py"
version.source = "vcs"

[tool.ruff]
target-version = "py39"
target-version = "py310"
line-length = 120
format.preview = true
format.docstring-code-line-length = 100
Expand Down
7 changes: 3 additions & 4 deletions src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import textwrap
import types
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, AnyStr, Callable, ForwardRef, NewType, TypeVar, get_type_hints
from typing import TYPE_CHECKING, Any, AnyStr, ForwardRef, NewType, TypeVar, get_type_hints

from docutils import nodes
from docutils.frontend import OptionParser
Expand All @@ -26,6 +26,7 @@

if TYPE_CHECKING:
from ast import FunctionDef, Module, stmt
from collections.abc import Callable

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


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


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

sph_signature = sph_signature.replace(parameters=parameters[start:])
Expand Down
3 changes: 1 addition & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import ( # no type comments
TYPE_CHECKING,
Any,
Callable,
NewType,
Optional,
TypeVar,
Expand All @@ -20,7 +19,7 @@
import pytest

if TYPE_CHECKING:
from collections.abc import AsyncGenerator
from collections.abc import AsyncGenerator, Callable
from io import StringIO
from mailbox import Mailbox
from types import CodeType, ModuleType
Expand Down
5 changes: 2 additions & 3 deletions tests/test_integration_autodoc_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import sys
from pathlib import Path
from textwrap import dedent, indent
from typing import TYPE_CHECKING, Any, Callable, Literal, NewType, TypeVar # no type comments
from typing import TYPE_CHECKING, Any, Literal, NewType, TypeVar

import pytest

if TYPE_CHECKING:
from collections.abc import Callable
from io import StringIO

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

expected = val.EXPECTED
if sys.version_info < (3, 10):
expected = expected.replace("NewType", "NewType()")
try:
assert result.strip() == dedent(expected).strip()
except Exception:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_integration_issue_384.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import sys
from pathlib import Path
from textwrap import dedent, indent
from typing import TYPE_CHECKING, Any, Callable, NewType, TypeVar # no type comments
from typing import TYPE_CHECKING, Any, NewType, TypeVar

import pytest

if TYPE_CHECKING:
from collections.abc import Callable
from io import StringIO

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

expected = val.EXPECTED
if sys.version_info < (3, 10):
expected = expected.replace("NewType", "NewType()")
try:
assert result.strip() == dedent(expected).strip()
except Exception:
Expand Down
32 changes: 22 additions & 10 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@

# Mypy does not support recursive type aliases, but
# other type checkers do.
RecList = Union[int, List["RecList"]] # noqa: UP006
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006
RecList = Union[int, List["RecList"]] # noqa: UP006, UP007
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006, UP007
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006, UP007


class A:
Expand Down Expand Up @@ -150,7 +150,7 @@ def __getitem__(self, params): # noqa: ANN001, ANN204
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type] # noqa: UP006
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"), # noqa: UP006
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"), # noqa: UP006
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"),
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"), # noqa: UP007
pytest.param(Callable, "typing", "Callable", (), id="Callable"),
pytest.param(Callable[..., str], "typing", "Callable", (..., str), id="Callable_returntype"),
pytest.param(Callable[[int, str], str], "typing", "Callable", (int, str, str), id="Callable_all_types"),
Expand Down Expand Up @@ -266,20 +266,32 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
),
pytest.param(Union, ":py:data:`~typing.Union`", id="Union"),
pytest.param(
Union[str, bool], r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]", id="Union-str-bool"
Union[str, bool], # noqa: UP007
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]",
id="Union-str-bool",
),
pytest.param(
Union[str, bool, None],
Union[str, bool, None], # noqa: UP007
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
id="Union-str-bool-None",
),
pytest.param(
Union[str, Any], r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]", id="Union-str-Any"
Union[str, Any], # noqa: UP007
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]",
id="Union-str-Any",
),
pytest.param(Optional[str], r":py:data:`~typing.Optional`\ \[:py:class:`str`]", id="Optional-str"),
pytest.param(Union[str, None], r":py:data:`~typing.Optional`\ \[:py:class:`str`]", id="Optional-str-None"),
pytest.param(
Optional[Union[str, bool]],
Optional[str], # noqa: UP007
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
id="Optional-str",
),
pytest.param(
Union[str, None], # noqa: UP007
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
id="Optional-str-None",
),
pytest.param(
Optional[str | bool], # noqa: UP007
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
id="Optional-Union-str-bool",
),
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ env_list =
type
coverage
readme
3.13
3.12
3.11
3.10
3.9
skip_missing_interpreters = true

[testenv]
Expand Down Expand Up @@ -70,10 +70,10 @@ commands =
coverage html -d {toxworkdir}/htmlcov
diff-cover --compare-branch {env:DIFF_AGAINST:origin/main} {toxworkdir}/coverage.xml
depends =
3.13
3.12
3.11
3.10
3.9

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

0 comments on commit f15864e

Please sign in to comment.