Require the PEP 563 'annotations' future import

This commit is contained in:
Adam Turner
2024-11-22 21:54:26 +00:00
parent 0e15ad7f33
commit 3af48520d2
122 changed files with 294 additions and 17 deletions

View File

@@ -295,7 +295,7 @@ select = [
"TC001", # documentation doesn't need type-checking blocks
]
"doc/conf.py" = ["INP001", "W605"]
"doc/development/tutorials/examples/*" = ["INP001"]
"doc/development/tutorials/examples/*" = ["I002", "INP001"]
# allow print() in the tutorial
"doc/development/tutorials/examples/recipe.py" = [
"FURB118",
@@ -360,7 +360,7 @@ select = [
# these tests need old ``typing`` generic aliases
"tests/test_util/test_util_typing.py" = ["UP006", "UP007", "UP035"]
"tests/test_util/typing_test_data.py" = ["FA100", "PYI030", "UP006", "UP007", "UP035"]
"tests/test_util/typing_test_data.py" = ["FA100", "I002", "PYI030", "UP006", "UP007", "UP035"]
"utils/*" = [
"T201", # whitelist ``print`` for stdout messages
@@ -377,6 +377,9 @@ inline-quotes = "single"
forced-separate = [
"tests",
]
required-imports = [
"from __future__ import annotations",
]
[format]
preview = true

View File

@@ -1,5 +1,7 @@
"""The Sphinx documentation toolchain."""
from __future__ import annotations
__version__ = '8.2.0'
__display_version__ = __version__ # used for command line version

View File

@@ -1,5 +1,7 @@
"""The Sphinx documentation toolchain."""
from __future__ import annotations
import sys
from sphinx.cmd.build import main

View File

@@ -1,5 +1,7 @@
"""Additional nodes for LaTeX writer."""
from __future__ import annotations
from docutils import nodes

View File

@@ -1,8 +1,14 @@
"""Assets adapter for sphinx.environment."""
from sphinx.environment import BuildEnvironment
from __future__ import annotations
from typing import TYPE_CHECKING
from sphinx.util._pathlib import _StrPath
if TYPE_CHECKING:
from sphinx.environment import BuildEnvironment
class ImageAdapter:
def __init__(self, env: BuildEnvironment) -> None:

View File

@@ -1,5 +1,7 @@
"""Command line interface for the intersphinx extension."""
from __future__ import annotations
import logging as _logging
import sys

View File

@@ -1,5 +1,7 @@
"""Sphinx theme specific highlighting styles."""
from __future__ import annotations
from pygments.style import Style
from pygments.styles.friendly import FriendlyStyle
from pygments.token import (

View File

@@ -1,11 +1,18 @@
from docutils import nodes
from __future__ import annotations
from typing import TYPE_CHECKING
from docutils.core import publish_doctree
from sphinx.application import Sphinx
from sphinx.io import SphinxStandaloneReader
from sphinx.parsers import RSTParser
from sphinx.util.docutils import sphinx_domains
if TYPE_CHECKING:
from docutils import nodes
from sphinx.application import Sphinx
def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document:
"""Parse a string as reStructuredText with Sphinx application."""

View File

@@ -1,3 +1,6 @@
from __future__ import annotations
def parse_line_num_spec(spec: str, total: int) -> list[int]:
"""Parse a line number spec (such as "1,2,4-6") and return a list of
wanted line numbers.

View File

@@ -1,5 +1,7 @@
"""Build phase of Sphinx application."""
from __future__ import annotations
from enum import IntEnum

View File

@@ -3,6 +3,8 @@
Reference: https://www.rfc-editor.org/rfc/rfc7231#section-7.1.1.1
"""
from __future__ import annotations
import time
import warnings
from email.utils import parsedate_tz

View File

@@ -1,5 +1,7 @@
"""Test all builders."""
from __future__ import annotations
import os
import shutil
from contextlib import contextmanager

View File

@@ -1,5 +1,7 @@
"""Test the ChangesBuilder class."""
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test dirhtml builder."""
from __future__ import annotations
import posixpath
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations
import os
import subprocess
import xml.etree.ElementTree as ET

View File

@@ -1,5 +1,7 @@
"""Test the build process with gettext builder with the test root."""
from __future__ import annotations
import gettext
import re
import subprocess

View File

@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations
import re
from pathlib import Path

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import time
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import hashlib
import re

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from unittest.mock import ANY, call, patch
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import re
from pathlib import Path

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest
from sphinx.errors import ConfigError

View File

@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations
import os
import re

View File

@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations
import pytest
from tests.test_builders.xpath_html_util import _intradocument_hyperlink_check

View File

@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations
import re
from unittest.mock import patch

View File

@@ -1,5 +1,7 @@
"""Test the build process with LaTeX builder with the test root."""
from __future__ import annotations
import http.server
import os
import re

View File

@@ -1,5 +1,7 @@
"""Test the build process with manpage builder with the test root."""
from __future__ import annotations
import docutils
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the build process with Texinfo builder with the test root."""
from __future__ import annotations
import re
import subprocess
from pathlib import Path

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import os
import re
import sys

View File

@@ -1,5 +1,7 @@
"""Test the Builder class."""
from __future__ import annotations
import sys
import pytest

View File

@@ -1,5 +1,7 @@
"""Test copyright year adjustment"""
from __future__ import annotations
import time
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the code-block directive."""
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,5 +1,7 @@
"""Test the only directive with the test root."""
from __future__ import annotations
import re
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the other directives."""
from __future__ import annotations
from pathlib import Path
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the patched directives."""
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,5 +1,7 @@
"""Tests the directives"""
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,9 +1,11 @@
"""Tests the C Domain"""
from __future__ import annotations
import itertools
import xml.etree.ElementTree as ET
import zlib
from io import StringIO
from typing import TYPE_CHECKING
import pytest
@@ -29,6 +31,9 @@ from sphinx.testing.util import assert_node
from sphinx.util.cfamily import DefinitionError
from sphinx.writers.text import STDINDENT
if TYPE_CHECKING:
from io import StringIO
class Config:
c_id_attributes = ['id_attr', 'LIGHTGBM_C_EXPORT']

View File

@@ -1,9 +1,11 @@
"""Tests the C++ Domain"""
from __future__ import annotations
import itertools
import re
import zlib
from io import StringIO
from typing import TYPE_CHECKING
import pytest
@@ -30,6 +32,9 @@ from sphinx.testing.util import assert_node
from sphinx.util.cfamily import DefinitionError, NoOldIdError
from sphinx.writers.text import STDINDENT
if TYPE_CHECKING:
from io import StringIO
def parse(name, string):
class Config:

View File

@@ -1,5 +1,7 @@
"""Tests the JavaScript Domain"""
from __future__ import annotations
from unittest.mock import Mock
import docutils.utils

View File

@@ -1,5 +1,7 @@
"""Tests the reStructuredText domain."""
from __future__ import annotations
import pytest
from sphinx import addnodes

View File

@@ -1,5 +1,7 @@
"""Tests the std domain"""
from __future__ import annotations
from unittest import mock
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the BuildEnvironment class."""
from __future__ import annotations
import shutil
from pathlib import Path

View File

@@ -1,5 +1,7 @@
"""Test the sphinx.environment.adapters.indexentries."""
from __future__ import annotations
import pytest
from sphinx.environment.adapters.indexentries import IndexEntries

View File

@@ -1,5 +1,7 @@
"""Tests for ``record_dependencies``."""
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the sphinx.environment.adapters.toctree."""
from __future__ import annotations
import pytest
from docutils import nodes
from docutils.nodes import bullet_list, list_item, literal, reference, title

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from sphinx.errors import ExtensionError

View File

@@ -1,5 +1,7 @@
"""Test the EventManager class."""
from __future__ import annotations
import pytest
from sphinx.errors import ExtensionError

View File

@@ -1,5 +1,7 @@
"""Test module for napoleon PEP 526 compatibility with google style"""
from __future__ import annotations
module_level_var: int = 99
"""This is an example module level variable"""

View File

@@ -1,5 +1,7 @@
"""Test module for napoleon PEP 526 compatibility with numpy style"""
from __future__ import annotations
module_level_var: int = 99
"""This is an example module level variable"""

View File

@@ -1,13 +1,18 @@
"""Test the sphinx.apidoc module."""
from __future__ import annotations
from collections import namedtuple
from pathlib import Path
from typing import TYPE_CHECKING
import pytest
import sphinx.ext.apidoc
from sphinx.ext.apidoc import main as apidoc_main
if TYPE_CHECKING:
from pathlib import Path
_apidoc = namedtuple('_apidoc', 'coderoot,outdir') # NoQA: PYI024

View File

@@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
source file translated by test_build.
"""
from __future__ import annotations
import pytest
from tests.test_extensions.autodoc_util import do_autodoc

View File

@@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
source file translated by test_build.
"""
from __future__ import annotations
import pytest
from tests.test_extensions.autodoc_util import do_autodoc

View File

@@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
source file translated by test_build.
"""
from __future__ import annotations
from typing import Any
import pytest

View File

@@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
source file translated by test_build.
"""
from __future__ import annotations
import inspect
import sys
import typing

View File

@@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
source file translated by test_build.
"""
from __future__ import annotations
import pytest
from tests.test_extensions.autodoc_util import do_autodoc

View File

@@ -1,10 +1,11 @@
"""Test the autodoc extension. This tests mainly for config variables"""
from __future__ import annotations
import platform
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
import pytest
@@ -12,6 +13,10 @@ from sphinx.testing import restructuredtext
from tests.test_extensions.autodoc_util import do_autodoc
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path
skip_py314_segfault = pytest.mark.skipif(
sys.version_info[:2] >= (3, 14),
reason='Segmentation fault: https://github.com/python/cpython/issues/125017',

View File

@@ -1,5 +1,7 @@
"""Test the autodoc extension. This tests mainly for autodoc events"""
from __future__ import annotations
import pytest
from sphinx.ext.autodoc import between, cut_lines

View File

@@ -1,5 +1,7 @@
"""Test the autodoc extension."""
from __future__ import annotations
import pytest
from tests.test_extensions.autodoc_util import do_autodoc

View File

@@ -1,5 +1,7 @@
"""Test the autodoc extension. This tests mainly for private-members option."""
from __future__ import annotations
import pytest
from tests.test_extensions.autodoc_util import do_autodoc

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.autosectionlabel extension."""
from __future__ import annotations
import re
import pytest

View File

@@ -1,10 +1,12 @@
"""Test the autosummary extension."""
from __future__ import annotations
import sys
from contextlib import chdir
from io import StringIO
from typing import TYPE_CHECKING
from unittest.mock import Mock, patch
from xml.etree.ElementTree import Element
import pytest
from docutils import nodes
@@ -26,6 +28,9 @@ from sphinx.ext.autosummary.generate import main as autogen_main
from sphinx.testing.util import assert_node, etree_parse
from sphinx.util.docutils import new_document
if TYPE_CHECKING:
from xml.etree.ElementTree import Element
html_warnfile = StringIO()

View File

@@ -1,5 +1,7 @@
"""Test autosummary for import cycles."""
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,5 +1,7 @@
"""Test the coverage builder."""
from __future__ import annotations
import pickle
import pytest

View File

@@ -1,5 +1,7 @@
"""Test the doctest extension."""
from __future__ import annotations
import os
from collections import Counter

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.duration extension."""
from __future__ import annotations
import re
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.githubpages extension."""
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.graphviz extension."""
from __future__ import annotations
import re
import sys

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.ifconfig extension."""
from __future__ import annotations
import docutils.utils
import pytest

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.imgconverter extension."""
from __future__ import annotations
import subprocess
import pytest

View File

@@ -1,5 +1,7 @@
"""Test image converter with identical basenames"""
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.inheritance_diagram extension."""
from __future__ import annotations
import re
import sys
import zlib

View File

@@ -1,5 +1,7 @@
"""Test math extensions."""
from __future__ import annotations
import re
import shutil
import subprocess

View File

@@ -1,5 +1,7 @@
"""Tests for :mod:`sphinx.ext.napoleon.__init__` module."""
from __future__ import annotations
import functools
from collections import namedtuple
from unittest import mock

View File

@@ -1,5 +1,7 @@
"""Tests for :mod:`sphinx.ext.napoleon.docstring` module."""
from __future__ import annotations
import re
import zlib
from collections import namedtuple

View File

@@ -1,5 +1,7 @@
"""Test sphinx.ext.todo extension."""
from __future__ import annotations
import re
import pytest

View File

@@ -1,5 +1,7 @@
"""Test sphinx.extension module."""
from __future__ import annotations
import pytest
from sphinx.errors import VersionRequirementError

View File

@@ -1,5 +1,7 @@
"""Test the Pygments highlighting bridge."""
from __future__ import annotations
from unittest import mock
import pygments

View File

@@ -1,5 +1,7 @@
"""Test the base build process."""
from __future__ import annotations
import shutil
from pathlib import Path

View File

@@ -3,11 +3,13 @@
Runs the text builder in the test root.
"""
from __future__ import annotations
import os
import re
import shutil
import time
from io import StringIO
from typing import TYPE_CHECKING
import pytest
from babel.messages import mofile, pofile
@@ -19,6 +21,9 @@ from sphinx.testing.util import assert_node, etree_parse
from sphinx.util.console import strip_colors
from sphinx.util.nodes import NodeMatcher
if TYPE_CHECKING:
from io import StringIO
_CATALOG_LOCALE = 'xx'
sphinx_intl = pytest.mark.sphinx(

View File

@@ -1,5 +1,7 @@
"""Test various Sphinx-specific markup extensions."""
from __future__ import annotations
import re
import warnings
from types import SimpleNamespace

View File

@@ -2,6 +2,7 @@
# adapted from an example of bibliographic metadata at
# https://docutils.sourceforge.io/docs/user/rst/demo.txt
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Tests parsers module."""
from __future__ import annotations
from unittest.mock import Mock, patch
import pytest

View File

@@ -1,5 +1,7 @@
"""Test smart quotes."""
from __future__ import annotations
import pytest
from sphinx.testing.util import etree_parse

View File

@@ -1,5 +1,7 @@
"""Tests project module."""
from __future__ import annotations
from pathlib import Path
import pytest

View File

@@ -1,5 +1,7 @@
"""Test pycode."""
from __future__ import annotations
import sys
from pathlib import Path

View File

@@ -1,5 +1,7 @@
"""Test pycode.ast"""
from __future__ import annotations
import ast
import pytest

View File

@@ -1,5 +1,7 @@
"""Test pycode.parser."""
from __future__ import annotations
from sphinx.pycode.parser import Parser
from sphinx.util.inspect import signature_from_str

View File

@@ -1,10 +1,10 @@
"""Test the sphinx.quickstart module."""
from __future__ import annotations
import time
from collections.abc import Callable
from io import StringIO
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any
import pytest
@@ -12,6 +12,10 @@ from sphinx.cmd import quickstart as qs
from sphinx.testing.util import SphinxTestApp
from sphinx.util.console import coloron, nocolor
if TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path
warnfile = StringIO()

View File

@@ -1,5 +1,7 @@
"""Test sphinx.roles"""
from __future__ import annotations
from unittest.mock import Mock
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest

View File

@@ -1,5 +1,7 @@
"""Test templating."""
from __future__ import annotations
import pytest
from sphinx.ext.autosummary.generate import setup_documenters

View File

@@ -1,5 +1,7 @@
"""Test the Theme class."""
from __future__ import annotations
import shutil
from pathlib import Path
from xml.etree.ElementTree import ParseError

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from types import SimpleNamespace
from docutils import nodes

View File

@@ -1,5 +1,7 @@
"""Tests the transformations"""
from __future__ import annotations
import pytest
from docutils import nodes

View File

@@ -1,10 +1,16 @@
"""Test the ``UnreferencedFootnotesDetector`` transform."""
from pathlib import Path
from __future__ import annotations
from typing import TYPE_CHECKING
from sphinx.testing.util import SphinxTestApp
from sphinx.util.console import strip_colors
if TYPE_CHECKING:
from pathlib import Path
from sphinx.testing.util import SphinxTestApp
def test_warnings(make_app: type[SphinxTestApp], tmp_path: Path) -> None:
"""Test that warnings are emitted for unreferenced footnotes."""

Some files were not shown because too many files have changed in this diff Show More