Skip to content

Commit

Permalink
Require the PEP 563 'annotations' future import
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Nov 22, 2024
1 parent 0e15ad7 commit 3af4852
Show file tree
Hide file tree
Showing 122 changed files with 294 additions and 17 deletions.
7 changes: 5 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -377,6 +377,9 @@ inline-quotes = "single"
forced-separate = [
"tests",
]
required-imports = [
"from __future__ import annotations",
]

[format]
preview = true
Expand Down
2 changes: 2 additions & 0 deletions sphinx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""The Sphinx documentation toolchain."""

from __future__ import annotations

__version__ = '8.2.0'
__display_version__ = __version__ # used for command line version

Expand Down
2 changes: 2 additions & 0 deletions sphinx/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""The Sphinx documentation toolchain."""

from __future__ import annotations

import sys

from sphinx.cmd.build import main
Expand Down
2 changes: 2 additions & 0 deletions sphinx/builders/latex/nodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Additional nodes for LaTeX writer."""

from __future__ import annotations

from docutils import nodes


Expand Down
8 changes: 7 additions & 1 deletion sphinx/environment/adapters/asset.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions sphinx/ext/intersphinx/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Command line interface for the intersphinx extension."""

from __future__ import annotations

import logging as _logging
import sys

Expand Down
2 changes: 2 additions & 0 deletions sphinx/pygments_styles.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
11 changes: 9 additions & 2 deletions sphinx/testing/restructuredtext.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions sphinx/util/_lines.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions sphinx/util/build_phase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Build phase of Sphinx application."""

from __future__ import annotations

from enum import IntEnum


Expand Down
2 changes: 2 additions & 0 deletions sphinx/util/http_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test all builders."""

from __future__ import annotations

import os
import shutil
from contextlib import contextmanager
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_changes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the ChangesBuilder class."""

from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_dirhtml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test dirhtml builder."""

from __future__ import annotations

import posixpath

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_epub.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_gettext.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_assets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""

from __future__ import annotations

import re
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_copyright.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import time

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import hashlib
import re

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_highlight.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest.mock import ANY, call, patch

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_maths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from sphinx.errors import ConfigError
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_numfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""

from __future__ import annotations

import os
import re

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_tocdepth.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_toctree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the HTML builder and check output against XPath."""

from __future__ import annotations

import re
from unittest.mock import patch

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_manpage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the build process with manpage builder with the test root."""

from __future__ import annotations

import docutils
import pytest

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_texinfo.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re
import sys
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_incremental_reading.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the Builder class."""

from __future__ import annotations

import sys

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_config/test_copyright.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test copyright year adjustment"""

from __future__ import annotations

import time

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_code.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the code-block directive."""

from __future__ import annotations

import pytest
from docutils import nodes

Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_only.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the only directive with the test root."""

from __future__ import annotations

import re

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_option.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_other.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the other directives."""

from __future__ import annotations

from pathlib import Path

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test the patched directives."""

from __future__ import annotations

import pytest
from docutils import nodes

Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directives_no_typesetting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests the directives"""

from __future__ import annotations

import pytest
from docutils import nodes

Expand Down
7 changes: 6 additions & 1 deletion tests/test_domains/test_domain_c.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -29,6 +31,9 @@
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']
Expand Down
7 changes: 6 additions & 1 deletion tests/test_domains/test_domain_cpp.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -30,6 +32,9 @@
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:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_domains/test_domain_js.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests the JavaScript Domain"""

from __future__ import annotations

from unittest.mock import Mock

import docutils.utils
Expand Down
2 changes: 2 additions & 0 deletions tests/test_domains/test_domain_rst.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests the reStructuredText domain."""

from __future__ import annotations

import pytest

from sphinx import addnodes
Expand Down
2 changes: 2 additions & 0 deletions tests/test_domains/test_domain_std.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests the std domain"""

from __future__ import annotations

from unittest import mock

import pytest
Expand Down
Loading

0 comments on commit 3af4852

Please sign in to comment.